Exemplo n.º 1
0
    def test_numeric(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "number(//TagWithNumeric)")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("numeric", evaluated[0]["match"])
        self.assertEqual(250, float(evaluated[0]["value"]))
Exemplo n.º 2
0
    def test_numeric(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "number(//TagWithNumeric)")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("numeric", evaluated[0]["match"])
        self.assertEqual(250, float(evaluated[0]["value"]))
Exemplo n.º 3
0
    def test_parentless_text(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "'hello there'")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("string", evaluated[0]["match"])
        self.assertEqual("hello there", evaluated[0]["value"])
Exemplo n.º 4
0
    def test_attribute(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//TagWithAttribute/@attribute")

        self.assertEqual(5, evaluated[0]["line_number"])
        self.assertEqual("@attribute", evaluated[0]["match"])
        self.assertEqual("attribute text", evaluated[0]["value"])
Exemplo n.º 5
0
    def test_text(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//TagWithText/text()")

        self.assertEqual(4, evaluated[0]["line_number"])
        self.assertEqual("string", evaluated[0]["match"])
        self.assertEqual("element text", evaluated[0]["value"])
Exemplo n.º 6
0
    def test_node(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//Tag")

        self.assertEqual(3, evaluated[0]["line_number"])
        self.assertEqual("<Tag>", evaluated[0]["match"])
        self.assertEqual("", evaluated[0]["value"])
Exemplo n.º 7
0
    def test_node(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//Tag")

        self.assertEqual(3, evaluated[0]["line_number"])
        self.assertEqual("<Tag>", evaluated[0]["match"])
        self.assertEqual("", evaluated[0]["value"])
Exemplo n.º 8
0
    def test_attribute(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//TagWithAttribute/@attribute")

        self.assertEqual(5, evaluated[0]["line_number"])
        self.assertEqual("@attribute", evaluated[0]["match"])
        self.assertEqual("attribute text", evaluated[0]["value"])
Exemplo n.º 9
0
    def test_parentless_text(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "'hello there'")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("string", evaluated[0]["match"])
        self.assertEqual("hello there", evaluated[0]["value"])
Exemplo n.º 10
0
    def test_text(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//TagWithText/text()")

        self.assertEqual(4, evaluated[0]["line_number"])
        self.assertEqual("string", evaluated[0]["match"])
        self.assertEqual("element text", evaluated[0]["value"])
Exemplo n.º 11
0
    def test_boolean(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(
            xml, "//TagWithAttribute/@attribute = 'attribute text'")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("boolean", evaluated[0]["match"])
        self.assertEqual("true()", evaluated[0]["value"])
Exemplo n.º 12
0
    def test_boolean(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, 
                        "//TagWithAttribute/@attribute = 'attribute text'")

        self.assertEqual(None, evaluated[0]["line_number"])
        self.assertEqual("boolean", evaluated[0]["match"])
        self.assertEqual("true()", evaluated[0]["value"])
Exemplo n.º 13
0
    def test_namespaces(self):
        namespaces = dict()
        namespaces["a"] = "http://someurl.org"
        namespaces["b"] = "http://anotherurl.org"

        xml = read_sample_xml("namespaces.xml")
        evaluatedA = xpath.evaluate(xml, "//a:Tag", namespaces)
        evaluatedB = xpath.evaluate(xml, "//b:Tag", namespaces)

        self.assertEqual(3, evaluatedA[0]["line_number"])
        self.assertEqual(4, evaluatedB[0]["line_number"])
Exemplo n.º 14
0
    def test_namespaces(self):
        namespaces = dict()
        namespaces["a"] = "http://someurl.org"
        namespaces["b"] = "http://anotherurl.org"

        xml = read_sample_xml("namespaces.xml")
        evaluatedA = xpath.evaluate(xml, "//a:Tag", namespaces)
        evaluatedB = xpath.evaluate(xml, "//b:Tag", namespaces)

        self.assertEqual(3, evaluatedA[0]["line_number"])
        self.assertEqual(4, evaluatedB[0]["line_number"])
Exemplo n.º 15
0
    def test_large_xml_line_number(self):
        #Reported that lxml cuts off sourceline at 65535 due to
        #libxml2 limitation https://bugs.launchpad.net/lxml/+bug/674775
        xml = read_sample_xml("very_large.xml")
        evaluated = xpath.evaluate(xml, "//Match")

        self.assertEqual(3, evaluated[0]["line_number"])
        self.assertEqual(65534, evaluated[1]["line_number"])
        self.assertEqual(65535, evaluated[2]["line_number"])
        self.assertEqual(70000, evaluated[3]["line_number"])
        self.assertEqual(135532, evaluated[4]["line_number"])
        self.assertEqual(135533, evaluated[5]["line_number"])
        self.assertEqual(139998, evaluated[6]["line_number"])
Exemplo n.º 16
0
    def test_large_xml_line_number(self):
        #Reported that lxml cuts off sourceline at 65535 due to
        #libxml2 limitation https://bugs.launchpad.net/lxml/+bug/674775
        xml = read_sample_xml("very_large.xml")
        evaluated = xpath.evaluate(xml, "//Match")

        self.assertEqual(3, evaluated[0]["line_number"])
        self.assertEqual(65534, evaluated[1]["line_number"])
        self.assertEqual(65535, evaluated[2]["line_number"])
        self.assertEqual(70000, evaluated[3]["line_number"])
        self.assertEqual(135532, evaluated[4]["line_number"])
        self.assertEqual(135533, evaluated[5]["line_number"])
        self.assertEqual(139998, evaluated[6]["line_number"])
    def test_default_namespace_is_called_default(self):
        xml = read_sample_xml("namespaces.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://someurl.org", prefixes["default"])
        self.assertEqual("http://anotherurl.org", prefixes["ns"])
Exemplo n.º 18
0
    def test_multiline_xml(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//Tag")

        self.assertEqual(3, evaluated[0]["line_number"])
Exemplo n.º 19
0
    def test_multiline_xml(self):
        xml = read_sample_xml("simple.xml")
        evaluated = xpath.evaluate(xml, "//Tag")

        self.assertEqual(3, evaluated[0]["line_number"])
Exemplo n.º 20
0
    def test_malformed_xml_throws_error(self):
        xml = read_sample_xml("malformed.xml")

        with self.assertRaises(namespace_prefix_guesser.PrefixGuessingError):
            prefixes = namespace_prefix_guesser.guess_prefixes(xml)
Exemplo n.º 21
0
    def test_default_namespace_is_called_default(self):
        xml = read_sample_xml("namespaces.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://someurl.org", prefixes["default"])
        self.assertEqual("http://anotherurl.org", prefixes["ns"])
Exemplo n.º 22
0
    def test_undefined_namespace_throws_wrapped_exception(self):
        xml = read_sample_xml("simple.xml")

        with self.assertRaises(XPathError):
            xpath.evaluate(xml, "//blarg:Tag")
    def test_first_node_depth_first_to_define_prefix_claims_it(self):
        xml = read_sample_xml("reused_namespace.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://thirdurl.org", prefixes["another"])
    def test_malformed_xml_throws_error(self):
        xml = read_sample_xml("malformed.xml")

        with self.assertRaises(namespace_prefix_guesser.PrefixGuessingError):
            prefixes = namespace_prefix_guesser.guess_prefixes(xml)
Exemplo n.º 25
0
    def test_undefined_namespace_throws_wrapped_exception(self):
        xml = read_sample_xml("simple.xml")

        with self.assertRaises(XPathError):
            xpath.evaluate(xml, "//blarg:Tag")
    def test_single_namespace_prefix_is_guessed(self):
        xml = read_sample_xml("single_namespace.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://onlyPrefix.com", prefixes["onlyPrefix"])
Exemplo n.º 27
0
    def test_first_node_depth_first_to_define_prefix_claims_it(self):
        xml = read_sample_xml("reused_namespace.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://thirdurl.org", prefixes["another"])
Exemplo n.º 28
0
    def test_bad_xpath_throws_wrapped_exception(self):
        xml = read_sample_xml("simple.xml")

        with self.assertRaises(XPathError):
            xpath.evaluate(xml, "//bla()rg")
Exemplo n.º 29
0
    def test_single_namespace_prefix_is_guessed(self):
        xml = read_sample_xml("single_namespace.xml")
        prefixes = namespace_prefix_guesser.guess_prefixes(xml)

        self.assertEqual("http://onlyPrefix.com", prefixes["onlyPrefix"])
Exemplo n.º 30
0
    def test_bad_xpath_throws_wrapped_exception(self):
        xml = read_sample_xml("simple.xml")

        with self.assertRaises(XPathError):
            xpath.evaluate(xml, "//bla()rg")