示例#1
0
    def test_compute_qname(self):
        """Test sequential assignment of unknown prefixes"""
        g = Graph()
        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar/baz")),
            ("ns1", URIRef("http://foo/bar/"), "baz"),
        )

        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar#baz")),
            ("ns2", URIRef("http://foo/bar#"), "baz"),
        )

        # should skip to ns4 when ns3 is already assigned
        g.bind("ns3", URIRef("http://example.org/"))
        self.assertEqual(
            g.compute_qname(URIRef("http://blip/blop")),
            ("ns4", URIRef("http://blip/"), "blop"),
        )

        # should return empty qnames correctly
        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar/")),
            ("ns1", URIRef("http://foo/bar/"), ""),
        )
示例#2
0
    def test_compute_qname(self):
        """Test sequential assignment of unknown prefixes"""
        g = Graph()
        self.assertEqual(g.compute_qname(URIRef("http://foo/bar/baz")),
                         ("ns1", URIRef("http://foo/bar/"), "baz"))

        self.assertEqual(g.compute_qname(URIRef("http://foo/bar#baz")),
                         ("ns2", URIRef("http://foo/bar#"), "baz"))

        # should skip to ns4 when ns3 is already assigned
        g.bind("ns3", URIRef("http://example.org/"))
        self.assertEqual(g.compute_qname(URIRef("http://blip/blop")),
                         ("ns4", URIRef("http://blip/"), "blop"))
示例#3
0
    def test_compute_qname(self):
        """Test sequential assignment of unknown prefixes"""
        g = Graph()
        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar/baz")),
            ("ns1", URIRef("http://foo/bar/"), "baz"),
        )

        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar#baz")),
            ("ns2", URIRef("http://foo/bar#"), "baz"),
        )

        # should skip to ns4 when ns3 is already assigned
        g.bind("ns3", URIRef("http://example.org/"))
        self.assertEqual(
            g.compute_qname(URIRef("http://blip/blop")),
            ("ns4", URIRef("http://blip/"), "blop"),
        )

        # should return empty qnames correctly
        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar/")),
            ("ns1", URIRef("http://foo/bar/"), ""),
        )

        # should compute qnames of URNs correctly as well
        self.assertEqual(
            g.compute_qname(URIRef("urn:ISSN:0167-6423")),
            ("ns5", URIRef("urn:ISSN:"), "0167-6423"),
        )

        self.assertEqual(
            g.compute_qname(URIRef("urn:ISSN:")),
            ("ns5", URIRef("urn:ISSN:"), ""),
        )

        # should compute qnames with parenthesis correctly
        self.assertEqual(
            g.compute_qname(URIRef("http://foo/bar/name_with_(parenthesis)")),
            ("ns1", URIRef("http://foo/bar/"), "name_with_(parenthesis)"),
        )