diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index bee70e523..33f308573 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -80,6 +80,11 @@ jobs: run: | pytest -n 2 --weldx-file-rw-buffer --weldx-file-rw-buffer-disp-header --cov-append ./weldx/tests/asdf_tests + - name: test quality standard + if: matrix.py == '3.8' + run: | + pytest --cov-append ./weldx/tests/asdf_tests/quality_standards_check.py + - name: coverage xml (combination is performed by pytest-cov) if: matrix.py == '3.8' run: coverage xml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 94297c049..9c5a133ca 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -34,6 +34,7 @@ fixes - Fix interactive ``view_tree`` display [:pull:`756`]. - Increase ``mypy`` coverage and update type hints and GH action [:pull:`753`]. +- Fix errors in tutorial about quality standards [:pull:`777`] dependencies ============ diff --git a/tutorials/quality_standards.ipynb b/tutorials/quality_standards.ipynb index 20d2b2674..7fb5cecff 100644 --- a/tutorials/quality_standards.ipynb +++ b/tutorials/quality_standards.ipynb @@ -123,7 +123,7 @@ "\n", "mem_fs.create(\"resources/my_organization/manifests/my_standard-1.0.0.yaml\")\n", "mem_fs.create(\n", - " \"resources/my_organization/schemas/my_measurement_equipment_schema-1.0.0.yaml\"\n", + " \"resources/my_organization/schemas/my_measurement_equipment_schema-0.1.0.yaml\"\n", ")\n", "mem_fs.tree()" ] @@ -187,13 +187,6 @@ "---\n", "$schema: \"http://stsci.edu/schemas/yaml-schema/draft-01\"\n", "id: \"asdf://weldx.bam.de/weldx/schemas/equipment/measurement_equipment-0.1.0\"\n", - "tag: \"asdf://weldx.bam.de/weldx/tags/equipment/measurement_equipment-0.1.0\"\n", - "\n", - "title: |\n", - " A piece of measurement equipment.\n", - "description: |\n", - " This schema describes a piece of measurement equipment that is part of a measurement chain.\n", - " Equipment can be associated with signal sources and data transformations.\n", "\n", "type: object\n", "properties:\n", @@ -247,13 +240,6 @@ "---\n", "$schema: \"http://stsci.edu/schemas/yaml-schema/draft-01\"\n", "id: \"asdf://weldx.bam.de/weldx/schemas/equipment/measurement_equipment-0.1.0\"\n", - "tag: \"asdf://weldx.bam.de/weldx/tags/equipment/measurement_equipment-0.1.0\"\n", - "\n", - "title: |\n", - " A piece of measurement equipment.\n", - "description: |\n", - " This schema describes a piece of measurement equipment that is part of a measurement chain.\n", - " Equipment can be associated with signal sources and data transformations.\n", "\n", "type: object\n", "properties:\n", @@ -350,7 +336,7 @@ "# mappings\n", "tags:\n", "- uri: \"asdf://weldx.bam.de/weldx/schemas/equipment/measurement_equipment-0.1.0\"\n", - " file: \"my_measurement_equipment_schema-1.0.0\"\n", + " file: \"my_measurement_equipment_schema-0.1.0\"\n", "\"\"\"" ] }, @@ -521,7 +507,9 @@ "try:\n", " WeldxFile(tree={\"equipment\": my_equipment}, mode=\"rw\")\n", "except asdf.ValidationError:\n", - " print(\"Ups..., got some lengthy validation error...\")" + " print(\"Ups..., got some lengthy validation error...\")\n", + "else:\n", + " raise Exception(\"Expected exception not raised\")" ] }, { @@ -557,7 +545,9 @@ "try:\n", " WeldxFile(tree={\"equipment\": my_equipment}, mode=\"rw\")\n", "except asdf.ValidationError:\n", - " print(\"Still getting a validation error...\")" + " print(\"Still getting a validation error...\")\n", + "else:\n", + " raise Exception(\"Expected exception not raised\")" ] }, { @@ -649,7 +639,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.11" + "version": "3.10.4" } }, "nbformat": 4, diff --git a/weldx/tests/asdf_tests/quality_standards_check.py b/weldx/tests/asdf_tests/quality_standards_check.py new file mode 100644 index 000000000..7272e7667 --- /dev/null +++ b/weldx/tests/asdf_tests/quality_standards_check.py @@ -0,0 +1,81 @@ +"""Tests if quality standards are working as expected.""" + +import asdf +import fs +import pytest + +from weldx import WeldxFile +from weldx.config import QualityStandard, add_quality_standard, enable_quality_standard +from weldx.measurement import MeasurementEquipment + +manifest_file = """ +id: http://weldx.bam.de/weldx/standards/manifests/test_standard-1.0.0 +extension_uri: http://weldx.bam.de/weldx/standards/test_standard-1.0.0 +asdf_standard_requirement: 1.0.0 + +tags: + - uri: "asdf://weldx.bam.de/weldx/schemas/equipment/measurement_equipment-0.1.0" + file: "test_schema-0.1.0" +""" + +schema_file = """ +%YAML 1.1 +--- +$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" +id: "asdf://weldx.bam.de/weldx/schemas/equipment/measurement_equipment-0.1.0" + +type: object +properties: + name: + type: string + sources: + type: array + items: + tag: "asdf://weldx.bam.de/weldx/tags/measurement/source-0.1.*" + transformations: + type: array + items: + tag: "asdf://weldx.bam.de/weldx/tags/measurement/signal_transformation-0.1.*" + wx_metadata: + type: object + properties: + required_field_for_test: + type: number + required: [required_field_for_test] + + +propertyOrder: [name, sources, transformations] +required: [name, wx_metadata] + +flowStyle: block +... +""" + + +def test_quality_standards(): + # create file structure + base_dir = "resources/some_organization" + manifest_dir = f"{base_dir}/manifests" + schema_dir = f"{base_dir}/schemas" + + vfs = fs.open_fs("mem://") + vfs.makedirs(manifest_dir) + vfs.makedirs(schema_dir) + with vfs.open(f"{manifest_dir}/test_standard-1.0.0.yaml", "w") as file: + file.write(manifest_file) + with vfs.open(f"{schema_dir}/test_schema-0.1.0.yaml", "w") as file: + file.write(schema_file) + # print(vfs.tree()) # skipcq: PY-W0069 + + # create and enable quality standard + qs = QualityStandard(vfs.opendir(base_dir)) + add_quality_standard(qs) + enable_quality_standard("test_standard") + + # run tests + eq = MeasurementEquipment("some_equipment") + with pytest.raises(asdf.ValidationError): + WeldxFile(tree={"equipment": eq}, mode="rw") + + eq.wx_metadata = {"required_field_for_test": 1234} + WeldxFile(tree={"equipment": eq}, mode="rw")