From 22105b4e8a65c2c6037edf5eaeee9edb5e3d756b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:47:20 +0200 Subject: [PATCH 01/13] [pre-commit.ci] pre-commit autoupdate (#770) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.1.0 → v4.2.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.1.0...v4.2.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c2fffa8a..7182da47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.2.0 hooks: - id: check-json - id: check-yaml From 1c8537bf3a1547be225e72d418528b95155342a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= <43052541+kysrpex@users.noreply.github.com> Date: Tue, 26 Apr 2022 08:58:14 +0200 Subject: [PATCH 02/13] Apply automatic pre-commit updates to `dev` instead of `master` (#777) --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7182da47..475338ba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,3 +21,6 @@ repos: hooks: - id: black args: [--line-length, "79"] + +ci: + autoupdate_branch: 'dev' From 641a24ef9accb78b992e82ca2de7dfe34c062fa8 Mon Sep 17 00:00:00 2001 From: Adham Hashibon <78446902+adhamhashibon@users.noreply.github.com> Date: Fri, 10 Jun 2022 15:15:06 +0100 Subject: [PATCH 03/13] Fix wrong argument name for `export_cuds` in `example_rdf_import_export.py` (#778) --- examples/example_rdf_import_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_rdf_import_export.py b/examples/example_rdf_import_export.py index 2c5082ec..286a4973 100644 --- a/examples/example_rdf_import_export.py +++ b/examples/example_rdf_import_export.py @@ -38,7 +38,7 @@ ) # Export from Core Session -export_cuds(path="test.rdf", format="ttl") +export_cuds(file="test.rdf", format="ttl") # Check output with open("test.rdf", encoding="utf-8") as f: @@ -50,7 +50,7 @@ with SqliteSession(path="test.db") as session: w = city.CityWrapper(session=session) w.add(c) - export_cuds(session, path="test.rdf", format="ttl") + export_cuds(session, file="test.rdf", format="ttl") # Check output with open("test.rdf", encoding="utf-8") as f: From 7392b20811c00d4d9f70956a5eed671fddaf3e38 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:46:40 +0200 Subject: [PATCH 04/13] [pre-commit.ci] pre-commit autoupdate (#787) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.2.0 → v4.3.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.2.0...v4.3.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 475338ba..bae067c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.3.0 hooks: - id: check-json - id: check-yaml From 412903ad85f0ac558daaa211a6947db3d80bc1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= <43052541+kysrpex@users.noreply.github.com> Date: Wed, 13 Jul 2022 17:55:29 +0200 Subject: [PATCH 05/13] Fetch FOAF using HTTPS (`dev`) (#802) * Fetch FOAF using HTTPS * Add quotes --- osp/core/ontology/docs/foaf.yml | 2 +- tests/test_installation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osp/core/ontology/docs/foaf.yml b/osp/core/ontology/docs/foaf.yml index f15eaf59..ea9d399c 100644 --- a/osp/core/ontology/docs/foaf.yml +++ b/osp/core/ontology/docs/foaf.yml @@ -1,6 +1,6 @@ --- identifier: foaf -ontology_file: http://xmlns.com/foaf/spec/index.rdf +ontology_file: "https://xmlns.com/foaf/spec/index.rdf" reference_by_label: False namespaces: foaf: "http://xmlns.com/foaf/0.1/" diff --git a/tests/test_installation.py b/tests/test_installation.py index a2ff2d19..9a3d0c05 100644 --- a/tests/test_installation.py +++ b/tests/test_installation.py @@ -191,7 +191,7 @@ def test_conflicting_labels(self): """ FOAF = """ identifier: foaf_TEST - ontology_file: http://xmlns.com/foaf/spec/index.rdf + ontology_file: https://xmlns.com/foaf/spec/index.rdf reference_by_label: True namespaces: foaf_TEST: "http://xmlns.com/foaf/0.1/" From eeff5b0253dd2c9a742ab33ea9ab435fad2f468a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Jul 2022 18:01:49 +0200 Subject: [PATCH 06/13] [pre-commit.ci] pre-commit autoupdate (#800) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.3.0 → 22.6.0](https://github.com/psf/black/compare/22.3.0...22.6.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: José Manuel Domínguez <43052541+kysrpex@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bae067c1..42034521 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: args: [--profile, black, --filter-files, --line-length, "79"] - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 22.6.0 hooks: - id: black args: [--line-length, "79"] From 70f9277b6025af6522b61fd3fac12852c2c920ed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 14:55:02 +0200 Subject: [PATCH 07/13] [pre-commit.ci] pre-commit autoupdate (#808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.6.0 → 22.8.0](https://github.com/psf/black/compare/22.6.0...22.8.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: José Manuel Domínguez --- .pre-commit-config.yaml | 2 +- osp/core/ontology/docs/foaf.yml | 2 +- tests/test_installation.py | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42034521..b3b62335 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: args: [--profile, black, --filter-files, --line-length, "79"] - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 22.8.0 hooks: - id: black args: [--line-length, "79"] diff --git a/osp/core/ontology/docs/foaf.yml b/osp/core/ontology/docs/foaf.yml index ea9d399c..a2a38161 100644 --- a/osp/core/ontology/docs/foaf.yml +++ b/osp/core/ontology/docs/foaf.yml @@ -1,6 +1,6 @@ --- identifier: foaf -ontology_file: "https://xmlns.com/foaf/spec/index.rdf" +ontology_file: "https://web.archive.org/web/20220614185720if_/http://xmlns.com/foaf/spec/index.rdf" reference_by_label: False namespaces: foaf: "http://xmlns.com/foaf/0.1/" diff --git a/tests/test_installation.py b/tests/test_installation.py index 9a3d0c05..c2fc2a7c 100644 --- a/tests/test_installation.py +++ b/tests/test_installation.py @@ -189,9 +189,13 @@ def test_conflicting_labels(self): label for multiple IRIs. An error is only raised on installation if the reference_by_label option is set to Tue in the yml file. """ - FOAF = """ + FOAF_URL = ( + "https://web.archive.org/web/20220614185720if_/" + "http://xmlns.com/foaf/spec/index.rdf" + ) + FOAF = f""" identifier: foaf_TEST - ontology_file: https://xmlns.com/foaf/spec/index.rdf + ontology_file: "{FOAF_URL}" reference_by_label: True namespaces: foaf_TEST: "http://xmlns.com/foaf/0.1/" From 0c9d9449ec2c84e379e49ade222ad83c4ecc7498 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 08:37:44 +0200 Subject: [PATCH 08/13] [pre-commit.ci] pre-commit autoupdate (#827) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 22.8.0 → 22.10.0](https://github.com/psf/black/compare/22.8.0...22.10.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b3b62335..9b58ca81 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: args: [--profile, black, --filter-files, --line-length, "79"] - repo: https://github.com/psf/black - rev: 22.8.0 + rev: 22.10.0 hooks: - id: black args: [--line-length, "79"] From 231d72c50988019be2411b22316b0042385289ed Mon Sep 17 00:00:00 2001 From: MBueschelberger <46421269+MBueschelberger@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:08:47 +0200 Subject: [PATCH 09/13] Enh/attributes in schema validation (#822) * add checking of data properties (attributes) in schema validation * Use FOAF from web archive --- osp/core/utils/schema_validation.py | 20 +++++++++-- tests/test_utils.py | 7 ++++ ..._validation_schema_city_with_attribute.yml | 33 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tests/test_validation_schema_city_with_attribute.yml diff --git a/osp/core/utils/schema_validation.py b/osp/core/utils/schema_validation.py index 618dc811..bf5f9f58 100644 --- a/osp/core/utils/schema_validation.py +++ b/osp/core/utils/schema_validation.py @@ -5,6 +5,7 @@ import yaml from osp.core.namespaces import get_entity +from osp.core.ontology import OntologyAttribute, OntologyRelationship logger = logging.getLogger(__name__) @@ -97,9 +98,22 @@ def _load_data_model_from_yaml(data_model_file): def _check_cuds_object_cardinality(origin_cuds, dest_oclass, rel, constraints): - actual_cardinality = len( - origin_cuds.get(rel=get_entity(rel), oclass=get_entity(dest_oclass)) - ) + rel_entity = get_entity(rel) + + if type(rel_entity) == OntologyRelationship: + actual_cardinality = len( + origin_cuds.get(rel=rel_entity, oclass=get_entity(dest_oclass)) + ) + elif type(rel_entity) == OntologyAttribute: + # No datatype checking since this is already done when Cuds are + # instantiated or imported from a file + actual_cardinality = ( + 1 if rel_entity in origin_cuds.get_attributes() else 0 + ) + else: + raise ConsistencyError( + f"Relation '{rel}' not supported for {origin_cuds.oclass}." + ) min, max = _interpret_cardinality_value_from_constraints(constraints) if actual_cardinality < min or actual_cardinality > max: diff --git a/tests/test_utils.py b/tests/test_utils.py index ea373297..44492af5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -134,6 +134,11 @@ def test_validate_tree_against_schema(self): "test_validation_schema_city_with_optional_subtree.yml", ) + schema_file_with_attribute = os.path.join( + os.path.dirname(__file__), + "test_validation_schema_city_with_attribute.yml", + ) + c = city.City(name="freiburg") # empty city is not valid @@ -188,6 +193,8 @@ def test_validate_tree_against_schema(self): schema_file_with_missing_entity, ) + validate_tree_against_schema(c, schema_file_with_attribute) + def test_branch(self): """Test the branch function.""" x = branch( diff --git a/tests/test_validation_schema_city_with_attribute.yml b/tests/test_validation_schema_city_with_attribute.yml new file mode 100644 index 00000000..4b62e872 --- /dev/null +++ b/tests/test_validation_schema_city_with_attribute.yml @@ -0,0 +1,33 @@ +version: "1.0.0" + +oclass: city.City + +model: + city.City: + city.name: + STRING: + cardinality: 1 + city.hasInhabitant: + city.Citizen: + cardinality: 1-2 + city.hasPart: + city.Neighborhood: + cardinality: 1 + + city.Neighborhood: + city.name: + STRING: + cardinality: 1 + city.hasPart: + city.Street: + cardinality: 1+ + + city.Street: + city.name: + STRING: + cardinality: 1 + + city.Citizen: + city.name: + STRING: + cardinality: 1 From 1b4a1e9b8c1d75fb7dc4acb3400f46f0db253f1e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:22:01 +0100 Subject: [PATCH 10/13] [pre-commit.ci] pre-commit autoupdate (#831) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.3.0 → v4.4.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.3.0...v4.4.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b58ca81..674a5d46 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-json - id: check-yaml From c7b984cb73cd2b5b23ffd9f1d2dc2bba179ddcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= <43052541+kysrpex@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:32:58 +0100 Subject: [PATCH 11/13] Use runners labeled with `simphony-osp` for the CI (#835) --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6c50466..f1832e63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request jobs: PEP8: - runs-on: self-hosted + runs-on: [self-hosted, simphony-osp] steps: - uses: actions/checkout@v3 @@ -16,7 +16,7 @@ jobs: run: pre-commit run --all-files complexity: - runs-on: self-hosted + runs-on: [self-hosted, simphony-osp] steps: - uses: actions/checkout@v3 @@ -26,7 +26,7 @@ jobs: radon mi -s . security: - runs-on: self-hosted + runs-on: [self-hosted, simphony-osp] steps: - uses: actions/checkout@v3 @@ -34,7 +34,7 @@ jobs: run: bandit -r osp --skip B101 testing: - runs-on: self-hosted + runs-on: [self-hosted, simphony-osp] steps: - uses: actions/checkout@v3 - name: tox From 3441c73c5bd3bd21030d35c3213d7c6afae40679 Mon Sep 17 00:00:00 2001 From: MBueschelberger <46421269+MBueschelberger@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:33:59 +0100 Subject: [PATCH 12/13] Schema validation attribute values and length (#830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add checking length and value of the attribute of cuds in schema validation. * Add option for strict check in schema validation. Authored-by: Matthias Büschelberger --- osp/core/utils/schema_validation.py | 93 ++++++++++++++++--- tests/test_utils.py | 25 ++++- ...ation_schema_city_with_attribute_value.yml | 40 ++++++++ 3 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 tests/test_validation_schema_city_with_attribute_value.yml diff --git a/osp/core/utils/schema_validation.py b/osp/core/utils/schema_validation.py index bf5f9f58..40f1bda2 100644 --- a/osp/core/utils/schema_validation.py +++ b/osp/core/utils/schema_validation.py @@ -6,6 +6,7 @@ from osp.core.namespaces import get_entity from osp.core.ontology import OntologyAttribute, OntologyRelationship +from osp.core.ontology.datatypes import YML_DATATYPES logger = logging.getLogger(__name__) @@ -18,7 +19,7 @@ class CardinalityError(Exception): """A cardinality constraint is violated.""" -def validate_tree_against_schema(root_obj, schema_file): +def validate_tree_against_schema(root_obj, schema_file, strict_check=False): """Test cardinality constraints on given CUDS tree. The tree that starts at root_obj. @@ -28,6 +29,8 @@ def validate_tree_against_schema(root_obj, schema_file): root_obj (Cuds): The root CUDS object of the tree schema_file (str): The path to the schema file that defines the constraints + strict_check (bool): whether extra cuds not listed in + the schema_file should be tolerated or not Raise: Exception: Tells the user which constraint was violated @@ -68,9 +71,12 @@ def validate_tree_against_schema(root_obj, schema_file): try: relationships = data_model_dict["model"][oclass] except KeyError: - # TODO ask Yoav: is it ok when there is an object - # in the tree that is not part of the datamodel? - continue + if strict_check: + message = f"An entity for {oclass} was found," + " but it is not part of the provided schema" + raise ConsistencyError(message) + else: + continue if relationships is None: # if there are no relationships defined, # the only constraint is that the object exists @@ -97,7 +103,6 @@ def _load_data_model_from_yaml(data_model_file): def _check_cuds_object_cardinality(origin_cuds, dest_oclass, rel, constraints): - rel_entity = get_entity(rel) if type(rel_entity) == OntologyRelationship: @@ -117,8 +122,9 @@ def _check_cuds_object_cardinality(origin_cuds, dest_oclass, rel, constraints): min, max = _interpret_cardinality_value_from_constraints(constraints) if actual_cardinality < min or actual_cardinality > max: - message = """Found invalid cardinality between {} and {} with relationship {}. - The constraint says it should be between {} and {}, but we found {}. + message = """Found invalid cardinality between {} and {} + with relationship {}. The constraint says it should be + between {} and {}, but we found {}. The uid of the affected cuds_object is: {}""".format( str(origin_cuds.oclass), dest_oclass, @@ -130,6 +136,64 @@ def _check_cuds_object_cardinality(origin_cuds, dest_oclass, rel, constraints): ) raise CardinalityError(message) + _check_attribute_contraints( + origin_cuds, rel_entity, dest_oclass, constraints + ) + + +def _check_attribute_contraints( + origin_cuds, rel_entity, dest_oclass, constraints +): + attribute = origin_cuds.get_attributes().get(rel_entity) + value = constraints.get("value") + if attribute: + if value and attribute != value: + message = """Found invalid attribute value + between {} and {} with relationship {}. + The constraint says it should be valued '{}', + but we found '{}'. The uid of the affected + cuds_object is: {}""".format( + str(origin_cuds.oclass), + dest_oclass, + rel_entity, + value, + attribute, + origin_cuds.uid, + ) + raise ConsistencyError(message) + + if type(attribute) == str: + attribute = len(attribute) + target = "length" + else: + target = "range" + min, max = _interpret_attribute_from_constraints(constraints, target) + if attribute < min or attribute > max: + message = """Found invalid attribute value {} between {} and {} + relationship {}. The constraint says it should be between {} + and {}, but we found {}. The uid of the affected + cuds_object is: {}""".format( + target, + str(origin_cuds.oclass), + dest_oclass, + rel_entity, + min, + max, + attribute, + origin_cuds.uid, + ) + raise CardinalityError(message) + + +def _interpret_attribute_from_constraints(constraints, range_or_len: str): + min = -float("inf") + if constraints is not None: + value = constraints.get(range_or_len) + min, max = _interpret_cardinality_value_from_constraints( + dict(cardinality=value) + ) + return min, max + def _interpret_cardinality_value_from_constraints(constraints): # default is arbitrary @@ -140,11 +204,12 @@ def _interpret_cardinality_value_from_constraints(constraints): if isinstance(cardinality_value, int): min = cardinality_value max = cardinality_value - elif "-" in cardinality_value: - min = int(cardinality_value.split("-")[0]) - max = int(cardinality_value.split("-")[1]) - elif "+" in cardinality_value: - min = int(cardinality_value.split("+")[0]) + elif isinstance(cardinality_value, str): + if "-" in cardinality_value: + min = int(cardinality_value.split("-")[0]) + max = int(cardinality_value.split("-")[1]) + elif "+" in cardinality_value: + min = int(cardinality_value.split("+")[0]) return min, max @@ -181,9 +246,9 @@ def _get_optional_and_mandatory_subtrees(data_model_dict): min, max = _interpret_cardinality_value_from_constraints( constraints ) - if min == 0: + if min == 0 and neighbor not in YML_DATATYPES.keys(): optional_subtrees.add(neighbor) - if min > 0: + if min > 0 and neighbor not in YML_DATATYPES.keys(): mandatory_subtrees.add(neighbor) if optional_subtrees & mandatory_subtrees: diff --git a/tests/test_utils.py b/tests/test_utils.py index 44492af5..6331ea8d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -139,7 +139,12 @@ def test_validate_tree_against_schema(self): "test_validation_schema_city_with_attribute.yml", ) - c = city.City(name="freiburg") + schema_file_with_attribute_value = os.path.join( + os.path.dirname(__file__), + "test_validation_schema_city_with_attribute_value.yml", + ) + + c = city.City(name="Freiburg") # empty city is not valid self.assertRaises( @@ -193,8 +198,26 @@ def test_validate_tree_against_schema(self): schema_file_with_missing_entity, ) + # now we validate the attributes and their cardinality validate_tree_against_schema(c, schema_file_with_attribute) + # additionally we check the length and the value of the attribute + validate_tree_against_schema(c, schema_file_with_attribute_value) + + # and if there are more objects in tree than in the schema + # it can be specified if the test should be done strictly + c.add(wrong_object, rel=city.hasPart) + # first no strict check - additional cuds is tolerated: + validate_tree_against_schema(c, schema_file_with_attribute_value) + # second with strict check - additional cuds is not tolerated: + self.assertRaises( + ConsistencyError, + validate_tree_against_schema, + c, + schema_file_with_attribute_value, + strict_check=True, + ) + def test_branch(self): """Test the branch function.""" x = branch( diff --git a/tests/test_validation_schema_city_with_attribute_value.yml b/tests/test_validation_schema_city_with_attribute_value.yml new file mode 100644 index 00000000..9139863f --- /dev/null +++ b/tests/test_validation_schema_city_with_attribute_value.yml @@ -0,0 +1,40 @@ +version: "1.0.0" + +oclass: city.City + +model: + city.City: + city.name: + STRING: + value: Freiburg + city.hasInhabitant: + city.Citizen: + cardinality: 1-2 + city.hasPart: + city.Neighborhood: + cardinality: 1 + + city.Neighborhood: + city.name: + STRING: + cardinality: 1 + city.hasPart: + city.Street: + cardinality: 1+ + + city.Street: + city.name: + STRING: + length: 1-10 + cardinality: 1 + + city.Citizen: + city.name: + STRING: + value: peter + length: 1+ + cardinality: 1 + city.age: + INT: + range: 0+ + cardinality: 1 From b59ce10b182b97665f2c66d2694c07a28191cf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Dom=C3=ADnguez?= <43052541+kysrpex@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:56:35 +0100 Subject: [PATCH 13/13] Bump package version to 3.9.0 (#838) --- packageinfo.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packageinfo.py b/packageinfo.py index 9dbe3510..671ce813 100644 --- a/packageinfo.py +++ b/packageinfo.py @@ -1,4 +1,4 @@ """Information about the package.""" NAME = "osp-core" -VERSION = "3.8.0" +VERSION = "3.9.0" diff --git a/setup.py b/setup.py index ae23b459..d3d388f9 100644 --- a/setup.py +++ b/setup.py @@ -66,7 +66,7 @@ "PyYaml", "rdflib >= 6.0.0, < 7.0.0; python_version >= '3.7'", "requests", - "websockets < 11", + "websockets >= 9, < 11", "websockets >= 10; python_version >= '3.10'", # ↓ --- Python 3.6 support. --- ↓ # "pyparsing < 3.0.0; python_version < '3.7'",