]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Add zone.to_file tests 188/head
authorMartin <martin.basti@gmail.com>
Wed, 31 Aug 2016 18:12:14 +0000 (20:12 +0200)
committerMartin <martin.basti@gmail.com>
Wed, 31 Aug 2016 18:12:14 +0000 (20:12 +0200)
Test covers both binary and textual mode for files and streams

tests/test_zone.py

index 712b5903c1b5aa665d71ed19c53ac4fabad0b3a2..3d53e9303870756332500f87278a4a5243a6e073 100644 (file)
@@ -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