diff options
author | nicholascar <nicholas.car@surroundaustralia.com> | 2021-12-01 12:24:28 +1000 |
---|---|---|
committer | nicholascar <nicholas.car@surroundaustralia.com> | 2021-12-01 12:24:28 +1000 |
commit | cc0f08ef67cf42873a0f5d96062eccca8e9a952b (patch) | |
tree | 5887ad2ddd1a54aa04a845da806fa013e98bfb0d /test/test_definednamespace_creator.py | |
parent | 910e831803858969783f5ce32cda3b0350441f92 (diff) | |
download | rdflib-sdo-https.tar.gz |
add script to generated DefinedNamespaces, with testssdo-https
Diffstat (limited to 'test/test_definednamespace_creator.py')
-rw-r--r-- | test/test_definednamespace_creator.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/test/test_definednamespace_creator.py b/test/test_definednamespace_creator.py new file mode 100644 index 00000000..7d8ebd55 --- /dev/null +++ b/test/test_definednamespace_creator.py @@ -0,0 +1,94 @@ +import sys +import subprocess +from pathlib import Path + + +def test_definednamespace_creator_qb(): + """ + Tests basic use of DefinedNamespace creator script using QB + """ + + definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + qb_data_file = Path(__file__).parent / "defined_namespaces" / "qb.ttl" + print("\n") + print(f"Using {definednamespace_script}...") + print(f"Testing {qb_data_file}...") + completed = subprocess.run( + [ + sys.executable, + str(definednamespace_script), + str(qb_data_file), + "http://purl.org/linked-data/cube#", + "QB", + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + assert completed.returncode == 0, "subprocess exited incorrectly" + assert Path.is_file(Path("_QB.py")), "_QB.py file not created" + has_ns = False + has_test_class = False + with open(Path("_QB.py")) as f: + for line in f.readlines(): + if '_NS = Namespace("http://purl.org/linked-data/cube#")' in line: + has_ns = True + if 'Attachable: URIRef # Abstract superclass for everything that can have attributes and dimensions' in line: + has_test_class = True + assert has_ns, "_QB.py does not contain _NS" + assert has_test_class, "_QB.py does not class Attachable" + + # cleanup + Path.unlink(Path("_QB.py")) + + +def test_definednamespace_creator_fake(): + """ + Tests incorrect use of DefinedNamespace creator script - + RDF file of unknonwn type + """ + + definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + qb_data_file = Path(__file__).parent / "defined_namespaces" / "fake.xxx" + print("\n") + print(f"Using {definednamespace_script}...") + print(f"Testing {qb_data_file}...(expected to fail)") + completed = subprocess.run( + [ + sys.executable, + str(definednamespace_script), + str(qb_data_file), + "http://purl.org/linked-data/cube#", + "QB", + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + assert completed.returncode == 1, "subprocess exited incorrectly (failure expected)" + + +def test_definednamespace_creator_bad_ns(): + """ + Tests incorrect use of DefinedNamespace creator script - + supplied namespace doesn't end in # or / + """ + + definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + qb_data_file = Path(__file__).parent / "defined_namespaces" / "fake.xxx" + print("\n") + print(f"Using {definednamespace_script}...") + print(f"Testing {qb_data_file}...(expected to fail - bad NS given)") + completed = subprocess.run( + [ + sys.executable, + str(definednamespace_script), + str(qb_data_file), + "http://purl.org/linked-data/cube", + "QB", + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + assert completed.returncode == 1, "subprocess exited incorrectly (failure expected)" |