def test_check_bidi(self): l = u'\u0061' r = u'\u05d0' al = u'\u0627' an = u'\u0660' en = u'\u0030' es = u'\u002d' cs = u'\u002c' et = u'\u0024' on = u'\u0021' bn = u'\u200c' nsm = u'\u0610' ws = u'\u0020' # RFC 5893 Rule 1 self.assertTrue(idna.check_bidi(l)) self.assertTrue(idna.check_bidi(r)) self.assertTrue(idna.check_bidi(al)) self.assertRaises(idna.IDNABidiError, idna.check_bidi, an) # RFC 5893 Rule 2 self.assertTrue(idna.check_bidi(r + al)) self.assertTrue(idna.check_bidi(r + al)) self.assertTrue(idna.check_bidi(r + an)) self.assertTrue(idna.check_bidi(r + en)) self.assertTrue(idna.check_bidi(r + es + al)) self.assertTrue(idna.check_bidi(r + cs + al)) self.assertTrue(idna.check_bidi(r + et + al)) self.assertTrue(idna.check_bidi(r + on + al)) self.assertTrue(idna.check_bidi(r + bn + al)) self.assertTrue(idna.check_bidi(r + nsm)) self.assertRaises(idna.IDNABidiError, idna.check_bidi, r + l) self.assertRaises(idna.IDNABidiError, idna.check_bidi, r + ws) # RFC 5893 Rule 3 self.assertTrue(idna.check_bidi(r + al)) self.assertTrue(idna.check_bidi(r + en)) self.assertTrue(idna.check_bidi(r + an)) self.assertTrue(idna.check_bidi(r + nsm)) self.assertTrue(idna.check_bidi(r + nsm + nsm)) self.assertRaises(idna.IDNABidiError, idna.check_bidi, r + on) # RFC 5893 Rule 4 self.assertTrue(idna.check_bidi(r + en)) self.assertTrue(idna.check_bidi(r + an)) self.assertRaises(idna.IDNABidiError, idna.check_bidi, r + en + an) self.assertRaises(idna.IDNABidiError, idna.check_bidi, r + an + en) # RFC 5893 Rule 5 self.assertTrue(idna.check_bidi(l + en, check_ltr=True)) self.assertTrue(idna.check_bidi(l + es + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + cs + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + et + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + on + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + bn + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + nsm, check_ltr=True)) # RFC 5893 Rule 6 self.assertTrue(idna.check_bidi(l + l, check_ltr=True)) self.assertTrue(idna.check_bidi(l + en, check_ltr=True)) self.assertTrue(idna.check_bidi(l + en + nsm, check_ltr=True)) self.assertTrue(idna.check_bidi(l + en + nsm + nsm, check_ltr=True)) self.assertRaises(idna.IDNABidiError, idna.check_bidi, l + cs, check_ltr=True)