From e0b364ddd1f0e6877c7640ad0f5a42ce7b412912 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 28 Nov 2023 11:35:58 +0100 Subject: [PATCH 01/10] chore!: add pytest, bump min Python version to 3.7 --- flake.nix | 52 ++++++++++------- poetry.lock | 154 +++++++++++++++++++++++++++++++++++++++++++++++-- pyproject.toml | 5 +- 3 files changed, 184 insertions(+), 27 deletions(-) diff --git a/flake.nix b/flake.nix index 3733e7e..5b099c3 100644 --- a/flake.nix +++ b/flake.nix @@ -26,40 +26,48 @@ ]; }; in { - packages.default = pkgs.poetry2nix.mkPoetryApplication { - projectDir = ./.; - + packages.default = let # Numpy 1.19.5 doesn't compile with Python3.10+ # # This was fixed in later versions of Numpy, but Numpy >=1.20 doesn't # support Python 3.6, which we need to support older systems. python = pkgs.python39; + in + pkgs.poetry2nix.mkPoetryApplication { + projectDir = ./.; + + inherit python; - nativeBuildInputs = with pkgs; [makeWrapper]; - propagatedBuildInputs = with pkgs.python39Packages; [tkinter]; + nativeBuildInputs = with pkgs; [makeWrapper]; + propagatedBuildInputs = with python.pkgs; [tkinter]; - overrides = pkgs.poetry2nix.overrides.withDefaults (_final: prev: { - reportlab = prev.reportlab.overridePythonAttrs (_old: { - buildInputs = with pkgs; [(freetype.overrideAttrs (_: {dontDisableStatic = true;}))]; + overrides = pkgs.poetry2nix.overrides.withDefaults (_final: prev: { + reportlab = prev.reportlab.overridePythonAttrs (_old: { + buildInputs = with pkgs; [(freetype.overrideAttrs (_: {dontDisableStatic = true;}))]; + }); }); - }); - postInstall = let - inherit (epnix.packages.x86_64-linux) epics-base; - in '' - wrapProgram $out/bin/wetest \ - --set PYEPICS_LIBCA "${epics-base}/lib/linux-x86_64/libca.so" - ''; + postInstall = let + inherit (epnix.packages.x86_64-linux) epics-base; + in '' + wrapProgram $out/bin/wetest \ + --set PYEPICS_LIBCA "${epics-base}/lib/linux-x86_64/libca.so" + ''; - doCheck = true; + doCheck = true; + checkPhase = '' + runHook preCheck + pytest + runHook postCheck + ''; - meta = { - description = "Tests automation utility for EPICS"; - mainProgram = "wetest"; - license = epnix.lib.licenses.epics; - maintainers = with epnix.lib.maintainers; [minijackson]; + meta = { + description = "Tests automation utility for EPICS"; + mainProgram = "wetest"; + license = epnix.lib.licenses.epics; + maintainers = with epnix.lib.maintainers; [minijackson]; + }; }; - }; devShells.default = pkgs.mkShell { nativeBuildInputs = with pkgs; [poetry python39Full]; diff --git a/poetry.lock b/poetry.lock index 04e055a..f447d76 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. [[package]] name = "colorama" @@ -41,6 +41,54 @@ files = [ {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, ] +[[package]] +name = "exceptiongroup" +version = "1.2.0" +description = "Backport of PEP 654 (exception groups)" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, + {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "importlib-metadata" +version = "6.7.0" +description = "Read metadata from Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "importlib_metadata-6.7.0-py3-none-any.whl", hash = "sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5"}, + {file = "importlib_metadata-6.7.0.tar.gz", hash = "sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4"}, +] + +[package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} +zipp = ">=0.5" + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +perf = ["ipython"] +testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + [[package]] name = "numpy" version = "1.19.5" @@ -85,6 +133,18 @@ files = [ {file = "numpy-1.19.5.zip", hash = "sha256:a76f502430dd98d7546e1ea2250a7360c065a5fdea52b2dffe8ae7180909b6f4"}, ] +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + [[package]] name = "pillow" version = "8.4.0" @@ -136,6 +196,25 @@ files = [ {file = "Pillow-8.4.0.tar.gz", hash = "sha256:b8e2f83c56e141920c39464b852de3719dfbfb6e3c99a2d8da0edf4fb33176ed"}, ] +[[package]] +name = "pluggy" +version = "1.2.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, + {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, +] + +[package.dependencies] +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pyepics" version = "3.5.1" @@ -167,6 +246,30 @@ docopt = ">=0.6.2" python-dateutil = ">=2.8.0" "ruamel.yaml" = ">=0.16.0" +[[package]] +name = "pytest" +version = "7.4.3" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.3-py3-none-any.whl", hash = "sha256:0d009c083ea859a71b76adf7c1d502e4bc170b80a8ef002da5806527b9591fac"}, + {file = "pytest-7.4.3.tar.gz", hash = "sha256:d989d136982de4e3b29dabcc838ad581c64e8ed52c11fbe86ddebd9da0818cd5"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + [[package]] name = "python-dateutil" version = "2.8.2" @@ -318,8 +421,11 @@ files = [ {file = "ruamel.yaml.clib-0.2.7-cp310-cp310-win32.whl", hash = "sha256:763d65baa3b952479c4e972669f679fe490eee058d5aa85da483ebae2009d231"}, {file = "ruamel.yaml.clib-0.2.7-cp310-cp310-win_amd64.whl", hash = "sha256:d000f258cf42fec2b1bbf2863c61d7b8918d31ffee905da62dede869254d3b8a"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:045e0626baf1c52e5527bd5db361bc83180faaba2ff586e763d3d5982a876a9e"}, - {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_12_6_arm64.whl", hash = "sha256:721bc4ba4525f53f6a611ec0967bdcee61b31df5a56801281027a3a6d1c2daf5"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:1a6391a7cabb7641c32517539ca42cf84b87b667bad38b78d4d42dd23e957c81"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:9c7617df90c1365638916b98cdd9be833d31d337dbcd722485597b43c4a215bf"}, {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:41d0f1fa4c6830176eef5b276af04c89320ea616655d01327d5ce65e50575c94"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-win32.whl", hash = "sha256:f6d3d39611ac2e4f62c3128a9eed45f19a6608670c5a2f4f07f24e8de3441d38"}, + {file = "ruamel.yaml.clib-0.2.7-cp311-cp311-win_amd64.whl", hash = "sha256:da538167284de58a52109a9b89b8f6a53ff8437dd6dc26d33b57bf6699153122"}, {file = "ruamel.yaml.clib-0.2.7-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4b3a93bb9bc662fc1f99c5c3ea8e623d8b23ad22f861eb6fce9377ac07ad6072"}, {file = "ruamel.yaml.clib-0.2.7-cp36-cp36m-macosx_12_0_arm64.whl", hash = "sha256:a234a20ae07e8469da311e182e70ef6b199d0fbeb6c6cc2901204dd87fb867e8"}, {file = "ruamel.yaml.clib-0.2.7-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:15910ef4f3e537eea7fe45f8a5d19997479940d9196f357152a09031c5be59f3"}, @@ -375,7 +481,47 @@ files = [ {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + +[[package]] +name = "typing-extensions" +version = "4.7.1" +description = "Backported and Experimental Type Hints for Python 3.7+" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "typing_extensions-4.7.1-py3-none-any.whl", hash = "sha256:440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36"}, + {file = "typing_extensions-4.7.1.tar.gz", hash = "sha256:b75ddc264f0ba5615db7ba217daeb99701ad295353c45f9e95963337ceeeffb2"}, +] + +[[package]] +name = "zipp" +version = "3.15.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "zipp-3.15.0-py3-none-any.whl", hash = "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556"}, + {file = "zipp-3.15.0.tar.gz", hash = "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] + [metadata] lock-version = "2.0" -python-versions = ">=3.6, <4" -content-hash = "770d3ba41298c93d0541cfe9b64d2818fcd0035f310bee19fe82ab98f810c4e7" +python-versions = ">=3.7, <4" +content-hash = "005fe59d13224f500106af5617706292090cc4e23a1fea7be3c34f2f515a1309" diff --git a/pyproject.toml b/pyproject.toml index 0962f60..4f4109c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.poetry.dependencies] -python = ">=3.6, <4" +python = ">=3.7, <4" PyYAML = "^6.0" colorlog = "^6.6.0" numpy = "^1.19.5, <1.20.0" @@ -38,6 +38,9 @@ pyepics = "^3.5.1" pykwalify = "^1.8.0" reportlab = "^3.6.8" +[tool.poetry.group.dev.dependencies] +pytest = "^7.4.3" + [tool.ruff] select = ["ALL"] ignore = [ From 6b2a3855ec32463c15133ddb2a526c1b049f0c76 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 15:00:14 +0100 Subject: [PATCH 02/10] chore(tests): move tests to own directory --- {wetest/tests => tests}/__init__.py | 0 {wetest/tests => tests}/acceptance-demo.yaml | 0 {wetest/tests => tests}/bad.yml | 0 {wetest/tests => tests}/gui-testing.yaml | 0 .../tests => tests}/include-testing-0.yaml | 0 .../tests => tests}/include-testing-1.yaml | 0 .../tests => tests}/include-testing-2.yaml | 0 .../tests => tests}/include-testing-3.yaml | 0 .../include-testing-empty.yaml | 0 .../include-testing-file_not_found.yaml | 0 .../include-testing-lacks_config.yaml | 0 .../include-testing-lacks_tests.yaml | 0 {wetest/tests => tests}/macro-testing.yaml | 0 {wetest/tests => tests}/mks946-testing.yaml | 0 {wetest/tests => tests}/mks946.yaml | 0 .../tests => tests}/scenario_example01.yaml | 0 .../tests => tests}/scenario_example02.yaml | 0 .../tests => tests}/scenario_example03.yaml | 0 .../tests => tests}/scenario_example04.yaml | 0 .../tests => tests}/scenario_example05.yaml | 0 {wetest/tests => tests}/scenario_range.yaml | 0 .../scenario_testing_naming.yaml | 0 .../tests => tests}/source-at-0-reference.yml | 0 {wetest/tests => tests}/suite_example01.yaml | 0 {wetest/tests => tests}/suite_example02.yaml | 0 .../tests => tests}/suite_with_macros.yaml | 0 .../tests => tests}/test_report_generator.py | 0 {wetest/tests => tests}/test_schema.py | 0 .../tests => tests}/test_testing_generator.py | 0 .../tests => tests}/test_testing_reader.py | 0 {wetest/tests => tests}/type-testing.yaml | 0 wetest/tests/results_samples/no_error.xml | 27 ------------ wetest/tests/results_samples/with_errors.xml | 41 ------------------- 33 files changed, 68 deletions(-) rename {wetest/tests => tests}/__init__.py (100%) rename {wetest/tests => tests}/acceptance-demo.yaml (100%) rename {wetest/tests => tests}/bad.yml (100%) rename {wetest/tests => tests}/gui-testing.yaml (100%) rename {wetest/tests => tests}/include-testing-0.yaml (100%) rename {wetest/tests => tests}/include-testing-1.yaml (100%) rename {wetest/tests => tests}/include-testing-2.yaml (100%) rename {wetest/tests => tests}/include-testing-3.yaml (100%) rename {wetest/tests => tests}/include-testing-empty.yaml (100%) rename {wetest/tests => tests}/include-testing-file_not_found.yaml (100%) rename {wetest/tests => tests}/include-testing-lacks_config.yaml (100%) rename {wetest/tests => tests}/include-testing-lacks_tests.yaml (100%) rename {wetest/tests => tests}/macro-testing.yaml (100%) rename {wetest/tests => tests}/mks946-testing.yaml (100%) rename {wetest/tests => tests}/mks946.yaml (100%) rename {wetest/tests => tests}/scenario_example01.yaml (100%) rename {wetest/tests => tests}/scenario_example02.yaml (100%) rename {wetest/tests => tests}/scenario_example03.yaml (100%) rename {wetest/tests => tests}/scenario_example04.yaml (100%) rename {wetest/tests => tests}/scenario_example05.yaml (100%) rename {wetest/tests => tests}/scenario_range.yaml (100%) rename {wetest/tests => tests}/scenario_testing_naming.yaml (100%) rename {wetest/tests => tests}/source-at-0-reference.yml (100%) rename {wetest/tests => tests}/suite_example01.yaml (100%) rename {wetest/tests => tests}/suite_example02.yaml (100%) rename {wetest/tests => tests}/suite_with_macros.yaml (100%) rename {wetest/tests => tests}/test_report_generator.py (100%) rename {wetest/tests => tests}/test_schema.py (100%) rename {wetest/tests => tests}/test_testing_generator.py (100%) rename {wetest/tests => tests}/test_testing_reader.py (100%) rename {wetest/tests => tests}/type-testing.yaml (100%) delete mode 100644 wetest/tests/results_samples/no_error.xml delete mode 100644 wetest/tests/results_samples/with_errors.xml diff --git a/wetest/tests/__init__.py b/tests/__init__.py similarity index 100% rename from wetest/tests/__init__.py rename to tests/__init__.py diff --git a/wetest/tests/acceptance-demo.yaml b/tests/acceptance-demo.yaml similarity index 100% rename from wetest/tests/acceptance-demo.yaml rename to tests/acceptance-demo.yaml diff --git a/wetest/tests/bad.yml b/tests/bad.yml similarity index 100% rename from wetest/tests/bad.yml rename to tests/bad.yml diff --git a/wetest/tests/gui-testing.yaml b/tests/gui-testing.yaml similarity index 100% rename from wetest/tests/gui-testing.yaml rename to tests/gui-testing.yaml diff --git a/wetest/tests/include-testing-0.yaml b/tests/include-testing-0.yaml similarity index 100% rename from wetest/tests/include-testing-0.yaml rename to tests/include-testing-0.yaml diff --git a/wetest/tests/include-testing-1.yaml b/tests/include-testing-1.yaml similarity index 100% rename from wetest/tests/include-testing-1.yaml rename to tests/include-testing-1.yaml diff --git a/wetest/tests/include-testing-2.yaml b/tests/include-testing-2.yaml similarity index 100% rename from wetest/tests/include-testing-2.yaml rename to tests/include-testing-2.yaml diff --git a/wetest/tests/include-testing-3.yaml b/tests/include-testing-3.yaml similarity index 100% rename from wetest/tests/include-testing-3.yaml rename to tests/include-testing-3.yaml diff --git a/wetest/tests/include-testing-empty.yaml b/tests/include-testing-empty.yaml similarity index 100% rename from wetest/tests/include-testing-empty.yaml rename to tests/include-testing-empty.yaml diff --git a/wetest/tests/include-testing-file_not_found.yaml b/tests/include-testing-file_not_found.yaml similarity index 100% rename from wetest/tests/include-testing-file_not_found.yaml rename to tests/include-testing-file_not_found.yaml diff --git a/wetest/tests/include-testing-lacks_config.yaml b/tests/include-testing-lacks_config.yaml similarity index 100% rename from wetest/tests/include-testing-lacks_config.yaml rename to tests/include-testing-lacks_config.yaml diff --git a/wetest/tests/include-testing-lacks_tests.yaml b/tests/include-testing-lacks_tests.yaml similarity index 100% rename from wetest/tests/include-testing-lacks_tests.yaml rename to tests/include-testing-lacks_tests.yaml diff --git a/wetest/tests/macro-testing.yaml b/tests/macro-testing.yaml similarity index 100% rename from wetest/tests/macro-testing.yaml rename to tests/macro-testing.yaml diff --git a/wetest/tests/mks946-testing.yaml b/tests/mks946-testing.yaml similarity index 100% rename from wetest/tests/mks946-testing.yaml rename to tests/mks946-testing.yaml diff --git a/wetest/tests/mks946.yaml b/tests/mks946.yaml similarity index 100% rename from wetest/tests/mks946.yaml rename to tests/mks946.yaml diff --git a/wetest/tests/scenario_example01.yaml b/tests/scenario_example01.yaml similarity index 100% rename from wetest/tests/scenario_example01.yaml rename to tests/scenario_example01.yaml diff --git a/wetest/tests/scenario_example02.yaml b/tests/scenario_example02.yaml similarity index 100% rename from wetest/tests/scenario_example02.yaml rename to tests/scenario_example02.yaml diff --git a/wetest/tests/scenario_example03.yaml b/tests/scenario_example03.yaml similarity index 100% rename from wetest/tests/scenario_example03.yaml rename to tests/scenario_example03.yaml diff --git a/wetest/tests/scenario_example04.yaml b/tests/scenario_example04.yaml similarity index 100% rename from wetest/tests/scenario_example04.yaml rename to tests/scenario_example04.yaml diff --git a/wetest/tests/scenario_example05.yaml b/tests/scenario_example05.yaml similarity index 100% rename from wetest/tests/scenario_example05.yaml rename to tests/scenario_example05.yaml diff --git a/wetest/tests/scenario_range.yaml b/tests/scenario_range.yaml similarity index 100% rename from wetest/tests/scenario_range.yaml rename to tests/scenario_range.yaml diff --git a/wetest/tests/scenario_testing_naming.yaml b/tests/scenario_testing_naming.yaml similarity index 100% rename from wetest/tests/scenario_testing_naming.yaml rename to tests/scenario_testing_naming.yaml diff --git a/wetest/tests/source-at-0-reference.yml b/tests/source-at-0-reference.yml similarity index 100% rename from wetest/tests/source-at-0-reference.yml rename to tests/source-at-0-reference.yml diff --git a/wetest/tests/suite_example01.yaml b/tests/suite_example01.yaml similarity index 100% rename from wetest/tests/suite_example01.yaml rename to tests/suite_example01.yaml diff --git a/wetest/tests/suite_example02.yaml b/tests/suite_example02.yaml similarity index 100% rename from wetest/tests/suite_example02.yaml rename to tests/suite_example02.yaml diff --git a/wetest/tests/suite_with_macros.yaml b/tests/suite_with_macros.yaml similarity index 100% rename from wetest/tests/suite_with_macros.yaml rename to tests/suite_with_macros.yaml diff --git a/wetest/tests/test_report_generator.py b/tests/test_report_generator.py similarity index 100% rename from wetest/tests/test_report_generator.py rename to tests/test_report_generator.py diff --git a/wetest/tests/test_schema.py b/tests/test_schema.py similarity index 100% rename from wetest/tests/test_schema.py rename to tests/test_schema.py diff --git a/wetest/tests/test_testing_generator.py b/tests/test_testing_generator.py similarity index 100% rename from wetest/tests/test_testing_generator.py rename to tests/test_testing_generator.py diff --git a/wetest/tests/test_testing_reader.py b/tests/test_testing_reader.py similarity index 100% rename from wetest/tests/test_testing_reader.py rename to tests/test_testing_reader.py diff --git a/wetest/tests/type-testing.yaml b/tests/type-testing.yaml similarity index 100% rename from wetest/tests/type-testing.yaml rename to tests/type-testing.yaml diff --git a/wetest/tests/results_samples/no_error.xml b/wetest/tests/results_samples/no_error.xml deleted file mode 100644 index df79607..0000000 --- a/wetest/tests/results_samples/no_error.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wetest/tests/results_samples/with_errors.xml b/wetest/tests/results_samples/with_errors.xml deleted file mode 100644 index 8ade908..0000000 --- a/wetest/tests/results_samples/with_errors.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 8ad8fb100a06927c95a1acf9eb187f3c5bbb1aa5 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 15:08:49 +0100 Subject: [PATCH 03/10] refactor(reader): make validate_file return boolean useful for testing --- wetest/testing/reader.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wetest/testing/reader.py b/wetest/testing/reader.py index 2d112f4..e89a347 100644 --- a/wetest/testing/reader.py +++ b/wetest/testing/reader.py @@ -854,7 +854,7 @@ def _substitute_macros(self, deserialized): return deserialized - def validate_file(self, config=None): + def validate_file(self: "ScenarioReader", config: Core) -> bool: """Run the schema, non-compulsory and compylsory validation. if compulsory validation fails, terminate the program with error code 1. @@ -863,14 +863,13 @@ def validate_file(self, config=None): :returns: wrether or not all the validation succeeded. """ - if config is not None: - fv_logger.info("Validating input file against schema.") - try: - config.validate() - schema_valid = True - except errors.SchemaError as err: - fv_logger.log(LVL_FORMAT_VAL, "%s", err.msg) - schema_valid = False + fv_logger.info("Validating input file against schema.") + try: + config.validate() + schema_valid = True + except errors.SchemaError as err: + fv_logger.log(LVL_FORMAT_VAL, "%s", err.msg) + schema_valid = False ncmp_valid = self.noncompulsory_validation() if len(ncmp_valid) != 0: @@ -887,4 +886,4 @@ def validate_file(self, config=None): else: fv_logger.info("Validated mandatory rules.") - return schema_valid and ncmp_valid and mand_valid + return schema_valid and ncmp_valid == [] and mand_valid == [] From 1c81a70bc665074ea837df0ba0aa407f6069fbaa Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 15:10:30 +0100 Subject: [PATCH 04/10] refactor(reader): rename _version_is_supported -> supports_version and make it a static method. Useful for testing --- wetest/testing/reader.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/wetest/testing/reader.py b/wetest/testing/reader.py index e89a347..9b21fb1 100644 --- a/wetest/testing/reader.py +++ b/wetest/testing/reader.py @@ -402,7 +402,9 @@ def __init__( self.bugfix = self.deserialized["version"]["bugfix"] self.version = f"{self.major!s}.{self.minor!s}.{self.bugfix!s}" - self.version_is_supported = self._version_is_supported() + self.version_is_supported = ScenarioReader.supports_version( + self.major, self.minor, self.bugfix + ) # Check YAML file schema and other validation tempo_file_path = "/tmp/no_macros.yml" @@ -756,23 +758,24 @@ def noncompulsory_validation(self): return errors - def _version_is_supported(self, major=None, minor=None, bugfix=None): + @staticmethod + def supports_version(major: str, minor: str, bugfix: str) -> bool: """Check if configuration file format version is supported. - :param major: optionally force the major digit parameter (should be - useful for testing only) - :param minor: optionally force the minor digit parameter (should be - useful for testing only) - :param bugfix: optionally force the bugfix digit parameter (should be - useful for testing only) + :param major: major version + :param minor: minor version + :param bugfix: patch version - :returns: True if version is supported, otherwise prompt the user for continue or abort. + :returns: True if version is supported, + otherwise prompt the user for continue or abort. """ # get file version - major = int(major or self.major) - minor = int(minor or self.minor) - bugfix = int(bugfix or self.bugfix) + major = int(major) + minor = int(minor) + bugfix = int(bugfix) + + version = f"{major}.{minor}.{bugfix}" logger.info("Configuration file format version: %i.%i.%i", major, minor, bugfix) @@ -787,14 +790,14 @@ def _version_is_supported(self, major=None, minor=None, bugfix=None): compatible_version = False logger.error( "File version (%s) too recent for installed WeTest (%s).", - self.version, + version, f"{MAJOR}.{MINOR}.{BUGFIX}", ) elif minor < MINOR: compatible_version = False logger.warning( "File version (%s) for older version than the installed WeTest (%s).", - self.version, + version, f"{MAJOR}.{MINOR}.{BUGFIX}", ) @@ -806,7 +809,7 @@ def _version_is_supported(self, major=None, minor=None, bugfix=None): if not try_continue: logger.error( "File format version is: %s, but wetest version is: %s.%s.%s", - self.version, + version, MAJOR, MINOR, BUGFIX, From 0da6de0529e6304d23f826f34d5b6ad07ab6afda Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 15:15:28 +0100 Subject: [PATCH 05/10] chore(reader): don't ask compatibility question compatibility should be guaranteed by semver. Useful for testing --- wetest/testing/reader.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/wetest/testing/reader.py b/wetest/testing/reader.py index 9b21fb1..6ee981d 100644 --- a/wetest/testing/reader.py +++ b/wetest/testing/reader.py @@ -20,7 +20,6 @@ import os import re import sys -import time import pkg_resources import yaml @@ -134,39 +133,6 @@ def display_changelog(file_version, wetest_version) -> None: ) -def query_yes_no(question, default=None): - """Ask a yes/no question via raw_input() and return their answer. - - Args: - ---- - question (str): is a string that is presented to the user. - default (str): is the presumed answer if the user just hits . - It must be "yes" (the default), "no" or None (meaning - an answer is required of the user). - - The "answer" return value is True for "yes" or False for "no". - """ - valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} - if default is None: - prompt = " [y/n] " - elif default == "yes": - prompt = " [Y/n] " - elif default == "no": - prompt = " [y/N] " - else: - raise ValueError("invalid default answer: '%s'" % default) - - while True: - print(question + prompt) - choice = input().lower() - if default is not None and choice == "": - return valid[default] - if choice in valid: - return valid[choice] - - print("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") - - class MacrosManager: """A class to keep track of known, used and unknown variable. @@ -803,8 +769,6 @@ def supports_version(major: str, minor: str, bugfix: str) -> bool: if not compatible_version and try_continue: display_changelog((major, minor, bugfix), (MAJOR, MINOR, BUGFIX)) - time.sleep(0.2) - try_continue = query_yes_no("Try running tests nonetheless ?", "yes") if not try_continue: logger.error( From 37760aadebba567e09bea870b143df77dd70bcc7 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 15:54:30 +0100 Subject: [PATCH 06/10] chore(reader): link to repository instead of print changelog it should be better managed there --- wetest/command_line.py | 9 +++---- wetest/testing/reader.py | 58 +++++++--------------------------------- 2 files changed, 12 insertions(+), 55 deletions(-) diff --git a/wetest/command_line.py b/wetest/command_line.py index 64dd3a0..1d38ba1 100755 --- a/wetest/command_line.py +++ b/wetest/command_line.py @@ -69,7 +69,6 @@ FileNotFound, MacrosManager, ScenarioReader, - display_changelog, ) DESCRIPTION = """WeTest is a testing facility for EPICS modules. @@ -247,9 +246,9 @@ def main(): parser.add_argument( "-V", "--version", - action="count", - default=0, - help="Show WeTest version, also shows major changes is doubling the option", + action="store_true", + default=False, + help="Show WeTest version", ) # tests relative arguments @@ -366,8 +365,6 @@ def main(): if args.version: major, minor, bugfix = (int(x) for x in version.split(".")) logger.warning("Installed WeTest is of version %d.%d.%d", major, minor, bugfix) - if args.version > 1: - display_changelog((major, 0, 0), (major, minor, bugfix)) sys.exit(0) with_gui = not args.no_gui diff --git a/wetest/testing/reader.py b/wetest/testing/reader.py index 6ee981d..c3376c0 100644 --- a/wetest/testing/reader.py +++ b/wetest/testing/reader.py @@ -16,12 +16,12 @@ # TODO(gohierf): margin should only be used with numbers import contextlib +import importlib.metadata import logging import os import re import sys -import pkg_resources import yaml from pkg_resources import resource_filename from pykwalify import errors @@ -54,18 +54,13 @@ fv_logger.addHandler(stream_handler) fv_logger.addHandler(FILE_HANDLER) +WETEST_METADATA = importlib.metadata.metadata("WeTest") + # Maximum file version supported -VERSION = pkg_resources.require("WeTest")[0].version +VERSION = importlib.metadata.version("WeTest") MAJOR, MINOR, BUGFIX = (int(x) for x in VERSION.split(".")) -CHANGELOG_WARN = { - 1: { - 1: """ - Range now tests the `stop` value, - use `include_stop: False` to deactivate""", - 2: """ - Now only macros from include line are provided to included file, - use `--propagate` CLI option to provide all macros already defined instead""", - }, -} +REPOSITORY = WETEST_METADATA["Home-page"] # Constants used elsewhere ABORT = "abort" @@ -96,43 +91,6 @@ class MacroError(WeTestError): """Something went wrong when parsing the macros.""" -def display_changelog(file_version, wetest_version) -> None: - """Display the changelog warnings, only between the two versions.""" - if file_version > wetest_version: - logger.warning("Some feature are not yet implemented in WeTest.") - min_version = wetest_version - max_version = file_version - return - if file_version < wetest_version: - if file_version[0:2] == wetest_version[0:2]: # only bugfix change - logger.warning("Some retrocompatible changes have been made to WeTest.") - else: - logger.warning( - "Some NON-retrocompatible changes have been made to WeTest since %s", - ".".join([str(x) for x in file_version]), - ) - min_version = file_version - max_version = wetest_version - else: - logger.warning("Same version.") - return - - for major in range(min_version[0], max_version[0] + 1): # do stop value too - if major in CHANGELOG_WARN: - for minor in sorted(CHANGELOG_WARN[major]): - if (major, minor) <= min_version[:2]: - continue # too early - if (major, minor) > max_version[:2]: - break # too new - - logger.warning( - "%d.%d.x:\n%s", - major, - minor, - CHANGELOG_WARN[major][minor], - ) - - class MacrosManager: """A class to keep track of known, used and unknown variable. @@ -767,8 +725,10 @@ def supports_version(major: str, minor: str, bugfix: str) -> bool: f"{MAJOR}.{MINOR}.{BUGFIX}", ) - if not compatible_version and try_continue: - display_changelog((major, minor, bugfix), (MAJOR, MINOR, BUGFIX)) + if not compatible_version: + logger.warning( + "Look at the WeTest repository for the CHANGELOG:\n%s", REPOSITORY + ) if not try_continue: logger.error( From f5a6bdc9eae0f7ac19ddef5d007850701bdb4082 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 16:00:48 +0100 Subject: [PATCH 07/10] refactor(command-line): better fetch of WeTest version --- wetest/command_line.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wetest/command_line.py b/wetest/command_line.py index 1d38ba1..42ac502 100755 --- a/wetest/command_line.py +++ b/wetest/command_line.py @@ -13,6 +13,7 @@ import argparse import contextlib +import importlib.metadata import logging import multiprocessing import os @@ -26,7 +27,6 @@ from pathlib import Path import epics -import pkg_resources from wetest.common.constants import ( ABORT_FROM_GUI, @@ -361,10 +361,9 @@ def main(): logger.info("Processing arguments...") - version = pkg_resources.require("WeTest")[0].version if args.version: - major, minor, bugfix = (int(x) for x in version.split(".")) - logger.warning("Installed WeTest is of version %d.%d.%d", major, minor, bugfix) + version = importlib.metadata.version("WeTest") + logger.warning("WeTest %s", version) sys.exit(0) with_gui = not args.no_gui From 0f04b06f0663734a31cf422ea972aa500a81ae33 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 16:27:42 +0100 Subject: [PATCH 08/10] refactor(reader): use semver for version comparison --- poetry.lock | 38 ++++++++------------- pyproject.toml | 1 + wetest/testing/reader.py | 72 ++++++++++++++-------------------------- 3 files changed, 39 insertions(+), 72 deletions(-) diff --git a/poetry.lock b/poetry.lock index f447d76..80242b6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "colorama" version = "0.4.5" description = "Cross-platform colored terminal text." -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -16,7 +15,6 @@ files = [ name = "colorlog" version = "6.7.0" description = "Add colours to the output of Python's logging module." -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -34,7 +32,6 @@ development = ["black", "flake8", "mypy", "pytest", "types-colorama"] name = "docopt" version = "0.6.2" description = "Pythonic argument parser, that will make you smile" -category = "main" optional = false python-versions = "*" files = [ @@ -45,7 +42,6 @@ files = [ name = "exceptiongroup" version = "1.2.0" description = "Backport of PEP 654 (exception groups)" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -60,7 +56,6 @@ test = ["pytest (>=6)"] name = "importlib-metadata" version = "6.7.0" description = "Read metadata from Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -81,7 +76,6 @@ testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -93,7 +87,6 @@ files = [ name = "numpy" version = "1.19.5" description = "NumPy is the fundamental package for array computing with Python." -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -137,7 +130,6 @@ files = [ name = "packaging" version = "23.2" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -149,7 +141,6 @@ files = [ name = "pillow" version = "8.4.0" description = "Python Imaging Library (Fork)" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -200,7 +191,6 @@ files = [ name = "pluggy" version = "1.2.0" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -219,7 +209,6 @@ testing = ["pytest", "pytest-benchmark"] name = "pyepics" version = "3.5.1" description = "Epics Channel Access for Python" -category = "main" optional = false python-versions = "*" files = [ @@ -233,7 +222,6 @@ setuptools = "*" name = "pykwalify" version = "1.8.0" description = "Python lib/cli for JSON/YAML schema validation" -category = "main" optional = false python-versions = "*" files = [ @@ -250,7 +238,6 @@ python-dateutil = ">=2.8.0" name = "pytest" version = "7.4.3" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -274,7 +261,6 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "python-dateutil" version = "2.8.2" description = "Extensions to the standard Python datetime module" -category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" files = [ @@ -289,7 +275,6 @@ six = ">=1.5" name = "pyyaml" version = "6.0" description = "YAML parser and emitter for Python" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -339,7 +324,6 @@ files = [ name = "reportlab" version = "3.6.8" description = "The Reportlab Toolkit" -category = "main" optional = false python-versions = ">=3.6, <4" files = [ @@ -391,7 +375,6 @@ rlpycairo = ["rlPyCairo (>=0.0.5)"] name = "ruamel-yaml" version = "0.17.21" description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" -category = "main" optional = false python-versions = ">=3" files = [ @@ -410,7 +393,6 @@ jinja2 = ["ruamel.yaml.jinja2 (>=0.2)"] name = "ruamel-yaml-clib" version = "0.2.7" description = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -453,11 +435,21 @@ files = [ {file = "ruamel.yaml.clib-0.2.7.tar.gz", hash = "sha256:1f08fd5a2bea9c4180db71678e850b995d2a5f4537be0e94557668cf0f5f9497"}, ] +[[package]] +name = "semver" +version = "3.0.2" +description = "Python helper for Semantic Versioning (https://semver.org)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "semver-3.0.2-py3-none-any.whl", hash = "sha256:b1ea4686fe70b981f85359eda33199d60c53964284e0cfb4977d243e37cf4bf4"}, + {file = "semver-3.0.2.tar.gz", hash = "sha256:6253adb39c70f6e51afed2fa7152bcd414c411286088fb4b9effb133885ab4cc"}, +] + [[package]] name = "setuptools" version = "59.6.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -473,7 +465,6 @@ testing = ["flake8-2020", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mock" name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" -category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -485,7 +476,6 @@ files = [ name = "tomli" version = "2.0.1" description = "A lil' TOML parser" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -497,7 +487,6 @@ files = [ name = "typing-extensions" version = "4.7.1" description = "Backported and Experimental Type Hints for Python 3.7+" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -509,7 +498,6 @@ files = [ name = "zipp" version = "3.15.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -524,4 +512,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.7, <4" -content-hash = "005fe59d13224f500106af5617706292090cc4e23a1fea7be3c34f2f515a1309" +content-hash = "e709d5f60bea46db48e88ca86cb292312581ee820e3090ad0e01fad7333c9626" diff --git a/pyproject.toml b/pyproject.toml index 4f4109c..9056894 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ numpy = "^1.19.5, <1.20.0" pyepics = "^3.5.1" pykwalify = "^1.8.0" reportlab = "^3.6.8" +semver = "^3.0.2" [tool.poetry.group.dev.dependencies] pytest = "^7.4.3" diff --git a/wetest/testing/reader.py b/wetest/testing/reader.py index c3376c0..c7c0dd7 100644 --- a/wetest/testing/reader.py +++ b/wetest/testing/reader.py @@ -26,6 +26,7 @@ from pkg_resources import resource_filename from pykwalify import errors from pykwalify.core import Core +from semver import Version from wetest.common.constants import ( FILE_HANDLER, @@ -57,8 +58,7 @@ WETEST_METADATA = importlib.metadata.metadata("WeTest") # Maximum file version supported -VERSION = importlib.metadata.version("WeTest") -MAJOR, MINOR, BUGFIX = (int(x) for x in VERSION.split(".")) +VERSION = Version.parse(importlib.metadata.version("WeTest")) REPOSITORY = WETEST_METADATA["Home-page"] @@ -79,6 +79,13 @@ class UnsupportedFileFormatError(WeTestError): supported one. """ + def __init__(self, version): + super().__init__( + f"Scenario version '{version}' not supported. " + f"Current WeTest version: '{VERSION}'.\n" + f"Look at the WeTest repository for the CHANGELOG:\n{REPOSITORY}" + ) + class InvalidFileContentError(WeTestError): """Somethings not right in YAML file. @@ -327,7 +334,7 @@ def __init__( self.version = f"{self.major!s}.{self.minor!s}.{self.bugfix!s}" self.version_is_supported = ScenarioReader.supports_version( - self.major, self.minor, self.bugfix + int(self.major), int(self.minor), int(self.bugfix) ) # Check YAML file schema and other validation @@ -683,7 +690,7 @@ def noncompulsory_validation(self): return errors @staticmethod - def supports_version(major: str, minor: str, bugfix: str) -> bool: + def supports_version(major: int, minor: int, bugfix: int) -> bool: """Check if configuration file format version is supported. :param major: major version @@ -691,56 +698,27 @@ def supports_version(major: str, minor: str, bugfix: str) -> bool: :param bugfix: patch version :returns: True if version is supported, - otherwise prompt the user for continue or abort. + otherwise raises an UnsupportedFileFormatError """ - # get file version - major = int(major) - minor = int(minor) - bugfix = int(bugfix) - - version = f"{major}.{minor}.{bugfix}" - - logger.info("Configuration file format version: %i.%i.%i", major, minor, bugfix) - - compatible_version = True - try_continue = True - - if major != MAJOR: - compatible_version = False - try_continue = False - logger.critical("File incompatible with reader of installed WeTest.") - elif minor > MINOR: - compatible_version = False - logger.error( - "File version (%s) too recent for installed WeTest (%s).", - version, - f"{MAJOR}.{MINOR}.{BUGFIX}", - ) - elif minor < MINOR: - compatible_version = False + file_version = Version(major, minor, bugfix) + + logger.debug("scenario file version is: %s", file_version) + + if not file_version.is_compatible(VERSION): + raise UnsupportedFileFormatError(file_version) + + if file_version.minor < VERSION.minor: logger.warning( - "File version (%s) for older version than the installed WeTest (%s).", - version, - f"{MAJOR}.{MINOR}.{BUGFIX}", + "A new file version is available: '%s'. " + "Current scenario file version: '%s'", + VERSION, + file_version, ) - - if not compatible_version: logger.warning( "Look at the WeTest repository for the CHANGELOG:\n%s", REPOSITORY ) - - if not try_continue: - logger.error( - "File format version is: %s, but wetest version is: %s.%s.%s", - version, - MAJOR, - MINOR, - BUGFIX, - ) - sys.exit(5) - - return compatible_version + return True def is_valid(self): """YAML file format is valid. From f148e7ddcac93d69ecb739a676fc69f52c181dfb Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 11 Dec 2023 16:28:51 +0100 Subject: [PATCH 09/10] fix(tests): fix reader tests also fix test yaml files to have the correct version --- tests/acceptance-demo.yaml | 4 +- tests/bad.yml | 4 +- tests/mks946-testing.yaml | 4 +- tests/mks946.yaml | 4 +- tests/scenario_example01.yaml | 6 +-- tests/scenario_example02.yaml | 8 +-- tests/scenario_example03.yaml | 6 +-- tests/scenario_example04.yaml | 6 +-- tests/scenario_example05.yaml | 6 +-- tests/suite_example01.yaml | 10 ++-- tests/test_testing_reader.py | 92 ++++++++++++++++++----------------- 11 files changed, 77 insertions(+), 73 deletions(-) diff --git a/tests/acceptance-demo.yaml b/tests/acceptance-demo.yaml index 98c1802..4bf58e0 100644 --- a/tests/acceptance-demo.yaml +++ b/tests/acceptance-demo.yaml @@ -1,7 +1,7 @@ version: major: 1 - minor: 0 - bugfix: 0 + minor: 2 + bugfix: 2 config: type: functional diff --git a/tests/bad.yml b/tests/bad.yml index a623dd9..c211732 100644 --- a/tests/bad.yml +++ b/tests/bad.yml @@ -1,7 +1,7 @@ version: major: 1 - minor: 0 - bugfix: 0 + minor: 2 + bugfix: 2 config: type: unit diff --git a/tests/mks946-testing.yaml b/tests/mks946-testing.yaml index 3b35bc1..8c721cb 100644 --- a/tests/mks946-testing.yaml +++ b/tests/mks946-testing.yaml @@ -1,7 +1,7 @@ version: major: 1 - minor: 0 - bugfix: 0 + minor: 2 + bugfix: 2 config: type: unit diff --git a/tests/mks946.yaml b/tests/mks946.yaml index 54582f3..bbec254 100644 --- a/tests/mks946.yaml +++ b/tests/mks946.yaml @@ -1,7 +1,7 @@ version: major: 1 - minor: 0 - bugfix: 0 + minor: 2 + bugfix: 2 config: type: unit diff --git a/tests/scenario_example01.yaml b/tests/scenario_example01.yaml index f992634..d8df0a3 100644 --- a/tests/scenario_example01.yaml +++ b/tests/scenario_example01.yaml @@ -1,7 +1,7 @@ version: - major: 0 - minor: 1 - bugfix: 0 + major: 1 + minor: 2 + bugfix: 2 config: type: "unit" diff --git a/tests/scenario_example02.yaml b/tests/scenario_example02.yaml index 188b3dc..46b5159 100644 --- a/tests/scenario_example02.yaml +++ b/tests/scenario_example02.yaml @@ -1,7 +1,9 @@ version: - major: 0 - minor: 1 - bugfix: 0 + major: 1 + minor: 2 + bugfix: 2 + +config: {} tests: - name: "Sequence 1" diff --git a/tests/scenario_example03.yaml b/tests/scenario_example03.yaml index f2bef9f..96c1bf2 100644 --- a/tests/scenario_example03.yaml +++ b/tests/scenario_example03.yaml @@ -1,7 +1,7 @@ version: - major: 0 - minor: 1 - bugfix: 0 + major: 1 + minor: 2 + bugfix: 2 config: type: functional diff --git a/tests/scenario_example04.yaml b/tests/scenario_example04.yaml index 4dfe80b..ae9aef4 100644 --- a/tests/scenario_example04.yaml +++ b/tests/scenario_example04.yaml @@ -1,7 +1,7 @@ version: - major: 0 - minor: 1 - bugfix: 0 + major: 1 + minor: 2 + bugfix: 2 config: type: functional diff --git a/tests/scenario_example05.yaml b/tests/scenario_example05.yaml index 422781c..83d16f7 100644 --- a/tests/scenario_example05.yaml +++ b/tests/scenario_example05.yaml @@ -1,7 +1,7 @@ version: - major: 0 - minor: 1 - bugfix: 0 + major: 1 + minor: 2 + bugfix: 2 config: type: functional diff --git a/tests/suite_example01.yaml b/tests/suite_example01.yaml index 890e6d9..aed7fa2 100644 --- a/tests/suite_example01.yaml +++ b/tests/suite_example01.yaml @@ -1,11 +1,11 @@ version: major: 1 - minor: 0 - bugfix: 0 + minor: 2 + bugfix: 2 name: "ExampleSuite01" include: - - 'wetest/tests/scenario_example01.yaml' - - 'wetest/tests/scenario_example02.yaml' - - 'wetest/tests/scenario_example03.yaml' + - 'tests/scenario_example01.yaml' + - 'tests/scenario_example02.yaml' + - 'tests/scenario_example03.yaml' diff --git a/tests/test_testing_reader.py b/tests/test_testing_reader.py index 5e5aeb8..b928a82 100644 --- a/tests/test_testing_reader.py +++ b/tests/test_testing_reader.py @@ -3,64 +3,66 @@ # Asserts are used here, # ruff: noqa: S101 -import unittest - import pytest -from wetest.testing.reader import ( - Reader, - ScenarioReader, - SuiteReader, - UnsupportedFileFormatError, -) +from wetest.testing.reader import ScenarioReader, UnsupportedFileFormatError + + +def test_yaml_version_checker(): + """Test supported versions are well identified.""" + assert ScenarioReader.supports_version(major=1, minor=0, bugfix=0) + assert ScenarioReader.supports_version(major=1, minor=1, bugfix=0) + assert ScenarioReader.supports_version(major=1, minor=2, bugfix=0) + assert ScenarioReader.supports_version(major=1, minor=2, bugfix=2) + with pytest.raises(UnsupportedFileFormatError): + ScenarioReader.supports_version(major=0, minor=0, bugfix=0) + with pytest.raises(UnsupportedFileFormatError): + ScenarioReader.supports_version(major=2, minor=1, bugfix=0) + with pytest.raises(UnsupportedFileFormatError): + ScenarioReader.supports_version(major=1, minor=3, bugfix=1) + + +def test_scenario_example01_syntax(): + assert ScenarioReader("tests/scenario_example01.yaml").is_valid() + + +def test_scenario_example02_syntax(): + assert ScenarioReader("tests/scenario_example02.yaml").is_valid() + + +def test_scenario_example03_syntax(): + assert ScenarioReader("tests/scenario_example03.yaml").is_valid() + + +def test_scenario_example04_syntax(): + assert ScenarioReader("tests/scenario_example04.yaml").is_valid() -class TestYAMLReading(unittest.TestCase): - """Module's Unit Tests.""" +def test_scenario_example05_syntax(): + assert ScenarioReader("tests/scenario_example05.yaml").is_valid() - def test_yaml_version_checker(self): - """Test supported versions are well identified.""" - assert True is Reader()._version_is_supported(major=1, minor=0, bugfix=0) - assert True is Reader()._version_is_supported(major=0, minor=1, bugfix=0) - assert True is Reader()._version_is_supported(major=0, minor=0, bugfix=1) - with pytest.raises(UnsupportedFileFormatError): - Reader()._version_is_supported(major=2, minor=0, bugfix=0) - with pytest.raises(UnsupportedFileFormatError): - Reader()._version_is_supported(major=1, minor=1, bugfix=0) - with pytest.raises(UnsupportedFileFormatError): - Reader()._version_is_supported(major=1, minor=0, bugfix=1) - def test_scenario_example01_syntax(self): - assert True is ScenarioReader("wetest/tests/scenario_example01.yaml").is_valid() +def test_scenario_acceptance_demo_syntax(): + assert ScenarioReader("tests/acceptance-demo.yaml").is_valid() - def test_scenario_example02_syntax(self): - assert True is ScenarioReader("wetest/tests/scenario_example02.yaml").is_valid() - def test_scenario_example03_syntax(self): - assert True is ScenarioReader("wetest/tests/scenario_example03.yaml").is_valid() +def test_scenario_mks946_testing_syntax(): + assert ScenarioReader("tests/mks946-testing.yaml").is_valid() - def test_scenario_example04_syntax(self): - assert True is ScenarioReader("wetest/tests/scenario_example04.yaml").is_valid() - def test_scenario_example05_syntax(self): - assert True is ScenarioReader("wetest/tests/scenario_example05.yaml").is_valid() +def test_scenario_mks946_syntax(): + assert ScenarioReader("tests/mks946.yaml").is_valid() - def test_scenario_acceptance_demo_syntax(self): - assert True is ScenarioReader("wetest/tests/acceptance-demo.yaml").is_valid() - def test_scenario_mks946_testing_syntax(self): - assert True is ScenarioReader("wetest/tests/mks946-testing.yaml").is_valid() +def test_suite_example01_syntax(): + assert ScenarioReader("tests/suite_example01.yaml").is_valid() - def test_scenario_mks946_syntax(self): - assert True is ScenarioReader("wetest/tests/mks946.yaml").is_valid() - def test_suite_example01_syntax(self): - assert True is SuiteReader("wetest/tests/suite_example01.yaml").is_valid() +def test_scenario_are_deserialized_in_suite(): + num_scenarios = 3 + suite = ScenarioReader("tests/suite_example01.yaml").get_deserialized() + assert len(suite["scenarios"]) == num_scenarios - def test_scenario_are_deserialized_in_suite(self): - suite = SuiteReader("wetest/tests/suite_example01.yaml").get_deserialized() - assert len(suite["scenarios"]) == 2 - # TODO(gohierf): Issue 10 - Bad parsing should fail - # def test_bad_syntax(self): - # self.assertEqual(False, "wetest/tests/bad.yml")) +def test_bad_syntax(): + assert not ScenarioReader("tests/bad.yml").is_valid() From 90a90bf4f703f3b444760f091b7892d3b18b4a0a Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 12 Dec 2023 08:51:00 +0100 Subject: [PATCH 10/10] chore(tests): remove non-working tests use GitHub's issue tracker instead --- tests/test_report_generator.py | 52 --------------------------------- tests/test_schema.py | 28 ------------------ tests/test_testing_generator.py | 48 ------------------------------ 3 files changed, 128 deletions(-) delete mode 100644 tests/test_report_generator.py delete mode 100644 tests/test_schema.py delete mode 100644 tests/test_testing_generator.py diff --git a/tests/test_report_generator.py b/tests/test_report_generator.py deleted file mode 100644 index 6b837a7..0000000 --- a/tests/test_report_generator.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Test report.generator module.""" - -import unittest - -import wetest.command_line -from wetest.report.generator import ReportGenerator - - -class TestReportGenerator(unittest.TestCase): - """Module's Unit Tests.""" - - def test_generates_report_without_error(self): - """Check a report can be generated.""" - suite, _ = wetest.command_line.new_suite_from( - scenario_file="wetest/tests/acceptance-demo.yaml", - skip_all=True, - ) - _, results, _ = wetest.command_line.Runner(suite).run() - ReportGenerator( - suite, - results, - ".test-report.pdf", - title="ReportGenerator Test", - ).save() - - def test_generates_another_report_without_error(self): - """Check a report can be generated with many commands.""" - suite, _ = wetest.command_line.new_suite_from( - scenario_file="wetest/tests/source-at-0-reference.yml", - skip_all=True, - ) - _, results, _ = wetest.command_line.Runner(suite).run() - ReportGenerator( - suite, - results, - ".test-report2.pdf", - title="ReportGenerator Test with many commands", - ).save() - - def test_generates_unit_testing_report_without_error(self): - """Check a report can be generated with many commands.""" - suite, _ = wetest.command_line.new_suite_from( - scenario_file="wetest/tests/mks946.yaml", - skip_all=True, - ) - _, results, _ = wetest.command_line.Runner(suite).run() - ReportGenerator( - suite, - results, - ".test-report3.pdf", - title="ReportGenerator Test with many commands", - ).save() diff --git a/tests/test_schema.py b/tests/test_schema.py deleted file mode 100644 index e6c0681..0000000 --- a/tests/test_schema.py +++ /dev/null @@ -1,28 +0,0 @@ -import unittest - -from pykwalify.core import Core - - -class TestReportGenerator(unittest.TestCase): - """Module's Unit Tests.""" - - def test_scenario_01(self): - c = Core( - source_file="wetest/tests/scenario_example01.yaml", - schema_files=["wetest/resources/scenario_schema.yaml"], - ) - c.validate() - - def test_scenario_02(self): - c = Core( - source_file="wetest/tests/scenario_example02.yaml", - schema_files=["wetest/resources/scenario_schema.yaml"], - ) - c.validate() - - def test_suite(self): - c = Core( - source_file="wetest/tests/suite_example01.yaml", - schema_files=["wetest/resources/suite_schema.yaml"], - ) - c.validate() diff --git a/tests/test_testing_generator.py b/tests/test_testing_generator.py deleted file mode 100644 index 2df47dc..0000000 --- a/tests/test_testing_generator.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Test testing.generator module.""" - -# Asserts are used here, -# ruff: noqa: S101 - -import unittest - -from wetest.testing.generator import TestsGenerator, TestsSequence, get_key -from wetest.testing.reader import ScenarioReader - - -class TestTestsGenerator(unittest.TestCase): - """Module's Unit Tests.""" - - def test_generator(self): - """Test generator can read and generates tests.""" - scenario = ScenarioReader("wetest/tests/mks946.yaml") - tests = TestsGenerator(scenario.get_deserialized()) - tests.generates(TestsSequence) - - def test_device_prefix(self): - """Device prefix is correctyl used.""" - scenario = ScenarioReader("wetest/tests/scenario_example03.yaml") - tests = TestsGenerator(scenario.get_deserialized()) - tests.generates(TestsSequence) - - def test_get_prefix(self): - """Prefix is correctly assembled from prefix fields.""" - scenario = ScenarioReader("wetest/tests/scenario_example03.yaml") - tests = TestsGenerator(scenario.get_deserialized()) - assert tests.tests_list[0][0].prefix == "LOCATION:DEVICE:" - - def test_get_setter(self): - """Setter is correctly defined.""" - scenario = ScenarioReader("wetest/tests/scenario_example03.yaml") - tests = TestsGenerator(scenario.get_deserialized()) - setter = get_key( - tests.data["tests"][0]["commands"][0], - tests.data["tests"][0], - "setter", - ) - assert setter == "LockS" - getter = get_key( - tests.data["tests"][0]["commands"][0], - tests.data["tests"][0], - "getter", - ) - assert getter == "LockR"