Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for quality standards and update the quality standard tutorial #777

Merged
merged 14 commits into from
Jul 19, 2022
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/test_quality_standards.py

- name: coverage xml (combination is performed by pytest-cov)
if: matrix.py == '3.8'
run: coverage xml
Expand Down
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ match = (?!__)(?!_version)(?!conftest).*\.py
match_dir = ^(?!(tests|tags|asdf)).*

[tool:pytest]
addopts = --tb=short --color=yes -rsw --cov=weldx --cov-report=term-missing:skip-covered --doctest-modules
addopts =
--tb=short --color=yes -rsw
--cov=weldx --cov-report=term-missing:skip-covered
--doctest-modules
--ignore=./weldx/tests/asdf_tests/test_quality_standards.py
vhirtham marked this conversation as resolved.
Show resolved Hide resolved
#addopts = --tb=short --color=yes -rs -p no:cov
testpaths =
weldx
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/test_quality_standards.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")