|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# This software was developed at the National Institute of Standards |
| 4 | +# and Technology by employees of the Federal Government in the course |
| 5 | +# of their official duties. Pursuant to title 17 Section 105 of the |
| 6 | +# United States Code this software is not subject to copyright |
| 7 | +# protection and is in the public domain. NIST assumes no |
| 8 | +# responsibility whatsoever for its use by other parties, and makes |
| 9 | +# no guarantees, expressed or implied, about its quality, |
| 10 | +# reliability, or any other characteristic. |
| 11 | +# |
| 12 | +# We would appreciate acknowledgement if the software is used. |
| 13 | + |
| 14 | +import importlib.resources |
| 15 | +import pathlib |
| 16 | +import typing |
| 17 | + |
| 18 | +import rdflib # type: ignore |
| 19 | + |
| 20 | +import case_utils.ontology |
| 21 | + |
| 22 | +from case_utils.ontology.version_info import * |
| 23 | + |
| 24 | +NS_OWL = rdflib.OWL |
| 25 | + |
| 26 | +def test_case_ontology_version_info_versus_monolithic() -> None: |
| 27 | + ontology_graph = rdflib.Graph() |
| 28 | + |
| 29 | + ttl_filename = "case-" + CURRENT_CASE_VERSION + ".ttl" |
| 30 | + ttl_data = importlib.resources.read_text(case_utils.ontology, ttl_filename) |
| 31 | + ontology_graph.parse(data=ttl_data) |
| 32 | + |
| 33 | + version_info : typing.Optional[str] = None |
| 34 | + for triple in ontology_graph.triples(( |
| 35 | + rdflib.URIRef("https://ontology.caseontology.org/case/case"), |
| 36 | + NS_OWL.versionInfo, |
| 37 | + None |
| 38 | + )): |
| 39 | + version_info = str(triple[2]) |
| 40 | + assert not version_info is None, "Failed to retrieve owl:versionInfo" |
| 41 | + |
| 42 | + assert CURRENT_CASE_VERSION == version_info, "Version recorded in case_utils.ontology.version_info does not match built ontology" |
| 43 | + |
| 44 | +def test_case_ontology_version_info_versus_submodule() -> None: |
| 45 | + ontology_graph = rdflib.Graph() |
| 46 | + |
| 47 | + top_srcdir = pathlib.Path(__file__).parent / ".." / ".." / ".." |
| 48 | + assert (top_srcdir / ".gitmodules").exists(), "Hard-coded path to top_srcdir no longer correct" |
| 49 | + |
| 50 | + ttl_filepath = top_srcdir / "dependencies" / "CASE" / "ontology" / "master" / "case.ttl" |
| 51 | + |
| 52 | + ontology_graph.parse(str(ttl_filepath)) |
| 53 | + |
| 54 | + version_info : typing.Optional[str] = None |
| 55 | + for triple in ontology_graph.triples(( |
| 56 | + rdflib.URIRef("https://ontology.caseontology.org/case/case"), |
| 57 | + NS_OWL.versionInfo, |
| 58 | + None |
| 59 | + )): |
| 60 | + version_info = str(triple[2]) |
| 61 | + assert not version_info is None, "Failed to retrieve owl:versionInfo" |
| 62 | + |
| 63 | + assert CURRENT_CASE_VERSION == version_info, "Version recorded in case_utils.ontology.version_info does not match tracked ontology" |
0 commit comments