def test_example_2(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesValues cntxt = setup_context(shex_2, rdf_2) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue3, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertTrue(nodeSatisfiesValues(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue4, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertTrue(nodeSatisfiesValues(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue6, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertFalse(nodeSatisfiesValues(cntxt, focus, nc)) self.assertEqual(['Node: "missing" not in value set:\n' '\t {"values": [{"value": "N/A"}, {"stem": "mailto:engineering-"...'], self.fail_reasons(cntxt)) focus = cntxt.graph.value(EX.issue7, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertFalse(nodeSatisfiesValues(cntxt, focus, nc)) self.assertEqual(['Node: <mailto:[email protected]> not in value set:\n' '\t {"values": [{"value": "N/A"}, {"stem": "mailto:engineering-"...'], self.fail_reasons(cntxt))
def test_trailing_zero(self): cntxt = setup_context(shex_2, rdf_2) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(URIRef("http://a.example/s1"), URIRef("http://a.example/p1")) cntxt.current_node = ParseNode(nodeSatisfiesNumericFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesNumericFacet(cntxt, focus, nc))
def test_basic_context(self): c = setup_context(shex_1, rdf_1) self.assertEqual(['http://schema.example/UserShape'], list(c.schema_id_map.keys())) self.assertTrue( isinstance(list(c.schema_id_map.values())[0], ShExJ.Shape)) self.assertEqual(['http://schema.example/te1'], list(c.te_id_map.keys())) self.assertTrue( isinstance(list(c.te_id_map.values())[0], ShExJ.TripleConstraint))
def test_example_1a(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesDataType cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue3, EX.submittedOn) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertFalse(nodeSatisfiesDataType(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue3a, EX.submittedOn) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertFalse(nodeSatisfiesDataType(cntxt, focus, nc))
def test_predicate_scan(self): c = setup_context(shex_1, rdf_1) predicates: List[URIRef] = [] c.visit_shapes( c.shapeExprFor(IRIREF('http://schema.example/UserShape')), triple_expr_finder, predicates) self.assertEqual([RDF.type], predicates) # Quick test of the utility function self.assertEqual( predicates_in_expression( c.shapeExprFor(IRIREF('http://schema.example/UserShape')), c), [ShExJ.IRIREF(str(u)) for u in predicates])
def test_example_1(self): cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue1, EX.submittedBy) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesStringFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue2, EX.submittedBy) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertFalse(nodeSatisfiesStringFacet(cntxt, focus, nc)) self.assertEqual(['String length violation - minimum: 10 actual: 4'], self.fail_reasons(cntxt))
def test_example_1(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesValues cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue1, EX.state) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertTrue(nodeSatisfiesValues(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue2, EX.state) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertFalse(nodeSatisfiesValues(cntxt, focus, nc)) self.assertEqual(['Node: :Unresolved not in value set:\n' '\t {"values": ["http://schema.example/Resolved", "http://schema...'], self.fail_reasons(cntxt))
def test_example_1(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesNodeKind cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue1, EX.state) cntxt.current_node = ParseNode(nodeSatisfiesNodeKind, nc, focus, cntxt) self.assertTrue(nodeSatisfiesNodeKind(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue3, EX.state) cntxt.current_node = ParseNode(nodeSatisfiesNodeKind, nc, focus, cntxt) self.assertFalse(nodeSatisfiesNodeKind(cntxt, focus, nc)) self.assertEqual(['Node kind mismatch have: Literal expected: iri'], self.fail_reasons(cntxt))
def test_example_2(self): cntxt = setup_context(shex_2, rdf_2) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue6, EX.submittedBy) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesStringFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue7, EX.submittedBy) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertFalse(nodeSatisfiesStringFacet(cntxt, focus, nc)) self.assertEqual([ 'Pattern match failure - pattern: genuser[0-9]+ flags:i string: ' 'http://schema.example/genContact817' ], self.fail_reasons(cntxt))
def test_example_2(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesDataType cntxt = setup_context(shex_2, rdf_2) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue3, RDFS.label) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertTrue(nodeSatisfiesDataType(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue4, RDFS.label) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertFalse(nodeSatisfiesDataType(cntxt, focus, nc)) self.assertEqual([ 'Datatype mismatch - expected: ' 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString actual: ' 'http://www.w3.org/2001/XMLSchema#string' ], self.fail_reasons(cntxt))
def test_example_1(self): cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue1, EX.confirmations) cntxt.current_node = ParseNode(nodeSatisfiesNumericFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesNumericFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue2, EX.confirmations) cntxt.current_node = ParseNode(nodeSatisfiesNumericFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesNumericFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue3, EX.confirmations) cntxt.current_node = ParseNode(nodeSatisfiesNumericFacet, nc, focus, cntxt) self.assertFalse(nodeSatisfiesNumericFacet(cntxt, focus, nc)) self.assertEqual( ['Numeric value volation - minimum inclusive: 1.0 actual: 0'], self.fail_reasons(cntxt))
def test_example_3(self): cntxt = setup_context(shex_3, rdf_3) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.product6, EX.trademark) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesStringFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.product7, EX.trademark) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertTrue(nodeSatisfiesStringFacet(cntxt, focus, nc)) focus = cntxt.graph.value(EX.product8, EX.trademark) cntxt.current_node = ParseNode(nodeSatisfiesStringFacet, nc, focus, cntxt) self.assertFalse(nodeSatisfiesStringFacet(cntxt, focus, nc)) self.assertEqual([ 'Pattern match failure - pattern: ^\\t\\\\𝒸\\?$ flags:None string: \t' '\\\\U0001D4B8?' ], self.fail_reasons(cntxt))
def test_example_3(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesValues cntxt = setup_context(shex_3, rdf_3) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue8, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertTrue(nodeSatisfiesValues(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue9, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertTrue(nodeSatisfiesValues(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue10, FOAF.mbox) cntxt.current_node = ParseNode(nodeSatisfiesValues, nc, focus, cntxt) self.assertFalse(nodeSatisfiesValues(cntxt, focus, nc)) self.assertEqual(['Node: <mailto:[email protected]> not in value set:\n' '\t {"values": [{"stem": {"type": "Wildcard"}, "exclusions": [{"...'], self.fail_reasons(cntxt))
def test_example_1(self): from pyshex.shape_expressions_language.p5_4_node_constraints import nodeSatisfiesDataType cntxt = setup_context(shex_1, rdf_1) nc = cntxt.schema.shapes[0].expression.valueExpr focus = cntxt.graph.value(EX.issue1, EX.submittedOn) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertTrue(nodeSatisfiesDataType(cntxt, focus, nc)) focus = cntxt.graph.value(EX.issue2, EX.submittedOn) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertFalse(nodeSatisfiesDataType(cntxt, focus, nc)) self.assertEqual([ 'Datatype mismatch - expected: http://www.w3.org/2001/XMLSchema#dateTime ' 'actual: http://www.w3.org/2001/XMLSchema#date' ], self.fail_reasons(cntxt)) focus = cntxt.graph.value(EX.issue3b, EX.submittedOn) cntxt.current_node = ParseNode(nodeSatisfiesDataType, nc, focus, cntxt) self.assertFalse(nodeSatisfiesDataType(cntxt, focus, nc)) self.assertEqual([ 'Datatype mismatch - expected: http://www.w3.org/2001/XMLSchema#dateTime ' 'actual: http://www.w3.org/2001/XMLSchema#date' ], self.fail_reasons(cntxt))