From: Martin Date: Wed, 31 Aug 2016 18:12:14 +0000 (+0200) Subject: Add zone.to_file tests X-Git-Tag: v1.15.0~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F188%2Fhead;p=thirdparty%2Fdnspython.git Add zone.to_file tests Test covers both binary and textual mode for files and streams --- diff --git a/tests/test_zone.py b/tests/test_zone.py index 712b5903..3d53e930 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -132,6 +132,59 @@ class ZoneTestCase(unittest.TestCase): os.unlink(here('example2.out')) self.failUnless(ok) + def testToFileTextualStream(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + f = StringIO() + z.to_file(f) + out = f.getvalue() + f.close() + self.assertEqual(out, example_text_output) + + def testToFileBinaryStream(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + f = BytesIO() + z.to_file(f) + out = f.getvalue() + f.close() + self.assertEqual(out, example_text_output.encode()) + + def testToFileTextual(self): + z = dns.zone.from_file(here('example'), 'example') + try: + f = open(here('example3-textual.out'), 'w') + z.to_file(f) + f.close() + ok = filecmp.cmp(here('example3-textual.out'), + here('example3.good')) + finally: + if not _keep_output: + os.unlink(here('example3-textual.out')) + self.failUnless(ok) + + def testToFileBinary(self): + z = dns.zone.from_file(here('example'), 'example') + try: + f = open(here('example3-binary.out'), 'wb') + z.to_file(f) + f.close() + ok = filecmp.cmp(here('example3-binary.out'), + here('example3.good')) + finally: + if not _keep_output: + os.unlink(here('example3-binary.out')) + self.failUnless(ok) + + def testToFileFilename(self): + z = dns.zone.from_file(here('example'), 'example') + try: + z.to_file('example3-filename.out') + ok = filecmp.cmp(here('example3-filename.out'), + here('example3.good')) + finally: + if not _keep_output: + os.unlink(here('example3-filename.out')) + self.failUnless(ok) + def testToText(self): z = dns.zone.from_file(here('example'), 'example') ok = False