summaryrefslogtreecommitdiff
path: root/tests/test_name.py
diff options
context:
space:
mode:
authorDaniel Lenski <dlenski@amazon.com>2020-04-30 17:31:48 -0700
committerDaniel Lenski <dlenski@amazon.com>2020-04-30 17:35:27 -0700
commit4f6db05816453cb1223626f14f81aaf1df4b5cdf (patch)
tree8ef80158c2aba0b165f19e883916c7126b20ddd4 /tests/test_name.py
parentea9b29fb1d1b7d764561621261381f544fa6fd41 (diff)
downloaddnspython-4f6db05816453cb1223626f14f81aaf1df4b5cdf.tar.gz
also use skipUnless for tests that require IDNA2008
Diffstat (limited to 'tests/test_name.py')
-rw-r--r--tests/test_name.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/tests/test_name.py b/tests/test_name.py
index 47cea18..a0dbb4b 100644
--- a/tests/test_name.py
+++ b/tests/test_name.py
@@ -704,42 +704,44 @@ class NameTestCase(unittest.TestCase):
e = dns.name.from_unicode(t)
self.assertEqual(str(e), 'xn--knigsgsschen-lcb0w.')
+ @unittest.skipUnless(dns.name.have_idna_2008,
+ 'Python idna cannot be imported; no IDNA2008')
def testFromUnicodeIDNA2008(self):
- if dns.name.have_idna_2008:
- t = 'Königsgäßchen'
- def bad():
- codec = dns.name.IDNA_2008_Strict
- return dns.name.from_unicode(t, idna_codec=codec)
- self.assertRaises(dns.name.IDNAException, bad)
- e1 = dns.name.from_unicode(t, idna_codec=dns.name.IDNA_2008)
- self.assertEqual(str(e1), 'xn--knigsgchen-b4a3dun.')
- c2 = dns.name.IDNA_2008_Transitional
- e2 = dns.name.from_unicode(t, idna_codec=c2)
- self.assertEqual(str(e2), 'xn--knigsgsschen-lcb0w.')
-
+ t = 'Königsgäßchen'
+ def bad():
+ codec = dns.name.IDNA_2008_Strict
+ return dns.name.from_unicode(t, idna_codec=codec)
+ self.assertRaises(dns.name.IDNAException, bad)
+ e1 = dns.name.from_unicode(t, idna_codec=dns.name.IDNA_2008)
+ self.assertEqual(str(e1), 'xn--knigsgchen-b4a3dun.')
+ c2 = dns.name.IDNA_2008_Transitional
+ e2 = dns.name.from_unicode(t, idna_codec=c2)
+ self.assertEqual(str(e2), 'xn--knigsgsschen-lcb0w.')
+
+ @unittest.skipUnless(dns.name.have_idna_2008,
+ 'Python idna cannot be imported; no IDNA2008')
def testFromUnicodeIDNA2008Mixed(self):
# the IDN rules for names are very restrictive, disallowing
# practical names like '_sip._tcp.Königsgäßchen'. Dnspython
# has a "practical" mode which permits labels which are purely
# ASCII to go straight through, and thus not invalid useful
# things in the real world.
- if dns.name.have_idna_2008:
- t = '_sip._tcp.Königsgäßchen'
- def bad1():
- codec = dns.name.IDNA_2008_Strict
- return dns.name.from_unicode(t, idna_codec=codec)
- def bad2():
- codec = dns.name.IDNA_2008_UTS_46
- return dns.name.from_unicode(t, idna_codec=codec)
- def bad3():
- codec = dns.name.IDNA_2008_Transitional
- return dns.name.from_unicode(t, idna_codec=codec)
- self.assertRaises(dns.name.IDNAException, bad1)
- self.assertRaises(dns.name.IDNAException, bad2)
- self.assertRaises(dns.name.IDNAException, bad3)
- e = dns.name.from_unicode(t,
- idna_codec=dns.name.IDNA_2008_Practical)
- self.assertEqual(str(e), '_sip._tcp.xn--knigsgchen-b4a3dun.')
+ t = '_sip._tcp.Königsgäßchen'
+ def bad1():
+ codec = dns.name.IDNA_2008_Strict
+ return dns.name.from_unicode(t, idna_codec=codec)
+ def bad2():
+ codec = dns.name.IDNA_2008_UTS_46
+ return dns.name.from_unicode(t, idna_codec=codec)
+ def bad3():
+ codec = dns.name.IDNA_2008_Transitional
+ return dns.name.from_unicode(t, idna_codec=codec)
+ self.assertRaises(dns.name.IDNAException, bad1)
+ self.assertRaises(dns.name.IDNAException, bad2)
+ self.assertRaises(dns.name.IDNAException, bad3)
+ e = dns.name.from_unicode(t,
+ idna_codec=dns.name.IDNA_2008_Practical)
+ self.assertEqual(str(e), '_sip._tcp.xn--knigsgchen-b4a3dun.')
def testToUnicode1(self):
n = dns.name.from_text('foo.bar')