Ejemplo n.º 1
0
 def test_creation(self):
     cds = UnicodeSubset([(0, 9), 11, 12, (14, 32),
                          (33, sys.maxunicode + 1)])
     self.assertEqual(cds, [(0, 9), (11, 13), (14, 32),
                            (33, sys.maxunicode + 1)])
     self.assertEqual(UnicodeSubset('0-9'), [(48, 58)])
     self.assertEqual(UnicodeSubset('0-9:'), [(48, 59)])
Ejemplo n.º 2
0
 def test_max_and_min(self):
     cds1 = UnicodeSubset([10, 51, (89, 151), 90])
     cds2 = UnicodeSubset([0, 2, (80, 201), 10000])
     cds3 = UnicodeSubset([1])
     self.assertEqual((min(cds1), max(cds1)), (10, 150))
     self.assertEqual((min(cds2), max(cds2)), (0, 10000))
     self.assertEqual((min(cds3), max(cds3)), (1, 1))
Ejemplo n.º 3
0
 def test_complement(self):
     cds = UnicodeSubset([50, 90, 10, 90])
     self.assertEqual(list(cds.complement()), [(0, 10), (11, 50), (51, 90), (91, sys.maxunicode + 1)])
     cds.add(11)
     self.assertEqual(list(cds.complement()), [(0, 10), (12, 50), (51, 90), (91, sys.maxunicode + 1)])
     cds.add((0, 10))
     self.assertEqual(list(cds.complement()), [(12, 50), (51, 90), (91, sys.maxunicode + 1)])
Ejemplo n.º 4
0
    def test_complement(self):
        cds = UnicodeSubset([50, 90, 10, 90])
        self.assertEqual(list(cds.complement()), [(0, 10), (11, 50), (51, 90),
                                                  (91, sys.maxunicode + 1)])
        cds.add(11)
        self.assertEqual(list(cds.complement()), [(0, 10), (12, 50), (51, 90),
                                                  (91, sys.maxunicode + 1)])
        cds.add((0, 10))
        self.assertEqual(list(cds.complement()), [(12, 50), (51, 90),
                                                  (91, sys.maxunicode + 1)])

        cds1 = UnicodeSubset(
            chain(UNICODE_CATEGORIES['L'].code_points,
                  UNICODE_CATEGORIES['M'].code_points,
                  UNICODE_CATEGORIES['N'].code_points,
                  UNICODE_CATEGORIES['S'].code_points))
        cds2 = UnicodeSubset(
            chain(UNICODE_CATEGORIES['C'].code_points,
                  UNICODE_CATEGORIES['P'].code_points,
                  UNICODE_CATEGORIES['Z'].code_points))
        self.assertListEqual(cds1.code_points,
                             UnicodeSubset(cds2.complement()).code_points)
Ejemplo n.º 5
0
 def test_modify(self):
     cds = UnicodeSubset([50, 90, 10, 90])
     self.assertEqual(cds, [10, 50, 90])
     self.assertRaises(XMLSchemaValueError, cds.add, -1)
     self.assertRaises(XMLSchemaValueError, cds.add, sys.maxunicode + 1)
     cds.add((100, 20001))
     cds.discard((100, 19001))
     self.assertEqual(cds, [10, 50, 90, (19001, 20001)])
     cds.add(0)
     cds.discard(1)
     self.assertEqual(cds, [0, 10, 50, 90, (19001, 20001)])
     cds.discard(0)
     self.assertEqual(cds, [10, 50, 90, (19001, 20001)])
     cds.discard((10, 100))
     self.assertEqual(cds, [(19001, 20001)])
     cds.add(20)
     cds.add(19)
     cds.add(30)
     cds.add([30, 33])
     cds.add(30000)
     cds.add(30001)
     self.assertEqual(cds, [(19, 21), (30, 33), (19001, 20001),
                            (30000, 30002)])
     cds.add(22)
     cds.add(21)
     cds.add(22)
     self.assertEqual(cds, [(19, 22), 22, (30, 33), (19001, 20001),
                            (30000, 30002)])
     cds.discard((90, 50000))
     self.assertEqual(cds, [(19, 22), 22, (30, 33)])
     cds.discard(21)
     cds.discard(19)
     self.assertEqual(cds, [20, 22, (30, 33)])
     cds.discard((0, 200))
     self.assertEqual(cds, [])
Ejemplo n.º 6
0
 def test_subtraction(self):
     cds = UnicodeSubset([0, 2, (80, 200), 10000])
     self.assertEqual(cds - {2, 120, 121, (150, 260)},
                      [0, (80, 120), (122, 150), 10000])
Ejemplo n.º 7
0
 def test_union_and_intersection(self):
     cds1 = UnicodeSubset([50, (90, 200), 10])
     cds2 = UnicodeSubset([10, 51, (89, 150), 90])
     self.assertEqual(cds1 | cds2, [10, (50, 52), (89, 200)])
     self.assertEqual(cds1 & cds2, [10, (90, 150)])