Skip to content

Commit 5902fb8

Browse files
committed
[tests] ensure order of shapes and constraints for testing constraint removal
1 parent 0f042f2 commit 5902fb8

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

tests/test_main.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ def read_test(file):
277277
return result, solution
278278

279279

280+
@pytest.mark.skip
281+
def sort_constraints_by_path(list_):
282+
return sorted(list_, key=lambda c: c.path if c.path is not None else '')
283+
284+
280285
@pytest.mark.parametrize('params', [PARAMS_TC6.copy()])
281286
def test_tc6_remove_one(params):
282287
query = "PREFIX test6: <http://example.org/testGraph6#>\nSELECT DISTINCT ?x WHERE {\n?x test6:property0 ?p0 .\n?x ^test6:property2 ?p2 .\n?x test6:property3 ?p3 .\n?x test6:belongsTo ?y.\n}"
@@ -292,26 +297,15 @@ def test_tc6_remove_one(params):
292297

293298
shape_schema = prepare_validation(Config.from_request_form(params), Query(query), None)
294299
assert len(shape_schema.shapes) == 2
295-
constraints = shape_schema.shapes[0].constraints
300+
constraints = sort_constraints_by_path(shape_schema.shapesDict['<http://example.org/ShapeA>'].constraints)
296301
assert len(constraints) == 3
297302
for i, c in enumerate(constraints):
298303
if i == 0:
299-
assert isinstance(c, MinOnlyConstraint)
300-
assert c.path == '<http://example.org/testGraph6#property3>'
301-
assert c.options is None
302-
assert c.min == 1
303-
elif i == 1:
304-
assert isinstance(c, MinOnlyConstraint)
305-
assert c.path == '<http://example.org/testGraph6#belongsTo>'
306-
assert c.options is None
307-
assert c.min == 1
308-
assert c.shapeRef == '<http://example.org/ShapeB>'
309-
else:
310304
assert isinstance(c, MinOnlyConstraint)
311305
assert c.path is None
312306
assert isinstance(c.options, list)
313307
assert len(c.options) == 2
314-
for j, orc in enumerate(c.options):
308+
for j, orc in enumerate(sort_constraints_by_path(c.options)):
315309
if j == 0:
316310
assert isinstance(orc, MinOnlyConstraint)
317311
assert orc.path == '<http://example.org/testGraph6#property0>'
@@ -320,6 +314,17 @@ def test_tc6_remove_one(params):
320314
assert isinstance(orc, MaxOnlyConstraint)
321315
assert orc.path == '^<http://example.org/testGraph6#property2>'
322316
assert orc.max == 0
317+
elif i == 1:
318+
assert isinstance(c, MinOnlyConstraint)
319+
assert c.path == '<http://example.org/testGraph6#belongsTo>'
320+
assert c.options is None
321+
assert c.min == 1
322+
assert c.shapeRef == '<http://example.org/ShapeB>'
323+
else:
324+
assert isinstance(c, MinOnlyConstraint)
325+
assert c.path == '<http://example.org/testGraph6#property3>'
326+
assert c.options is None
327+
assert c.min == 1
323328

324329

325330
@pytest.mark.parametrize('params', [PARAMS_TC6.copy()])
@@ -336,19 +341,19 @@ def test_remove_down_to_one(params):
336341

337342
shape_schema = prepare_validation(Config.from_request_form(params), Query(query), None)
338343
assert len(shape_schema.shapes) == 1
339-
constraints = shape_schema.shapes[0].constraints
344+
constraints = sort_constraints_by_path(shape_schema.shapes[0].constraints)
340345
assert len(constraints) == 2
341346
for i, c in enumerate(constraints):
342347
if i == 0:
343348
assert isinstance(c, MinOnlyConstraint)
344-
assert c.path == '<http://example.org/testGraph6#property3>'
349+
assert c.path == '<http://example.org/testGraph6#property1>'
345350
assert c.options is None
346-
assert c.min == 1
351+
assert c.min == 3
347352
else:
348353
assert isinstance(c, MinOnlyConstraint)
349-
assert c.path == '<http://example.org/testGraph6#property1>'
354+
assert c.path == '<http://example.org/testGraph6#property3>'
350355
assert c.options is None
351-
assert c.min == 3
356+
assert c.min == 1
352357

353358

354359
@pytest.mark.parametrize('params', [PARAMS_TC6.copy()])

0 commit comments

Comments
 (0)