Skip to content

Commit

Permalink
Fix HasValue test . This test was updated in the SHT testsuite and th…
Browse files Browse the repository at this point in the history
…e DASH testsuite months ago.

Don't trigger custom constraint component (SPARQL-constraint-component) on sh_parameter, because sh_parameter is also used in SHACL-AF SPARQL Target Types, and thats unrelated to the former.
  • Loading branch information
ashleysommer committed Sep 6, 2020
1 parent 64d8123 commit 383665d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
5 changes: 1 addition & 4 deletions pyshacl/constraints/core/other_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ def _evaluate_has_value(self, target_graph, hv, f_v_dict):
# a_value_node = next(iter(value_nodes))
# rept = self.make_v_result(f, value_node=a_value_node)
# else:
if not self.shape.is_property_shape:
rept = self.make_v_result(target_graph, f, value_node=f)
else:
rept = self.make_v_result(target_graph, f, value_node=None)
rept = self.make_v_result(target_graph, f, value_node=None)
reports.append(rept)
return non_conformant, reports
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __init__(self, constraint, shape, validator, param_bind_map):
@classmethod
def constraint_parameters(cls):
# TODO:coverage: this is never used for this constraint?
return [SH_validator, SH_nodeValidator, SH_propertyValidator, SH_parameter]
return [SH_validator, SH_nodeValidator, SH_propertyValidator]

@classmethod
def constraint_name(cls):
Expand Down Expand Up @@ -399,12 +399,12 @@ def parameter_name(cls, parameter):
path = str(parameter.path())
hash_index = path.find('#')
if hash_index > 0:
ending = path[hash_index + 1 :]
ending = path[hash_index + 1:]
return ending
right_slash_index = path.rfind('/')
if right_slash_index > 0:
# TODO:coverage: No test for this case where path has a right slash
ending = path[right_slash_index + 1 :]
ending = path[right_slash_index + 1:]
return ending
raise ReportableRuntimeError("Cannot get a local name for {}".format(path))

Expand Down
12 changes: 6 additions & 6 deletions pyshacl/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ def advanced_target(self):
result_set = dict()
for c in custom_targets:
ct = dict()
is_types = set(self.sg.graph.objects(c, RDF_type))
is_target_type = False
parameters = set(self.sg.graph.objects(c, SH_parameter))
if SH_SPARQLTargetType in is_types or len(parameters) > 0:
is_target_type = True
ct['type'] = SH_SPARQLTargetType if is_target_type else SH_SPARQLTarget
selects = set(self.sg.graph.objects(c, SH_select))
if len(selects) < 1:
continue
is_types = set(self.sg.graph.objects(c, RDF_type))
is_type_target_type = False
parameters = set(self.sg.graph.objects(c, SH_parameter))
if SH_SPARQLTargetType in is_types or len(parameters) > 0:
is_type_target_type = True
ct['type'] = SH_SPARQLTargetType if is_type_target_type else SH_SPARQLTarget
ct['select'] = next(iter(selects))
qh = SPARQLQueryHelper(self, c, ct['select'], deactivated=self._deactivated)
ct['qh'] = qh
Expand Down
3 changes: 1 addition & 2 deletions test/resources/dash_tests/core/node/hasValue-001.test.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ ex:GraphValidationTestCase
sh:focusNode "Invalid String" ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:HasValueConstraintComponent ;
sh:sourceShape ex:TestShape ;
sh:value "Invalid String" ;
sh:sourceShape ex:TestShape
] ;
] ;
.
Expand Down
2 changes: 1 addition & 1 deletion test/resources/sht_tests/core/node/hasValue-001.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ex:TestShape
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:HasValueConstraintComponent ;
sh:sourceShape ex:TestShape ;
sh:value "Invalid String" ;
# See See https://github.com/w3c/data-shapes/issues/111: don't create sh:value "Invalid String" ;
] ;
] ;
mf:status sht:approved ;
Expand Down

0 comments on commit 383665d

Please sign in to comment.