Skip to content

FAILED test/test_js/test_js_rules.py::test_js_rules #293

@santiagorr

Description

@santiagorr

Hi there!

When trying to package pyshacl for Debian, I am getting failures with six tests:

...
=========================== short test summary info ============================
FAILED test/test_js/test_js_constraint_component.py::test_js_constraint_component - pyshacl.errors.ConstraintLoadError: A Custom Constraint must include one of a SPARQLConstraintComponent validator or a JSConstraint validator.
For reference, see https://www.w3.org/TR/shacl/#constraint-components-validators
FAILED test/test_js/test_js_constraint_path_component.py::test_js_constraint_path_component - pyshacl.errors.ConstraintLoadError: A Custom Constraint must include one of a SPARQLConstraintComponent validator or a JSConstraint validator.
For reference, see https://www.w3.org/TR/shacl/#constraint-components-validators
FAILED test/test_js/test_js_function.py::test_js_function - assert not True
FAILED test/test_js/test_js_rules.py::test_js_rules - pyshacl.errors.RuleLoadError: when using sh:rule, the Rule must be defined as either a TripleRule or SPARQLRule.
For reference, see https://www.w3.org/TR/shacl-af/#rules-syntax
FAILED test/test_js/test_js_target.py::test_js_target - KeyError: 'type'
FAILED test/test_js/test_js_target_type.py::test_js_target_type - pyshacl.errors.ShapeLoadError: None of these types match a TargetType: http://datashapes.org/sh/tests/js/target/jsTargetType-001.test#PeopleBornInCountryTarget
For reference, see https://www.w3.org/TR/shacl-af/#SPARQLTargetType
============ 6 failed, 362 passed, 21 warnings in 88.58s (0:01:28) =============
...

This is the report for test_js_rules.py::test_js_rules: https://salsa.debian.org/python-team/packages/pyshacl/-/jobs/7443344#L1667

________________________________ test_js_rules _________________________________
    def test_js_rules():
        s1 = Graph().parse(data=shapes_graph, format="turtle")
        g1 = Graph().parse(data=data_graph, format="turtle")
>       conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True)
test/test_js/test_js_rules.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyshacl/entrypoints.py:178: in validate
    conforms, report_graph, report_text = validator.run()
pyshacl/validator.py:279: in run
    'rules': gather_rules(executor, self.shacl_graph, from_shapes=gather_from_shapes),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
executor = SHACLExecutor(validator=<pyshacl.validator.Validator object at 0x7f619fbc9810>, advanced_mode=True, abort_on_first=Fal...e, allow_warnings=False, iterate_rules=False, debug=True, sparql_mode=False, max_validation_depth=15, focus_nodes=None)
shacl_graph = <pyshacl.shapes_graph.ShapesGraph object at 0x7f619fbf42d0>
from_shapes = None
    def gather_rules(
        executor: SHACLExecutor,
        shacl_graph: 'ShapesGraph',
        from_shapes: Union[Sequence[Union[URIRef, BNode]], None] = None,
    ) -> Dict['Shape', List['SHACLRule']]:
        """
        :param executor:
        :type executor: SHACLExecutor
        :param shacl_graph:
        :type shacl_graph: ShapesGraph
        :return:
        :rtype: Dict[Shape, List[SHACLRule]]
        """
        triple_rule_nodes = set(shacl_graph.subjects(RDF_type, SH_TripleRule))
        sparql_rule_nodes = set(shacl_graph.subjects(RDF_type, SH_SPARQLRule))
        if shacl_graph.js_enabled:
            from pyshacl.extras.js.rules import JSRule, SH_JSRule
    
            js_rule_nodes = set(shacl_graph.subjects(RDF_type, SH_JSRule))
            use_JSRule: Union[bool, Type] = JSRule
        else:
            use_JSRule = False
            js_rule_nodes = set()
        overlaps = triple_rule_nodes.intersection(sparql_rule_nodes)
        if len(overlaps) > 0:
            raise RuleLoadError(
                "A SHACL Rule cannot be both a TripleRule and a SPARQLRule.",
                "https://www.w3.org/TR/shacl-af/#rules-syntax",
            )
        overlaps = triple_rule_nodes.intersection(js_rule_nodes)
        if len(overlaps) > 0:
            raise RuleLoadError(
                "A SHACL Rule cannot be both a TripleRule and a JSRule.",
                "https://www.w3.org/TR/shacl-af/#rules-syntax",
            )
        overlaps = sparql_rule_nodes.intersection(js_rule_nodes)
        if len(overlaps) > 0:
            raise RuleLoadError(
                "A SHACL Rule cannot be both a SPARQLRule and a JSRule.",
                "https://www.w3.org/TR/shacl-af/#rules-syntax",
            )
        used_rules = shacl_graph.subject_objects(SH_rule)
        ret_rules = defaultdict(list)
        for sub, obj in used_rules:
            if from_shapes is not None and sub not in from_shapes:
                # Skipping rule that is not in the whitelist of Shapes to use
                continue
            try:
                shape: Shape = shacl_graph.lookup_shape_from_node(sub)
            except (AttributeError, KeyError):
                raise RuleLoadError(
                    "The shape that rule is attached to is not a valid SHACL Shape.",
                    "https://www.w3.org/TR/shacl-af/#rules-syntax",
                )
            if obj in triple_rule_nodes:
                rule: SHACLRule = TripleRule(executor, shape, obj, iterate=executor.iterate_rules)
            elif obj in sparql_rule_nodes:
                rule = SPARQLRule(executor, shape, obj)
            elif use_JSRule and callable(use_JSRule) and obj in js_rule_nodes:
                rule = use_JSRule(executor, shape, obj)
            else:
>               raise RuleLoadError(
                    "when using sh:rule, the Rule must be defined as either a TripleRule or SPARQLRule.",
                    "https://www.w3.org/TR/shacl-af/#rules-syntax",
                )
E               pyshacl.errors.RuleLoadError: when using sh:rule, the Rule must be defined as either a TripleRule or SPARQLRule.
E               For reference, see https://www.w3.org/TR/shacl-af/#rules-syntax
pyshacl/rules/__init__.py:81: RuleLoadError

Full log can be found at: https://salsa.debian.org/python-team/packages/pyshacl/-/jobs/7443344

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions