Example #1
0
 def test_dict(self):
     d = {"one": 1, "two": 2, "three": 3}
     for i in (1, 2, 3):
         self.assertTrue(i in py2.dict_values(d))
         self.assertFalse(i in py2.dict_keys(d))
     self.assertFalse("one" in py2.dict_values(d))
     self.assertTrue("one" in py2.dict_keys(d))
     self.assertTrue(("one", 1) in py2.dict_items(d))
     self.assertFalse((1, "one") in py2.dict_items(d))
     # finally, these functions return iterable objects, not lists
     try:
         py2.dict_keys(d)[0]
         self.fail("dict_keys can be indexed")
     except TypeError:
         pass
     try:
         py2.dict_values(d)[0]
         self.fail("dict_values can be indexed")
     except TypeError:
         pass
     try:
         py2.dict_items(d)[0]
         self.fail("dict_items can be indexed")
     except TypeError:
         pass
Example #2
0
 def test_dict(self):
     d = {"one": 1, "two": 2, "three": 3}
     for i in (1, 2, 3):
         self.assertTrue(i in py2.dict_values(d))
         self.assertFalse(i in py2.dict_keys(d))
     self.assertFalse("one" in py2.dict_values(d))
     self.assertTrue("one" in py2.dict_keys(d))
Example #3
0
 def test_get_set(self):
     e = atom.AtomElement(None)
     e.set_base("http://www.example.com/")
     self.assertTrue(e.get_base() == "http://www.example.com/",
                     "Get/Set example xml:base value")
     e.set_lang("en-US")
     self.assertTrue(e.get_lang() == "en-US",
                     "Get/Set example xml:lang value")
     attrs = e.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 2,
                     "Two attributes expected")
     self.assertTrue(attrs[(xmlns.XML_NAMESPACE, 'base')] ==
                     "http://www.example.com/", "Base attribute")
     self.assertTrue(attrs[(xmlns.XML_NAMESPACE, 'lang')] == "en-US",
                     "Lang attribute")
     e.set_base(None)
     attrs = e.get_attributes()
     self.assertTrue(e.get_base() is None, "Get/Set empty xml:base value")
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 1,
                     "One attribute expected")
     e.set_lang(None)
     attrs = e.get_attributes()
     self.assertTrue(e.get_lang() is None, "Get/Set empty xml:lang value")
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "No attributes expected")
Example #4
0
 def test_dict(self):
     d = {"one": 1, "two": 2, "three": 3}
     for i in (1, 2, 3):
         self.assertTrue(i in py2.dict_values(d))
         self.assertFalse(i in py2.dict_keys(d))
     self.assertFalse("one" in py2.dict_values(d))
     self.assertTrue("one" in py2.dict_keys(d))
     self.assertTrue(("one", 1) in py2.dict_items(d))
     self.assertFalse((1, "one") in py2.dict_items(d))
     # finally, these functions return iterable objects, not lists
     try:
         py2.dict_keys(d)[0]
         self.fail("dict_keys can be indexed")
     except TypeError:
         pass
     try:
         py2.dict_values(d)[0]
         self.fail("dict_values can be indexed")
     except TypeError:
         pass
     try:
         py2.dict_items(d)[0]
         self.fail("dict_items can be indexed")
     except TypeError:
         pass
Example #5
0
 def test_se_range(self):
     """seRange ::= charOrEsc '-' charOrEsc  """
     tests = {
         'a-c': ("abc", "`dABC"),
         '\\?-A': ("?@A", ">Ba"),
         'z-\\|': ("z{|", "y}Z")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             cclass = p.require_se_range()
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
     p = xsi.RegularExpressionParser("c-a")
     try:
         cclass = p.require_se_range()
         self.fail("Failed to spot reversed range")
     except xsi.RegularExpressionError:
         pass
Example #6
0
 def test_char_prop(self):
     """::
     charProp ::= IsCategory | IsBlock"""
     tests = {
         # positive and negative tests
         'Nd': (u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3'),
                u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98')),
         'S': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}"),
         'IsBasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
         'IsLatin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
         'IsCurrencySymbols': (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'),
                               ul("\x24\xa2\xa3")),
         'IsNumberForms': (
             u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
             "1/5 2/5 3/5 4/5")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_char_prop()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
Example #7
0
 def test_is_block(self):
     """::
     IsBlock    ::=    'Is' [a-zA-Z0-9#x2D]+"""
     tests = {
         # positive and negative tests
         'BasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
         'Latin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
         'CurrencySymbols': (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'),
                             ul("\x24\xa2\xa3")),
         'NumberForms': (
             u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
             "1/5 2/5 3/5 4/5")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser("Is" + b)
         cclass = p.require_is_block()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in Is%s" % (repr(c), b))
     p = xsi.RegularExpressionParser("IsNumberFoams")
     try:
         cclass = p.require_is_block()
         self.fail("IsNumberFoams")
     except xsi.RegularExpressionError:
         pass
Example #8
0
 def test_quant_exact(self):
     """::
     QuantExact ::= [0-9]+ """
     tests = {
         '0': 0,
         '1': 1,
         '9': 9,
         '01': 1,
         '010': 10,
         '020': 20,
         '20': 20,
         '99': 99
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             result = p.require_quant_exact()
             self.assertTrue(result == tests[b],
                             "Mismatched number: %s expected %s" %
                             (repr(result), repr(tests[b])))
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
     p = xsi.RegularExpressionParser("x")
     try:
         p.require_quant_exact()
         self.fail("Parsed x as QuantExact")
     except xsi.RegularExpressionError:
         pass
 def test_quant_exact(self):
     """::
     QuantExact ::= [0-9]+ """
     tests = {
         '0': 0,
         '1': 1,
         '9': 9,
         '01': 1,
         '010': 10,
         '020': 20,
         '20': 20,
         '99': 99
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             result = p.require_quant_exact()
             self.assertTrue(
                 result == tests[b], "Mismatched number: %s expected %s" %
                 (repr(result), repr(tests[b])))
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
     p = xsi.RegularExpressionParser("x")
     try:
         p.require_quant_exact()
         self.fail("Parsed x as QuantExact")
     except xsi.RegularExpressionError:
         pass
 def test_se_range(self):
     """seRange ::= charOrEsc '-' charOrEsc  """
     tests = {
         'a-c': ("abc", "`dABC"),
         '\\?-A': ("?@A", ">Ba"),
         'z-\\|': ("z{|", "y}Z")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             cclass = p.require_se_range()
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
     p = xsi.RegularExpressionParser("c-a")
     try:
         cclass = p.require_se_range()
         self.fail("Failed to spot reversed range")
     except xsi.RegularExpressionError:
         pass
 def test_decode(self):
     tests = {
         "-1.23": -1.23,
         "+100000.00": 100000.0,
         "210.": 210.0,
         "010": 10,
         "010.": 10,
         "01.0": 1,
         "0.10": 0.1,
         ".010": 0.01,
         " 1": ValueError,
         "1,000": ValueError,
         "0.0": 0.0,
         "+0.0": 0.0,
         "-0.0": 0.0,
         "1E+2": ValueError,
         "1e-2": ValueError,
         "1 ": ValueError,
         "1 000": ValueError
     }
     for src in dict_keys(tests):
         t = tests[src]
         try:
             result = xsi.decimal_from_str(src)
             self.assertTrue(
                 result == t, "Mismatched decimal: %s expected %s" %
                 (repr(result), repr(t)))
         except ValueError:
             if t is ValueError:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(src))
                 raise
 def test_char_prop(self):
     """::
     charProp ::= IsCategory | IsBlock"""
     tests = {
         # positive and negative tests
         'Nd': (u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3'),
                u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98')),
         'S': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}"),
         'IsBasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
         'IsLatin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
         'IsCurrencySymbols':
         (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'), ul("\x24\xa2\xa3")),
         'IsNumberForms':
         (u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
          "1/5 2/5 3/5 4/5")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_char_prop()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
 def test_is_block(self):
     """::
     IsBlock    ::=    'Is' [a-zA-Z0-9#x2D]+"""
     tests = {
         # positive and negative tests
         'BasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
         'Latin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
         'CurrencySymbols':
         (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'), ul("\x24\xa2\xa3")),
         'NumberForms':
         (u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
          "1/5 2/5 3/5 4/5")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser("Is" + b)
         cclass = p.require_is_block()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in Is%s" % (repr(c), b))
     p = xsi.RegularExpressionParser("IsNumberFoams")
     try:
         cclass = p.require_is_block()
         self.fail("IsNumberFoams")
     except xsi.RegularExpressionError:
         pass
Example #14
0
 def test_constructor(self):
     entry = atom.Entry(None)
     self.assertTrue(isinstance(entry, atom.AtomElement), "Entry not an AtomElement")
     self.assertTrue(entry.get_base() is None, "xml:base present on construction")
     self.assertTrue(entry.get_lang() is None, "xml:lang present on construction")
     attrs = entry.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0, "Attributes present on construction")
 def test_quantity(self):
     """::
     quantity ::= quantRange | quantMin | QuantExact
     quantRange ::= QuantExact ',' QuantExact
     quantMin ::= QuantExact ','  """
     tests = {
         '0,0': (0, 0),
         '0,': (0, None),
         '99,': (99, None),
         '0': (0, 0),
         '99': (99, 99),
         '99,1': xsi.RegularExpressionParser,
         '1,99': (1, 99),
         '0,99': (0, 99),
         ',99': xsi.RegularExpressionParser,
         '?': xsi.RegularExpressionParser,
         '*': xsi.RegularExpressionParser,
         '+': xsi.RegularExpressionParser
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         t = tests[b]
         try:
             x, y = p.require_quantity()
             self.assertTrue(
                 x == t[0] and y == t[1],
                 "Mismatched quantity: %s expected %s" % (repr(
                     (x, y)), repr(t)))
             self.assertTrue(p.the_char is None)
         except xsi.RegularExpressionError:
             if t is xsi.RegularExpressionParser:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(b))
                 raise
Example #16
0
 def test_quantity(self):
     """::
     quantity ::= quantRange | quantMin | QuantExact
     quantRange ::= QuantExact ',' QuantExact
     quantMin ::= QuantExact ','  """
     tests = {
         '0,0': (0, 0),
         '0,': (0, None),
         '99,': (99, None),
         '0': (0, 0),
         '99': (99, 99),
         '99,1': xsi.RegularExpressionParser,
         '1,99': (1, 99),
         '0,99': (0, 99),
         ',99': xsi.RegularExpressionParser,
         '?': xsi.RegularExpressionParser,
         '*': xsi.RegularExpressionParser,
         '+': xsi.RegularExpressionParser
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         t = tests[b]
         try:
             x, y = p.require_quantity()
             self.assertTrue(x == t[0] and y == t[1],
                             "Mismatched quantity: %s expected %s" %
                             (repr((x, y)), repr(t)))
             self.assertTrue(p.the_char is None)
         except xsi.RegularExpressionError:
             if t is xsi.RegularExpressionParser:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(b))
                 raise
Example #17
0
 def test_decode(self):
     tests = {
         "-1.23": -1.23,
         "+100000.00": 100000.0,
         "210.": 210.0,
         "010": 10,
         "010.": 10,
         "01.0": 1,
         "0.10": 0.1,
         ".010": 0.01,
         " 1": ValueError,
         "1,000": ValueError,
         "0.0": 0.0,
         "+0.0": 0.0,
         "-0.0": 0.0,
         "1E+2": ValueError,
         "1e-2": ValueError,
         "1 ": ValueError,
         "1 000": ValueError}
     for src in dict_keys(tests):
         t = tests[src]
         try:
             result = xsi.decimal_from_str(src)
             self.assertTrue(result == t,
                             "Mismatched decimal: %s expected %s" %
                             (repr(result), repr(t)))
         except ValueError:
             if t is ValueError:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(src))
                 raise
Example #18
0
 def test_server(self):
     for k in dict_keys(SERVER_EXAMPLES):
         userinfo, host, port = uri.split_server(k)
         userinfo2, host2, port2 = SERVER_EXAMPLES[k]
         self.assertTrue(userinfo == userinfo2, "%s found userinfo %s" %
                         (repr(k), repr(userinfo2)))
         self.assertTrue(host == host2, "%s found host %s" % (k, host2))
         self.assertTrue(port == port2, "%s found port %s" % (k, port2))
Example #19
0
 def test_server(self):
     for k in dict_keys(SERVER_EXAMPLES):
         userinfo, host, port = uri.split_server(k)
         userinfo2, host2, port2 = SERVER_EXAMPLES[k]
         self.assertTrue(userinfo == userinfo2, "%s found userinfo %s" %
                         (repr(k), repr(userinfo2)))
         self.assertTrue(host == host2, "%s found host %s" % (k, host2))
         self.assertTrue(port == port2, "%s found port %s" % (k, port2))
Example #20
0
 def test_attributes(self):
     e = structures.Element(None)
     e.set_xmlname("test")
     e.set_attribute("atest", "value")
     attrs = e.get_attributes()
     self.assertTrue(len(list(dict_keys(attrs))) == 1, "Attribute not set")
     self.assertTrue(attrs["atest"] == "value", "Attribute not set correctly")
     e = ReflectiveElement(None)
     e.set_attribute("atest", "value")
     # Deprecated: self.assertTrue(e.atest=='value',"Attribute relfection")
     attrs = e.get_attributes()
     self.assertTrue(attrs["atest"] == "value", "Attribute not set correctly")
     e.set_attribute("btest", "Yes")
     self.assertTrue(e.bTest == "Yes", "Attribute relfection with simple assignment")
     attrs = e.get_attributes()
     self.assertTrue(attrs["btest"] == "Yes", "Attribute not set correctly")
     e.set_attribute("ctest", "Yes")
     self.assertTrue(e.cTest is True, "Attribute relfection with decode/encode")
     attrs = e.get_attributes()
     self.assertTrue(attrs["ctest"] == "Yes", "Attribute not set correctly")
     self.assertFalse("dtest" in attrs, "Optional ordered list attribute")
     self.assertTrue(attrs["dtestR"] == "", "Required ordered list attribute")
     e.set_attribute("dtest", "Yes No")
     self.assertTrue(e.dTest == [True, False], "Attribute relfection with list; %s" % repr(e.dTest))
     attrs = e.get_attributes()
     self.assertTrue(attrs["dtest"] == "Yes No", "Attribute not set correctly")
     self.assertFalse("etest" in attrs, "Optional unordered list attribute")
     self.assertTrue(attrs["etestR"] == "", "Required unordered list attribute")
     e.set_attribute("etest", "Yes No Yes")
     self.assertTrue(e.eTest == {True: 2, False: 1}, "Attribute relfection with list: %s" % repr(e.eTest))
     attrs = e.get_attributes()
     self.assertTrue(attrs["etest"] == "No Yes Yes", "Attribute not set correctly: %s" % repr(attrs["etest"]))
     try:
         if e.ztest:
             pass
         self.fail("AttributeError required for undefined names")
     except AttributeError:
         pass
     e.ztest = 1
     if e.ztest:
         pass
     del e.ztest
     try:
         if e.ztest:
             pass
         self.fail("AttributeError required for undefined names after del")
     except AttributeError:
         pass
     try:
         self.assertTrue(e.fTest is None, "Missing attribute auto value not None")
     except AttributeError:
         self.fail("Missing attribute auto value: AttributeError")
     e.fTest = 1
     del e.fTest
     try:
         self.assertTrue(e.fTest is None, "Missing attribute auto value not None (after del)")
     except AttributeError:
         self.fail("Missing attribute auto value: AttributeError (after del)")
Example #21
0
 def test_constructor(self):
     text = atom.Text(None)
     self.assertTrue(text.xmlname is None, "element name on construction")
     self.assertTrue(isinstance(text, atom.AtomElement), "Text not an AtomElement")
     self.assertTrue(text.get_base() is None, "xml:base present on construction")
     self.assertTrue(text.get_lang() is None, "xml:lang present on construction")
     attrs = text.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 1, "Attributes present on construction")
     self.assertTrue(text.get_value() == "", "Content present on construction")
Example #22
0
 def test_constructor(self):
     feed = atom.Feed(None)
     self.assertTrue(isinstance(feed, atom.AtomElement), "Feed not an AtomElement")
     self.assertTrue(feed.xmlname == "feed", "Feed XML name")
     self.assertTrue(feed.get_base() is None, "xml:base present on construction")
     self.assertTrue(feed.get_lang() is None, "xml:lang present on construction")
     self.assertTrue(len(feed.Entry) == 0, "Non-empty feed on construction")
     attrs = feed.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0, "Attributes present on construction")
Example #23
0
 def test_constructor(self):
     e = atom.AtomElement(None)
     self.assertTrue(e.parent is None, "empty parent on construction")
     self.assertTrue(e.xmlname is None, "element name on construction")
     self.assertTrue(e.get_base() is None, "xml:base present on construction")
     self.assertTrue(e.get_lang() is None, "xml:lang present on construction")
     attrs = e.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0, "Attributes present on construction")
     e2 = atom.AtomElement(e)
     self.assertTrue(e2.parent is e, "non-empty parent on construction")
Example #24
0
 def test_relative_examples(self):
     base = uri.URI(REL_BASE)
     current = uri.URI(REL_CURRENT)
     relatives = {}
     for k in dict_keys(REL_EXAMPLES):
         logging.info("Testing relative: %s", k)
         u = uri.URI(k)
         resolved, scheme, authority, abs_path, rel_path, query, \
             fragment = REL_EXAMPLES[k]
         relatives[resolved] = relatives.get(resolved, []) + [k]
         resolution = str(u.resolve(base, current))
         self.assertTrue(scheme == u.scheme,
                         "%s found scheme %s" % (k, u.scheme))
         self.assertTrue(authority == u.authority,
                         "%s found authority %s" % (k, u.authority))
         self.assertTrue(abs_path == u.abs_path,
                         "%s found abs_path %s" % (k, u.abs_path))
         self.assertTrue(rel_path == u.rel_path,
                         "%s found rel_path %s" % (k, u.rel_path))
         self.assertTrue(query == u.query,
                         "%s found query %s" % (k, u.query))
         self.assertTrue(fragment == u.fragment,
                         "%s found fragment %s" % (k, u.fragment))
         self.assertTrue(resolved == resolution,
                         "%s [*] %s = %s ; found %s" %
                         (str(base), k, resolved, resolution))
     for r in dict_keys(relatives):
         logging.info("Testing %s [/] %s = ( %s )", r, str(base),
                      ' | '.join(relatives[r]))
         u = uri.URI(r)
         # this check removes the 'current document' case
         if not u.is_absolute():
             continue
         relative = str(u.relative(base))
         # relative should be one of the relatives!
         no_match = True
         for k in relatives[r]:
             if k == relative:
                 no_match = False
                 break
         self.assertFalse(no_match, "%s [/] %s = ( %s ) ; found %s" %
                          (r, str(base), ' | '.join(relatives[r]),
                           relative))
Example #25
0
 def test_relative_examples(self):
     base = uri.URI(REL_BASE)
     current = uri.URI(REL_CURRENT)
     relatives = {}
     for k in dict_keys(REL_EXAMPLES):
         logging.info("Testing relative: %s", k)
         u = uri.URI(k)
         resolved, scheme, authority, abs_path, rel_path, query, \
             fragment = REL_EXAMPLES[k]
         relatives[resolved] = relatives.get(resolved, []) + [k]
         resolution = str(u.resolve(base, current))
         self.assertTrue(scheme == u.scheme,
                         "%s found scheme %s" % (k, u.scheme))
         self.assertTrue(authority == u.authority,
                         "%s found authority %s" % (k, u.authority))
         self.assertTrue(abs_path == u.abs_path,
                         "%s found abs_path %s" % (k, u.abs_path))
         self.assertTrue(rel_path == u.rel_path,
                         "%s found rel_path %s" % (k, u.rel_path))
         self.assertTrue(query == u.query,
                         "%s found query %s" % (k, u.query))
         self.assertTrue(fragment == u.fragment,
                         "%s found fragment %s" % (k, u.fragment))
         self.assertTrue(resolved == resolution,
                         "%s [*] %s = %s ; found %s" %
                         (str(base), k, resolved, resolution))
     for r in dict_keys(relatives):
         logging.info("Testing %s [/] %s = ( %s )", r, str(base),
                      ' | '.join(relatives[r]))
         u = uri.URI(r)
         # this check removes the 'current document' case
         if not u.is_absolute():
             continue
         relative = str(u.relative(base))
         # relative should be one of the relatives!
         no_match = True
         for k in relatives[r]:
             if k == relative:
                 no_match = False
                 break
         self.assertFalse(no_match, "%s [/] %s = ( %s ) ; found %s" %
                          (r, str(base), ' | '.join(relatives[r]),
                           relative))
Example #26
0
 def test_constructor(self):
     person = atom.Person(None)
     self.assertTrue(person.xmlname is None, "element name on construction")
     self.assertTrue(isinstance(person, atom.AtomElement), "Person not an AtomElement")
     self.assertTrue(person.get_base() is None, "xml:base present on construction")
     self.assertTrue(person.get_lang() is None, "xml:lang present on construction")
     attrs = person.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0, "Attributes present on construction")
     self.assertTrue(isinstance(person.Name, atom.Name), "Name on construction")
     self.assertTrue(person.URI is None, "URI on construction")
     self.assertTrue(person.Email is None, "Email on construction")
Example #27
0
 def test_constructor(self):
     svc = app.Service(None)
     self.assertTrue(
         isinstance(svc, app.APPElement), "Service not an APPElement")
     self.assertTrue(svc.xmlname == "service", "Service XML name")
     attrs = svc.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     workspaces = svc.Workspace
     self.assertTrue(
         len(workspaces) == 0, "Workspaces present on construction")
Example #28
0
 def test_constructor(self):
     entry = atom.Entry(None)
     self.assertTrue(
         isinstance(entry, atom.AtomElement), "Entry not an AtomElement")
     self.assertTrue(
         entry.get_base() is None, "xml:base present on construction")
     self.assertTrue(
         entry.get_lang() is None, "xml:lang present on construction")
     attrs = entry.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
Example #29
0
 def test_constructor(self):
     e = structures.Element(None)
     self.assertTrue(e.xmlname is None, "element name on construction")
     self.assertTrue(e.get_document() is None, "document set on construction")
     attrs = e.get_attributes()
     self.assertTrue(len(list(dict_keys(attrs))) == 0, "Attributes present on construction")
     children = e.get_children()
     try:
         next(children)
         self.fail("Children present on construction")
     except StopIteration:
         pass
Example #30
0
 def test_constructor(self):
     e = app.APPElement(None)
     self.assertTrue(e.xmlname is None, 'element name on construction')
     self.assertTrue(
         e.get_base() is None, "xml:base present on construction")
     self.assertTrue(
         e.get_lang() is None, "xml:lang present on construction")
     self.assertTrue(
         e.get_space() is None, "xml:space present on construction")
     attrs = e.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
Example #31
0
 def test_constructor(self):
     svc = app.Service(None)
     self.assertTrue(isinstance(svc, app.APPElement),
                     "Service not an APPElement")
     self.assertTrue(svc.xmlname == "service", "Service XML name")
     attrs = svc.get_attributes()
     self.assertTrue(
         sum(1 for k in dict_keys(attrs)) == 0,
         "Attributes present on construction")
     workspaces = svc.Workspace
     self.assertTrue(
         len(workspaces) == 0, "Workspaces present on construction")
Example #32
0
 def test_constructor(self):
     ws = app.Workspace(None)
     self.assertTrue(
         isinstance(ws, app.APPElement), "Workspace not an APPElement")
     self.assertTrue(ws.xmlname == "workspace", "Workspace XML name")
     attrs = ws.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     self.assertTrue(ws.Title is None, "Title present on construction")
     collections = ws.Collection
     self.assertTrue(
         len(collections) == 0, "Collections present on construction")
Example #33
0
 def test_constructor(self):
     e = app.APPElement(None)
     self.assertTrue(e.xmlname is None, 'element name on construction')
     self.assertTrue(e.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(e.get_lang() is None,
                     "xml:lang present on construction")
     self.assertTrue(e.get_space() is None,
                     "xml:space present on construction")
     attrs = e.get_attributes()
     self.assertTrue(
         sum(1 for k in dict_keys(attrs)) == 0,
         "Attributes present on construction")
Example #34
0
 def test_constructor(self):
     feed = atom.Feed(None)
     self.assertTrue(
         isinstance(feed, atom.AtomElement), "Feed not an AtomElement")
     self.assertTrue(feed.xmlname == "feed", "Feed XML name")
     self.assertTrue(
         feed.get_base() is None, "xml:base present on construction")
     self.assertTrue(
         feed.get_lang() is None, "xml:lang present on construction")
     self.assertTrue(len(feed.Entry) == 0, "Non-empty feed on construction")
     attrs = feed.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
Example #35
0
 def test_constructor(self):
     e = atom.AtomElement(None)
     self.assertTrue(e.parent is None, 'empty parent on construction')
     self.assertTrue(e.xmlname is None, 'element name on construction')
     self.assertTrue(e.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(e.get_lang() is None,
                     "xml:lang present on construction")
     attrs = e.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     e2 = atom.AtomElement(e)
     self.assertTrue(e2.parent is e, 'non-empty parent on construction')
Example #36
0
 def test_atom_date_constructor(self):
     date = atom.Date(None)
     self.assertTrue(date.xmlname is None, "element name on construction")
     self.assertTrue(isinstance(date, atom.AtomElement), "Date not an AtomElement")
     self.assertTrue(date.get_base() is None, "xml:base present on construction")
     self.assertTrue(date.get_lang() is None, "xml:lang present on construction")
     attrs = date.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0, "Attributes present on construction")
     self.assertTrue(isinstance(date.get_value(), iso8601.TimePoint), "Value not a TimePoint")
     date.set_value("2016-10-22T19:10:00Z")
     date2 = date.get_value()
     self.assertTrue(isinstance(date2, iso8601.TimePoint), "Value not a TimePoint")
     self.assertTrue(date2 == iso8601.TimePoint.from_str("2016-10-22T19:10:00Z"))
Example #37
0
 def test_constructor(self):
     ws = app.Workspace(None)
     self.assertTrue(isinstance(ws, app.APPElement),
                     "Workspace not an APPElement")
     self.assertTrue(ws.xmlname == "workspace", "Workspace XML name")
     attrs = ws.get_attributes()
     self.assertTrue(
         sum(1 for k in dict_keys(attrs)) == 0,
         "Attributes present on construction")
     self.assertTrue(ws.Title is None, "Title present on construction")
     collections = ws.Collection
     self.assertTrue(
         len(collections) == 0, "Collections present on construction")
Example #38
0
 def test_atom_date_constructor(self):
     date = atom.Date(None)
     self.assertTrue(date.xmlname is None, 'element name on construction')
     self.assertTrue(isinstance(date, atom.AtomElement),
                     "Date not an AtomElement")
     self.assertTrue(date.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(date.get_lang() is None,
                     "xml:lang present on construction")
     attrs = date.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     self.assertTrue(isinstance(date.get_value(), iso8601.TimePoint),
                     "Value not a TimePoint")
Example #39
0
 def test_constructor(self):
     text = atom.Text(None)
     self.assertTrue(text.xmlname is None, 'element name on construction')
     self.assertTrue(isinstance(text, atom.AtomElement),
                     "Text not an AtomElement")
     self.assertTrue(text.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(text.get_lang() is None,
                     "xml:lang present on construction")
     attrs = text.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 1,
                     "Attributes present on construction")
     self.assertTrue(text.get_value() == '',
                     "Content present on construction")
Example #40
0
 def test_constructor(self):
     c = app.Collection(None)
     self.assertTrue(
         isinstance(c, app.APPElement), "Collection not an APPElement")
     self.assertTrue(c.xmlname == "collection", "Collection XML name")
     self.assertTrue(c.href is None, "HREF present on construction")
     attrs = c.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     self.assertTrue(c.Title is None, "Title present on construction")
     self.assertTrue(len(c.Accept) == 0,
                     "Accept list non-empty on construction")
     self.assertTrue(len(c.Categories) == 0,
                     "Categories list non-empty on construction")
Example #41
0
 def test_constructor(self):
     e = structures.Element(None)
     self.assertTrue(e.xmlname is None, 'element name on construction')
     self.assertTrue(e.get_document() is None,
                     'document set on construction')
     attrs = e.get_attributes()
     self.assertTrue(
         len(list(dict_keys(attrs))) == 0,
         "Attributes present on construction")
     children = e.get_children()
     try:
         next(children)
         self.fail("Children present on construction")
     except StopIteration:
         pass
Example #42
0
 def test_constructor(self):
     c = app.Collection(None)
     self.assertTrue(isinstance(c, app.APPElement),
                     "Collection not an APPElement")
     self.assertTrue(c.xmlname == "collection", "Collection XML name")
     self.assertTrue(c.href is None, "HREF present on construction")
     attrs = c.get_attributes()
     self.assertTrue(
         sum(1 for k in dict_keys(attrs)) == 0,
         "Attributes present on construction")
     self.assertTrue(c.Title is None, "Title present on construction")
     self.assertTrue(
         len(c.Accept) == 0, "Accept list non-empty on construction")
     self.assertTrue(
         len(c.Categories) == 0,
         "Categories list non-empty on construction")
Example #43
0
 def test_constructor(self):
     person = atom.Person(None)
     self.assertTrue(person.xmlname is None, 'element name on construction')
     self.assertTrue(isinstance(person, atom.AtomElement),
                     "Person not an AtomElement")
     self.assertTrue(person.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(person.get_lang() is None,
                     "xml:lang present on construction")
     attrs = person.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     self.assertTrue(isinstance(person.Name, atom.Name),
                     "Name on construction")
     self.assertTrue(person.URI is None, "URI on construction")
     self.assertTrue(person.Email is None, "Email on construction")
 def test_is_category(self):
     """::
     IsCategory ::= Letters | Marks | Numbers | Punctuation |
         Separators | Symbols | Others
     Letters  ::= 'L' [ultmo]?
     Marks  ::= 'M' [nce]?
     Numbers  ::= 'N' [dlo]?
     Punctuation ::= 'P' [cdseifo]?
     Separators ::= 'Z' [slp]?
     Symbols  ::= 'S' [mcko]?
     Others  ::= 'C' [cfon]?"""
     tests = [
         "L", "Lu", "Ll", "Lt", "Lm", "Lo", "M", "Mn", "Mc", "Me", "N",
         "Nd", "Nl", "No", "P", "Pc", "Pd", "Ps", "Pe", "Pi", "Pf", "Po",
         "Z", "Zs", "Zl", "Zp", "S", "Sm", "Sc", "Sk", "So", "C", "Cc",
         "Cf", "Co", "Cn"
     ]
     bad = ["A", "Za"]
     for s in tests:
         p = xsi.RegularExpressionParser(s)
         self.assertTrue(isinstance(p.require_is_category(), CharClass),
                         "Missing category: %s" % s)
         self.assertTrue(p.the_char is None,
                         "Incomplete parse of category: %s" % s)
     for s in bad:
         p = xsi.RegularExpressionParser(s)
         try:
             p.require_is_category()
             self.assertFalse(p.the_char is None,
                              "Undetected bad category: %s" % s)
         except xsi.RegularExpressionError:
             pass
     tests = {
         # positive and negative tests
         'Nd': (u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3'),
                u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98')),
         'S': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_is_category()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
Example #45
0
 def test_is_category(self):
     """::
     IsCategory ::= Letters | Marks | Numbers | Punctuation |
         Separators | Symbols | Others
     Letters  ::= 'L' [ultmo]?
     Marks  ::= 'M' [nce]?
     Numbers  ::= 'N' [dlo]?
     Punctuation ::= 'P' [cdseifo]?
     Separators ::= 'Z' [slp]?
     Symbols  ::= 'S' [mcko]?
     Others  ::= 'C' [cfon]?"""
     tests = ["L", "Lu", "Ll", "Lt", "Lm", "Lo", "M", "Mn", "Mc", "Me",
              "N", "Nd", "Nl", "No", "P", "Pc", "Pd", "Ps", "Pe", "Pi",
              "Pf", "Po", "Z", "Zs", "Zl", "Zp", "S", "Sm", "Sc", "Sk",
              "So", "C", "Cc", "Cf", "Co", "Cn"]
     bad = ["A", "Za"]
     for s in tests:
         p = xsi.RegularExpressionParser(s)
         self.assertTrue(isinstance(p.require_is_category(), CharClass),
                         "Missing category: %s" % s)
         self.assertTrue(
             p.the_char is None, "Incomplete parse of category: %s" % s)
     for s in bad:
         p = xsi.RegularExpressionParser(s)
         try:
             p.require_is_category()
             self.assertFalse(
                 p.the_char is None, "Undetected bad category: %s" % s)
         except xsi.RegularExpressionError:
             pass
     tests = {
         # positive and negative tests
         'Nd': (
             u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3'),
             u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98')),
         'S': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_is_category()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
Example #46
0
 def test_absolute_examples(self):
     for k in dict_keys(ABS_EXAMPLES):
         logging.info("Testing absolute: %s", k)
         u = uri.URI(k)
         scheme, opaque_part, authority, abs_path, query, fName = \
             ABS_EXAMPLES[k]
         self.assertTrue(scheme == u.scheme,
                         "%s found scheme %s" % (k, u.scheme))
         self.assertTrue(opaque_part == u.opaque_part,
                         "%s found opaque_part %s" % (k, u.opaque_part))
         self.assertTrue(authority == u.authority,
                         "%s found authority %s" % (k, u.authority))
         self.assertTrue(abs_path == u.abs_path,
                         "%s found abs_path %s" % (k, u.abs_path))
         self.assertTrue(query == u.query,
                         "%s found query %s" % (k, u.query))
         self.assertTrue(fName == u.get_file_name(),
                         "%s found file name %s" % (k, u.get_file_name()))
Example #47
0
 def test_absolute_examples(self):
     for k in dict_keys(ABS_EXAMPLES):
         logging.info("Testing absolute: %s", k)
         u = uri.URI(k)
         scheme, opaque_part, authority, abs_path, query, fName = \
             ABS_EXAMPLES[k]
         self.assertTrue(scheme == u.scheme,
                         "%s found scheme %s" % (k, u.scheme))
         self.assertTrue(opaque_part == u.opaque_part,
                         "%s found opaque_part %s" % (k, u.opaque_part))
         self.assertTrue(authority == u.authority,
                         "%s found authority %s" % (k, u.authority))
         self.assertTrue(abs_path == u.abs_path,
                         "%s found abs_path %s" % (k, u.abs_path))
         self.assertTrue(query == u.query,
                         "%s found query %s" % (k, u.query))
         self.assertTrue(fName == u.get_file_name(),
                         "%s found file name %s" % (k, u.get_file_name()))
Example #48
0
 def test_atom(self):
     """::
     atom ::= Char | charClass | ( '(' regExp ')' ) """
     tests = {
         'A': "A",
         '[A-z-[\[-\]]]': "[A-Z_-z^]",
         '(Hello(Mum)|(Dad))': "(Hello(Mum)|(Dad))"
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             result = p.require_atom()
             self.assertTrue(result == tests[b],
                             "Mismatched atom: %s expected %s" %
                             (repr(result), repr(b)))
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
 def test_reg_exp(self):
     """::
     regExp ::= branch ( '|' branch )* """
     tests = {"A.*Z": "A[^\\n\\r]*Z", ".*AAA.*": "[^\\n\\r]*AAA[^\\n\\r]*"}
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         t = tests[b]
         try:
             result = p.require_reg_exp()
             self.assertTrue(
                 result == t, "Mismatched regExp: %s expected %s" %
                 (repr(result), repr(t)))
             self.assertTrue(p.the_char is None)
         except xsi.RegularExpressionError:
             if t is xsi.RegularExpressionParser:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(b))
                 raise
Example #50
0
 def test_char_class_esc(self):
     """::
     charClassEsc ::= ( SingleCharEsc | MultiCharEsc | catEsc | complEsc )
     """
     tests = {
         '\\?': ("?", "\\"),
         '\\d': (u8(b'123\xd9\xa1\xd9\xa2\xd9\xa3'),
                 u8(b'ABC\xe2\x82\x81\xe2\x82\x82\xe2\x82\x83')),
         '\\p{S}': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}"),
         '\\P{S}': ("(){}", u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'))}
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_char_class_esc()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
Example #51
0
 def test_constructor(self):
     e = app.Categories(None)
     self.assertTrue(e.ns == app.APP_NAMESPACE, 'ns on construction')
     self.assertTrue(
         e.xmlname == "categories", 'element name on construction')
     self.assertTrue(
         e.get_base() is None, "xml:base present on construction")
     self.assertTrue(
         e.get_lang() is None, "xml:lang present on construction")
     self.assertTrue(
         e.get_space() is None, "xml:space present on construction")
     attrs = e.get_attributes()
     self.assertTrue(sum(1 for k in dict_keys(attrs)) == 0,
                     "Attributes present on construction")
     self.assertTrue(e.href is None, "href present on construction")
     self.assertTrue(e.fixed is None, "fixed on construction")
     self.assertTrue(e.scheme is None, "scheme present on construction")
     self.assertTrue(
         len(e.Category) == 0, "Category  list non empty on construction")
 def test_atom(self):
     """::
     atom ::= Char | charClass | ( '(' regExp ')' ) """
     tests = {
         'A': "A",
         '[A-z-[\[-\]]]': "[A-Z_-z^]",
         '(Hello(Mum)|(Dad))': "(Hello(Mum)|(Dad))"
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             result = p.require_atom()
             self.assertTrue(
                 result == tests[b], "Mismatched atom: %s expected %s" %
                 (repr(result), repr(b)))
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
Example #53
0
 def test_piece(self):
     """::
     piece ::= atom quantifier? """
     tests = {
         'A': "A",
         '[A-z-[\[-\]]]': "[A-Z_-z^]",
         '(Hello(Mum)|(Dad))': "(Hello(Mum)|(Dad))",
         "A{0,0}": "",
         '[A-Z]{0,1}': "[A-Z]?",
         '(Hello){0,}': "(Hello)*",
         'B{1,}': "B+",
         ul('[@-\xA9]?'): ul("[@-\xA9]?"),
         '(Bye)*': "(Bye)*",
         'X+': "X+",
         '[45]{099,}': "[45]{99,}",
         '(45){0}': "",
         '@{99}': "@{99}",
         'A{99,1}': xsi.RegularExpressionParser,
         'A{1,99}': "A{1,99}",
         'A{0,99}': "A{,99}",
         'A{,99}': xsi.RegularExpressionParser,
         '$': "\\$",
         '^': "\\^",
         'A{1,99': xsi.RegularExpressionParser,
         '\\{{0,1}': "\\{?",
         '\\??': "\\??"
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         t = tests[b]
         try:
             result = p.require_piece()
             self.assertTrue(result == t,
                             "Mismatched piece: %s expected %s" %
                             (repr(result), repr(t)))
             self.assertTrue(p.the_char is None)
         except xsi.RegularExpressionError:
             if t is xsi.RegularExpressionParser:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(b))
                 raise
 def test_piece(self):
     """::
     piece ::= atom quantifier? """
     tests = {
         'A': "A",
         '[A-z-[\[-\]]]': "[A-Z_-z^]",
         '(Hello(Mum)|(Dad))': "(Hello(Mum)|(Dad))",
         "A{0,0}": "",
         '[A-Z]{0,1}': "[A-Z]?",
         '(Hello){0,}': "(Hello)*",
         'B{1,}': "B+",
         ul('[@-\xA9]?'): ul("[@-\xA9]?"),
         '(Bye)*': "(Bye)*",
         'X+': "X+",
         '[45]{099,}': "[45]{99,}",
         '(45){0}': "",
         '@{99}': "@{99}",
         'A{99,1}': xsi.RegularExpressionParser,
         'A{1,99}': "A{1,99}",
         'A{0,99}': "A{,99}",
         'A{,99}': xsi.RegularExpressionParser,
         '$': "\\$",
         '^': "\\^",
         'A{1,99': xsi.RegularExpressionParser,
         '\\{{0,1}': "\\{?",
         '\\??': "\\??"
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         t = tests[b]
         try:
             result = p.require_piece()
             self.assertTrue(
                 result == t, "Mismatched piece: %s expected %s" %
                 (repr(result), repr(t)))
             self.assertTrue(p.the_char is None)
         except xsi.RegularExpressionError:
             if t is xsi.RegularExpressionParser:
                 pass
             else:
                 logging.debug("Failed to parse %s" % repr(b))
                 raise
Example #55
0
 def test_compl_esc(self):
     """::
     complEsc ::= '\P{' charProp '}' """
     tests = {
         # positive and negative tests
         '\\P{Nd}':
         (u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
          u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3')),
         '\\P{S}': ("(){}", u8(b'+<=>\xe2\x81\x84\xe2\x82\xac')),
         '\\P{IsBasicLatin}': (ul("\xc0\xdf\xa9"), "ABC")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_compl_esc()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
 def test_compl_esc(self):
     """::
     complEsc ::= '\P{' charProp '}' """
     tests = {
         # positive and negative tests
         '\\P{Nd}':
         (u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
          u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3')),
         '\\P{S}': ("(){}", u8(b'+<=>\xe2\x81\x84\xe2\x82\xac')),
         '\\P{IsBasicLatin}': (ul("\xc0\xdf\xa9"), "ABC")
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_compl_esc()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
 def test_char_class_esc(self):
     """::
     charClassEsc ::= ( SingleCharEsc | MultiCharEsc | catEsc | complEsc )
     """
     tests = {
         '\\?': ("?", "\\"),
         '\\d': (u8(b'123\xd9\xa1\xd9\xa2\xd9\xa3'),
                 u8(b'ABC\xe2\x82\x81\xe2\x82\x82\xe2\x82\x83')),
         '\\p{S}': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}"),
         '\\P{S}': ("(){}", u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'))
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         cclass = p.require_char_class_esc()
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
Example #58
0
 def test_constructor(self):
     e = app.Categories(None)
     self.assertTrue(e.ns == app.APP_NAMESPACE, 'ns on construction')
     self.assertTrue(e.xmlname == "categories",
                     'element name on construction')
     self.assertTrue(e.get_base() is None,
                     "xml:base present on construction")
     self.assertTrue(e.get_lang() is None,
                     "xml:lang present on construction")
     self.assertTrue(e.get_space() is None,
                     "xml:space present on construction")
     attrs = e.get_attributes()
     self.assertTrue(
         sum(1 for k in dict_keys(attrs)) == 0,
         "Attributes present on construction")
     self.assertTrue(e.href is None, "href present on construction")
     self.assertTrue(e.fixed is None, "fixed on construction")
     self.assertTrue(e.scheme is None, "scheme present on construction")
     self.assertTrue(
         len(e.Category) == 0, "Category  list non empty on construction")
 def test_char_group(self):
     """::
     charGroup ::= posCharGroup | negCharGroup | charClassSub """
     tests = {
         'a-c': ("abc", "ABC-"),
         '^a-c': ("ABC-", "abc"),
         '^a-z-[^A-Z]': ("ABZ", "`abz{@[-"),
     }
     for b in dict_keys(tests):
         p = xsi.RegularExpressionParser(b)
         try:
             cclass = p.require_char_group()
         except xsi.RegularExpressionError:
             logging.debug("Failed to parse %s" % repr(b))
             raise
         self.assertTrue(p.the_char is None)
         t1, t2 = tests[b]
         for c in t1:
             self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
         for c in t2:
             self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))