def setUp(self): self.test_set_a = [u'ábc', u'abc', u'Straße', u'echo', u'peña', u'pena'] self.test_set_b = [u'àbc', u'Straße', u'live', u'xkcd', u'äbc', u'ábc'] self.test_set_c = [u'ÀBC', u'Live', 'abc'] self.a = unicode_set(self.test_set_a) self.b = unicode_set(self.test_set_b) self.a3 = unicode_set(self.test_set_a, comparison_level=3) self.b3 = unicode_set(self.test_set_b, comparison_level=3)
def test_create(self): a = unicode_set(self.test_set_a) self.assertEqual(len(a), 4) b = unicode_set(self.test_set_b) self.assertEqual(len(b), 4) c = unicode_set(self.test_set_c) self.assertEqual(len(c), 2)
def test_create_collations(self): an = unicode_set(self.test_set_a,locale = 'ES_ES') self.assertEqual(len(an), 5) cc = unicode_set(self.test_set_c,case_sensitive = True) self.assertEqual(len(cc), 3) a3 = unicode_set(self.test_set_a, comparison_level=3) self.assertEqual(len(a3), len(self.test_set_a)) b3 = unicode_set(self.test_set_b, comparison_level=3) self.assertEqual(len(b3), len(self.test_set_b))
def test_superset(self): self.assertTrue(self.a.issuperset(['äbc'])) self.assertTrue(self.a.issuperset(self.test_set_a)) self.assertFalse(self.a.issuperset(self.test_set_b)) self.assertFalse(self.a.issuperset(self.test_set_a+["live"])) self.assertTrue(self.a >= unicode_set(['äbc'])) self.assertTrue(self.a >= unicode_set(self.test_set_a)) self.assertFalse(self.a > unicode_set(self.test_set_a)) self.assertFalse(self.a >= unicode_set(self.test_set_b)) self.assertFalse(self.a >= unicode_set(self.test_set_a+["live"])) self.assertTrue(self.a.issuperset(self.a3)) with self.assertRaises(TypeError) as cm: self.a >= self.a3 with self.assertRaises(TypeError) as cm: self.a >= ['äbc'] with self.assertRaises(TypeError) as cm: self.a >= set(['äbc'])
def test_subset(self): self.assertFalse(self.a.issubset(['äbc'])) self.assertTrue(self.a.issubset(self.test_set_a)) self.assertFalse(self.a.issubset(self.test_set_b)) self.assertTrue(self.a.issubset(self.test_set_a+["live"])) self.assertFalse(self.a <= unicode_set(['äbc'])) self.assertTrue(self.a <= unicode_set(self.test_set_a)) self.assertFalse(self.a < unicode_set(self.test_set_a)) self.assertFalse(self.a <= unicode_set(self.test_set_b)) self.assertTrue(self.a <= unicode_set(self.test_set_a+["live"])) self.assertTrue(self.a.issubset(self.a3)) with self.assertRaises(TypeError): self.a <= self.a3 with self.assertRaises(TypeError): self.a <= ['äbc'] with self.assertRaises(TypeError): self.a <= set(['äbc'])
def test_clear(self): self.a3.clear() self.assertEqual(len(self.a3),0) for i in self.a3: self.fail() cc = unicode_set(self.test_set_c,case_sensitive = True) cc.clear() self.assertEqual(len(cc),0) for i in cc: self.fail() self.b.clear() self.assertEqual(len(self.b),0) for i in self.b: self.fail()