Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ def shacl2code_generate(args, python_args, outfile):


@pytest.fixture(scope="module")
def model_context_url(model_server):
yield model_server + "/test-context.json"


@pytest.fixture(scope="module")
def python_model(tmp_path_factory, model_context_url):
def python_model(tmp_path_factory, test_context_url):
tmp_directory = tmp_path_factory.mktemp("pythontestcontext")
module_name = "pymodel"
output_dir = tmp_directory / module_name
Expand All @@ -79,7 +74,7 @@ def python_model(tmp_path_factory, model_context_url):
"--input",
TEST_MODEL,
"--context",
model_context_url,
test_context_url,
"--jss-signature",
"signatures",
],
Expand Down Expand Up @@ -2121,7 +2116,7 @@ def test_varname_reserved_words(tmp_path):
del sys.modules[mod]


def test_extensible_properties(model, model_context_url):
def test_extensible_properties(model, test_context_url):

class Extension(model.extensible_class):
TYPE = "http://example.org/shacl2code-test/extension"
Expand All @@ -2136,7 +2131,7 @@ class Extension(model.extensible_class):

DATA = {
"@context": [
model_context_url,
test_context_url,
{
"prefix": "http://example.org/shacl2code-test/",
},
Expand Down Expand Up @@ -2169,7 +2164,7 @@ class Extension(model.extensible_class):
assert s.serialize_data(objset, True) == DATA


def test_custom_objset_index(model, model_context_url):
def test_custom_objset_index(model, test_context_url):
# Creates a derived objectset that indexes objects based on a property
class ObjectSet(model.SHACLObjectSet):
def create_index(self):
Expand All @@ -2185,7 +2180,7 @@ def add_index(self, obj):
d = model.JSONLDDeserializer()
d.deserialize_data(
{
"@context": model_context_url,
"@context": test_context_url,
"@graph": [
{
"@type": "test-class",
Expand Down Expand Up @@ -2394,7 +2389,7 @@ def test_prerelease_warning(model):
model.test_class()


def test_pre_release_cli_option(tmp_path_factory, model_context_url):
def test_pre_release_cli_option(tmp_path_factory, test_context_url):
tmp_directory = tmp_path_factory.mktemp("prerelease_test")
module_name = "pymodel_prerelease"
output_dir = tmp_directory / module_name
Expand All @@ -2403,7 +2398,7 @@ def test_pre_release_cli_option(tmp_path_factory, model_context_url):
"--input",
str(TEST_MODEL),
"--context",
model_context_url,
test_context_url,
"--pre-release",
],
[
Expand All @@ -2419,9 +2414,12 @@ def test_pre_release_cli_option(tmp_path_factory, model_context_url):
assert m.SHACL2CODE_TEST.is_prerelease is True
finally:
sys.path.remove(str(tmp_directory))
for mod in list(sys.modules):
if mod == module_name or mod.startswith(module_name + "."):
del sys.modules[mod]


def test_no_pre_release_cli_option(tmp_path, model_context_url):
def test_no_pre_release_cli_option(tmp_path, test_context_url):
ttl_content = """
@base <http://example.org/shacl2code-test/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -2445,7 +2443,7 @@ def test_no_pre_release_cli_option(tmp_path, model_context_url):
"--input",
str(ttl_file),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand All @@ -2468,7 +2466,7 @@ def test_no_pre_release_cli_option(tmp_path, model_context_url):
"--input",
str(ttl_file),
"--context",
model_context_url,
test_context_url,
"--no-pre-release",
],
[
Expand All @@ -2486,7 +2484,7 @@ def test_no_pre_release_cli_option(tmp_path, model_context_url):
sys.path.remove(str(tmp_path))


def test_pre_release_annotations_cases(tmp_path, model_context_url):
def test_pre_release_annotations_cases(tmp_path, test_context_url):
# The number in the comment indicates the precedence of the annotation.
# 1 is the highest precedence (force by command line option)
cases = [
Expand Down Expand Up @@ -2559,7 +2557,7 @@ def test_pre_release_annotations_cases(tmp_path, model_context_url):
"--input",
str(ttl_file),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand All @@ -2578,7 +2576,7 @@ def test_pre_release_annotations_cases(tmp_path, model_context_url):
sys.path.remove(str(tmp_path))


def test_pre_release_precedence(tmp_path, model_context_url):
def test_pre_release_precedence(tmp_path, test_context_url):
# Example 1:
# 2) sh-to-code:isPreRelease false (False)
# 3) adms:status EU SEMIC DEVELOP (True)
Expand Down Expand Up @@ -2606,7 +2604,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
"--input",
str(ttl_file_1),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand Down Expand Up @@ -2649,7 +2647,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
"--input",
str(ttl_file_2),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand Down Expand Up @@ -2692,7 +2690,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
"--input",
str(ttl_file_3),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand Down Expand Up @@ -2735,7 +2733,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
"--input",
str(ttl_file_4),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand Down Expand Up @@ -2778,7 +2776,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
"--input",
str(ttl_file_5),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand All @@ -2795,7 +2793,7 @@ def test_pre_release_precedence(tmp_path, model_context_url):
sys.path.remove(str(tmp_path))


def test_pre_release_multi_valued_annotations(tmp_path, model_context_url):
def test_pre_release_multi_valued_annotations(tmp_path, test_context_url):
# Each of these predicates can legally repeat.
# A stable-looking value listed first must not hide
# a pre-release-indicating value listed after it.
Expand Down Expand Up @@ -2869,7 +2867,7 @@ def test_pre_release_multi_valued_annotations(tmp_path, model_context_url):
"--input",
str(ttl_file),
"--context",
model_context_url,
test_context_url,
],
[
"--version",
Expand Down
Loading