summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@play-bow.org>2020-06-30 08:24:41 -0700
committerBob Halley <halley@play-bow.org>2020-06-30 08:24:41 -0700
commit1e16e7fee759893b17abb9257bdbe96e7edc65f8 (patch)
treeb591b4ca498981c88b93fde7a6029c13c5201ba4
parent2545364012b04ce3341482071067ec854487210f (diff)
downloaddnspython-1e16e7fee759893b17abb9257bdbe96e7edc65f8.tar.gz
increase name test coverage
-rw-r--r--tests/test_name.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_name.py b/tests/test_name.py
index f5c6b6d..0e8bd8e 100644
--- a/tests/test_name.py
+++ b/tests/test_name.py
@@ -17,6 +17,7 @@
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from typing import Dict # pylint: disable=unused-import
+import copy
import operator
import unittest
@@ -962,5 +963,70 @@ class NameTestCase(unittest.TestCase):
dns.name.from_wire(123, 0)
self.assertRaises(ValueError, bad)
+ def testBadPunycode(self):
+ c = dns.name.IDNACodec()
+ with self.assertRaises(dns.name.IDNAException):
+ c.decode(b'xn--0000h')
+
+ def testRootLabel2003StrictDecode(self):
+ c = dns.name.IDNA_2003_Strict
+ self.assertEqual(c.decode(b''), '')
+
+ @unittest.skipUnless(dns.name.have_idna_2008,
+ 'Python idna cannot be imported; no IDNA2008')
+ def testRootLabel2008StrictDecode(self):
+ c = dns.name.IDNA_2008_Strict
+ self.assertEqual(c.decode(b''), '')
+
+ @unittest.skipUnless(dns.name.have_idna_2008,
+ 'Python idna cannot be imported; no IDNA2008')
+ def testCodecNotFoundRaises(self):
+ dns.name.have_idna_2008 = False
+ with self.assertRaises(dns.name.NoIDNA2008):
+ c = dns.name.IDNA2008Codec()
+ c.encode('Königsgäßchen')
+ with self.assertRaises(dns.name.NoIDNA2008):
+ c = dns.name.IDNA2008Codec(strict_decode=True)
+ c.decode('xn--eckwd4c7c.xn--zckzah.')
+ dns.name.have_idna_2008 = True
+
+ @unittest.skipUnless(dns.name.have_idna_2008,
+ 'Python idna cannot be imported; no IDNA2008')
+ def testBadPunycodeStrict2008(self):
+ c = dns.name.IDNA2008Codec(strict_decode=True)
+ with self.assertRaises(dns.name.IDNAException):
+ c.decode(b'xn--0000h')
+
+ def testRelativizeSubtractionSyntax(self):
+ n = dns.name.from_text('foo.example.')
+ o = dns.name.from_text('example.')
+ e = dns.name.from_text('foo', None)
+ self.assertEqual(n - o, e)
+
+ def testCopy(self):
+ n1 = dns.name.from_text('foo.example.')
+ n2 = copy.copy(n1)
+ self.assertTrue(n1 is not n2)
+ # the Name constructor always copies labels, so there is no
+ # difference between copy and deepcopy
+ self.assertTrue(n1.labels is not n2.labels)
+ self.assertEqual(len(n1.labels), len(n2.labels))
+ for i, l in enumerate(n1.labels):
+ self.assertTrue(l is n2[i])
+
+ def testDeepCopy(self):
+ n1 = dns.name.from_text('foo.example.')
+ n2 = copy.deepcopy(n1)
+ self.assertTrue(n1 is not n2)
+ self.assertTrue(n1.labels is not n2.labels)
+ self.assertEqual(len(n1.labels), len(n2.labels))
+ for i, l in enumerate(n1.labels):
+ self.assertTrue(l is n2[i])
+
+ def testNoAttributeDeletion(self):
+ n = dns.name.from_text('foo.example.')
+ with self.assertRaises(TypeError):
+ del n.labels
+
if __name__ == '__main__':
unittest.main()