diff --git a/tests/test_python.py b/tests/test_python.py index 5a421db1..b99f2e9d 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -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 @@ -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", ], @@ -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" @@ -2136,7 +2131,7 @@ class Extension(model.extensible_class): DATA = { "@context": [ - model_context_url, + test_context_url, { "prefix": "http://example.org/shacl2code-test/", }, @@ -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): @@ -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", @@ -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 @@ -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", ], [ @@ -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 . @prefix rdf: . @@ -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", @@ -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", ], [ @@ -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 = [ @@ -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", @@ -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) @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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. @@ -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",