Skip to content

Commit

Permalink
Add a test for quality standards and update the quality standard tuto…
Browse files Browse the repository at this point in the history
…rial (#777)
  • Loading branch information
vhirtham authored Jul 19, 2022
1 parent 65753d7 commit 0a2d2d6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
============
Expand Down
28 changes: 9 additions & 19 deletions tutorials/quality_standards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
"\"\"\""
]
},
Expand Down Expand Up @@ -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\")"
]
},
{
Expand Down Expand Up @@ -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\")"
]
},
{
Expand Down Expand Up @@ -649,7 +639,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
81 changes: 81 additions & 0 deletions weldx/tests/asdf_tests/quality_standards_check.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 0a2d2d6

Please sign in to comment.