summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mx-2-0.picklebin0 -> 223 bytes
-rw-r--r--tests/test_message.py3
-rw-r--r--tests/test_rdata.py18
-rw-r--r--tests/test_zone.py29
-rw-r--r--tests/util.py21
5 files changed, 67 insertions, 4 deletions
diff --git a/tests/mx-2-0.pickle b/tests/mx-2-0.pickle
new file mode 100644
index 0000000..53d094c
--- /dev/null
+++ b/tests/mx-2-0.pickle
Binary files differ
diff --git a/tests/test_message.py b/tests/test_message.py
index 4eb48d3..e64578b 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -29,8 +29,7 @@ import dns.rdatatype
import dns.rrset
import dns.update
-def here(filename):
- return os.path.join(os.path.dirname(__file__), filename)
+from tests.util import here
query_text = """id 1234
opcode QUERY
diff --git a/tests/test_rdata.py b/tests/test_rdata.py
index 022642f..7960dd1 100644
--- a/tests/test_rdata.py
+++ b/tests/test_rdata.py
@@ -34,6 +34,7 @@ from dns.rdtypes.ANY.OPT import OPT
import tests.stxt_module
import tests.ttxt_module
+from tests.util import here
class RdataTestCase(unittest.TestCase):
@@ -94,6 +95,15 @@ class RdataTestCase(unittest.TestCase):
a1.replace(address="bogus")
self.assertRaises(dns.exception.SyntaxError, bad)
+ def test_replace_comment(self):
+ a1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
+ "1.2.3.4 ;foo")
+ self.assertEqual(a1.rdcomment, "foo")
+ a2 = a1.replace(rdcomment="bar")
+ self.assertEqual(a1, a2)
+ self.assertEqual(a1.rdcomment, "foo")
+ self.assertEqual(a2.rdcomment, "bar")
+
def test_to_generic(self):
a = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "1.2.3.4")
self.assertEqual(str(a.to_generic()), r'\# 4 01020304')
@@ -415,5 +425,13 @@ class RdataTestCase(unittest.TestCase):
rdata = dns.rdata.from_wire('in', 'a', wire, 0, 4)
self.assertEqual(rdata, dns.rdata.from_text('in', 'a', '1.2.3.4'))
+ def test_unpickle(self):
+ expected_mx = dns.rdata.from_text('in', 'mx', '10 mx.example.')
+ with open(here('mx-2-0.pickle'), 'rb') as f:
+ mx = pickle.load(f)
+ self.assertEqual(mx, expected_mx)
+ self.assertIsNone(mx.rdcomment)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_zone.py b/tests/test_zone.py
index 36428b1..9857f80 100644
--- a/tests/test_zone.py
+++ b/tests/test_zone.py
@@ -35,8 +35,7 @@ import dns.rrset
import dns.zone
import dns.node
-def here(filename):
- return os.path.join(os.path.dirname(__file__), filename)
+from tests.util import here
example_text = """$TTL 3600
$ORIGIN example.
@@ -175,6 +174,23 @@ $ORIGIN example.
@ 300 ns ns2
"""
+example_comments_text = """$TTL 3600
+$ORIGIN example.
+@ soa foo bar (1 ; not kept
+2 3 4 5) ; kept
+@ ns ns1
+@ ns ns2
+ns1 a 10.0.0.1 ; comment1
+ns2 a 10.0.0.2 ; comment2
+"""
+
+example_comments_text_output = """@ 3600 IN SOA foo bar 1 2 3 4 5 ; kept
+@ 3600 IN NS ns1
+@ 3600 IN NS ns2
+ns1 3600 IN A 10.0.0.1 ; comment1
+ns2 3600 IN A 10.0.0.2 ; comment2
+"""
+
_keep_output = True
def _rdata_sort(a):
@@ -746,5 +762,14 @@ class ZoneTestCase(unittest.TestCase):
self.assertEqual(z._validate_name('foo.bar.example.'),
dns.name.from_text('foo.bar', None))
+ def testComments(self):
+ z = dns.zone.from_text(example_comments_text, 'example.',
+ relativize=True)
+ f = StringIO()
+ z.to_file(f, want_comments=True)
+ out = f.getvalue()
+ f.close()
+ self.assertEqual(out, example_comments_text_output)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/util.py b/tests/util.py
new file mode 100644
index 0000000..df736df
--- /dev/null
+++ b/tests/util.py
@@ -0,0 +1,21 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+
+# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation for any purpose with or without fee is hereby granted,
+# provided that the above copyright notice and this permission notice
+# appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import os.path
+
+def here(filename):
+ return os.path.join(os.path.dirname(__file__), filename)