def test_vocabulary_is_set_of_names_without_datatypes(self): self.assertEqual(self.graph.vocabulary(), {URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), URI('http://xmlns.com/foaf/0.1/name'), URI('http://xmlns.com/foaf/0.1/knows'), Literal("John Lennon", XSD.string)})
def test_find_yields_valid_matches(self): triples = {(1, EX.prop, "foo"), (EX.a, EX.prop, Literal("bar")), (BlankNode('x'), RDF.type, BlankNode('y')), (EX.b, BlankNode(), EX.c)} matches = list(self.pattern.find(triples)) self.assertEqual(len(matches), 2) self.assert_({ self.uuu: EX.a, self.aaa: EX.prop, self.xxx: Literal("bar") } in matches) self.assert_({ self.uuu: BlankNode('x'), self.aaa: RDF.type, self.xxx: BlankNode('y') } in matches)
def test_names_is_set_of_uris_and_literals(self): self.assertEqual(self.graph.names(), {URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), URI('http://xmlns.com/foaf/0.1/name'), URI('http://xmlns.com/foaf/0.1/knows'), Literal("John Lennon", XSD.string), XSD.string})
def test_not_equal_to_frozenset_with_different_triples(self): triples = {(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), URI('http://www.example.org/staffid/85740')), (URI('http://www.example.org/staffid/85740'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Doe", XSD.string))} self.assertNotEqual(self.graph, frozenset(triples))
def setUp(self): self.triples = {(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), URI('http://www.example.org/staffid/85740')), (URI('http://www.example.org/staffid/85740'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Lennon", XSD.string))} self.graph = Graph(self.triples)
def test_not_equal_to_graph_with_different_number_of_unground_triples(self): graph = Graph({(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), URI('john')), (URI('john'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Lennon", XSD.string))}) self.assertNotEqual(self.graph, graph) self.assertNotEqual(graph, self.graph)
def setUp(self): self.triples = {(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), BlankNode('john')), (BlankNode('john'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Lennon", XSD.string)), (BlankNode('john'), URI('http://xmlns.com/foaf/0.1/knows'), BlankNode('paul'))} self.bijection = {(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), BlankNode('lennon')), (BlankNode('lennon'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Lennon", XSD.string)), (BlankNode('lennon'), URI('http://xmlns.com/foaf/0.1/knows'), BlankNode('starr'))} self.graph = Graph(self.triples)
def test_not_equal_to_graph_without_valid_bijection(self): graph = Graph({(URI('http://www.example.org/index.html'), URI('http://purl.org/dc/elements/1.1/creator'), BlankNode('john')), (BlankNode('john'), URI('http://xmlns.com/foaf/0.1/name'), Literal("John Lennon", XSD.string)), (BlankNode('paul'), URI('http://xmlns.com/foaf/0.1/knows'), BlankNode('john'))}) self.assertNotEqual(self.graph, graph) self.assertNotEqual(graph, self.graph)
def test_contains_instances_of_classes_in_class_set(self): uri = EX.test bnode = BlankNode() literal = Literal("cat") self.assert_(self.uuu.contains(uri)) self.assert_(self.uuu.contains(bnode)) self.assertFalse(self.uuu.contains(literal)) self.assert_(self.aaa.contains(uri)) self.assertFalse(self.aaa.contains(bnode)) self.assertFalse(self.aaa.contains(literal)) self.assert_(self.xxx.contains(uri)) self.assert_(self.xxx.contains(bnode)) self.assert_(self.xxx.contains(literal))
def test_compares_less_than_plain_literal(self): self.assert_(self.bnode < Literal("test"))
def test_compares_less_than_plain_literal(self): literal = Literal("a") self.assert_(self.uri < literal) self.assert_(not self.uri > literal)
def test_nodes_is_set_of_subjects_and_objects(self): self.assertEqual(self.graph.nodes(), {URI('http://www.example.org/index.html'), BlankNode('john'), BlankNode('paul'), Literal("John Lennon", XSD.string)})
def test_compares_less_than_typed_literal(self): literal = Literal("1", XSD.integer) self.assert_(self.uri < literal) self.assert_(not self.uri > literal)
def test_constructor_with_only_lexical_form_creates_plain_literal(self): literal = Literal("cat") self.assert_(isinstance(literal, PlainLiteral))
def test_constructor_with_language_creates_plain_literal(self): literal = Literal("cat", 'en') self.assert_(isinstance(literal, PlainLiteral))
def test_nodes_is_set_of_subjects_and_objects(self): self.assertEqual(self.graph.nodes(), {URI('http://www.example.org/index.html'), URI('http://www.example.org/staffid/85740'), Literal("John Lennon", XSD.string)})
def test_compares_less_than_typed_literal(self): self.assert_(self.bnode < Literal("0", XSD.integer))
def test_constructor_with_uri_creates_typed_literal(self): literal = Literal("cat", XSD.string) self.assert_(isinstance(literal, TypedLiteral))