From 813f1b355078105668c6189945e47a4a7a646706 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Fri, 7 Feb 2020 16:06:51 -0800 Subject: [PATCH 1/6] - Fixed test_train_model test in code_test.py - Renamed code_test.py to train_test.py - Moved train_test.py under diabetes_regression directory - Moved data_test.py under data directory - Added lint and unit test tasks to azdo-base-pipeline.yml - Deleted lint-and-test.sh and tox.ini --- .pipelines/azdo-base-pipeline.yml | 16 +++++++++++++--- {tests/unit => data}/data_test.py | 2 +- .../training/test_train.py | 11 ++++++++--- lint-and-test.sh | 4 ---- tox.ini | 7 ------- 5 files changed, 22 insertions(+), 18 deletions(-) rename {tests/unit => data}/data_test.py (98%) rename tests/unit/code_test.py => diabetes_regression/training/test_train.py (66%) delete mode 100755 lint-and-test.sh delete mode 100644 tox.ini diff --git a/.pipelines/azdo-base-pipeline.yml b/.pipelines/azdo-base-pipeline.yml index ad0e4ad8..2ffe6cfe 100644 --- a/.pipelines/azdo-base-pipeline.yml +++ b/.pipelines/azdo-base-pipeline.yml @@ -1,7 +1,17 @@ steps: -- script: | - ./lint-and-test.sh - displayName: 'Linting & unit tests' +- task: PythonScript@0 + inputs: + scriptSource: inline + script: set -eux + flake8 --output-file=lint-testresults.xml --format junit-xml + displayName: 'Run lint tests' + +- task: PythonScript@0 + inputs: + scriptSource: inline + script: set -eux + python -m pytest tests/unit --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml + displayName: 'Test with pytest' - task: PublishTestResults@2 condition: succeededOrFailed() diff --git a/tests/unit/data_test.py b/data/data_test.py similarity index 98% rename from tests/unit/data_test.py rename to data/data_test.py index 4148f029..6d7d2ddf 100644 --- a/tests/unit/data_test.py +++ b/data/data_test.py @@ -35,7 +35,7 @@ def get_absPath(filename): path = os.path.abspath( os.path.join( os.path.dirname( - __file__), os.path.pardir, os.path.pardir, "data", filename + __file__), os.path.pardir, "data", filename ) ) return path diff --git a/tests/unit/code_test.py b/diabetes_regression/training/test_train.py similarity index 66% rename from tests/unit/code_test.py rename to diabetes_regression/training/test_train.py index 1b133766..e6a9a58d 100644 --- a/tests/unit/code_test.py +++ b/diabetes_regression/training/test_train.py @@ -15,8 +15,13 @@ def test_train_model(): run = Mock(Run) reg = train_model(run, data, alpha=1.2) - run.log.assert_called_with("mse", 0.029843893480257067, - description='Mean squared error metric') + _, call2 = run.log.call_args_list + nameValue, descriptionDict = call2 + name, value = nameValue + description = descriptionDict['description'] + assert (name == 'mse') + np.testing.assert_almost_equal(value, 0.029843893480257067) + assert (description == 'Mean squared error metric') preds = reg.predict([[1], [2]]) - np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303]) + np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303]) \ No newline at end of file diff --git a/lint-and-test.sh b/lint-and-test.sh deleted file mode 100755 index 77c646ba..00000000 --- a/lint-and-test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eux -flake8 --output-file=lint-testresults.xml --format junit-xml -python -m pytest tests/unit --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml diff --git a/tox.ini b/tox.ini deleted file mode 100644 index e24d8ae1..00000000 --- a/tox.ini +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -# ignore obsolete warning -ignore = W503 -exclude = .git,__pycache__,.venv,.tox,**/site-packages/**/*.py,**/lib/**.py,**/bin/**.py - -[pytest] -junit_family = legacy From b36742145da60bc9c9a49e8d8c9339278deabd57 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Fri, 7 Feb 2020 17:48:10 -0800 Subject: [PATCH 2/6] Resolved PR comments --- .pipelines/azdo-base-pipeline.yml | 16 +++++----------- diabetes_regression/ci_dependencies.yml | 1 - docs/development_setup.md | 4 ---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.pipelines/azdo-base-pipeline.yml b/.pipelines/azdo-base-pipeline.yml index 2ffe6cfe..0eb05b98 100644 --- a/.pipelines/azdo-base-pipeline.yml +++ b/.pipelines/azdo-base-pipeline.yml @@ -1,17 +1,11 @@ steps: -- task: PythonScript@0 - inputs: - scriptSource: inline - script: set -eux - flake8 --output-file=lint-testresults.xml --format junit-xml +- script: | + flake8 --output-file=lint-testresults.xml --format junit-xml displayName: 'Run lint tests' -- task: PythonScript@0 - inputs: - scriptSource: inline - script: set -eux - python -m pytest tests/unit --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml - displayName: 'Test with pytest' +- script: | + python -m pytest tests/unit --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml + displayName: 'Run unit tests' - task: PublishTestResults@2 condition: succeededOrFailed() diff --git a/diabetes_regression/ci_dependencies.yml b/diabetes_regression/ci_dependencies.yml index c5463456..d6a52ed0 100644 --- a/diabetes_regression/ci_dependencies.yml +++ b/diabetes_regression/ci_dependencies.yml @@ -25,4 +25,3 @@ dependencies: - flake8==3.7.9 - flake8_formatter_junit_xml==0.0.6 - azure-cli==2.0.81 - - tox==3.14.3 diff --git a/docs/development_setup.md b/docs/development_setup.md index 8565ff04..68e6b6bf 100644 --- a/docs/development_setup.md +++ b/docs/development_setup.md @@ -38,7 +38,3 @@ BUILD_BUILDID is a variable used to uniquely identify the ML pipeline between th set to the current build number. In a local environment, we can use a command such as `uuidgen` so set a different random identifier on each run, ensuring there are no collisions. - -### Local testing - -Before committing, run `tox` to execute linter and unit test checks. From ac740ba4ca9cb881a3c697bd94a9f34e5c6dde85 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 10 Feb 2020 11:50:04 -0800 Subject: [PATCH 3/6] Removed test/unit directory --- tests/unit/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/unit/__init__.py diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index e69de29b..00000000 From c9d704e40e3224c86843dc94e76aa69e18d308e6 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 10 Feb 2020 11:52:21 -0800 Subject: [PATCH 4/6] Added newline --- diabetes_regression/training/test_train.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diabetes_regression/training/test_train.py b/diabetes_regression/training/test_train.py index e6a9a58d..eb0fa2b3 100644 --- a/diabetes_regression/training/test_train.py +++ b/diabetes_regression/training/test_train.py @@ -24,4 +24,5 @@ def test_train_model(): assert (description == 'Mean squared error metric') preds = reg.predict([[1], [2]]) - np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303]) \ No newline at end of file + np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303]) + \ No newline at end of file From c319b8fc7a715041dc6e610bb4971d85f8941c46 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 10 Feb 2020 12:02:20 -0800 Subject: [PATCH 5/6] Fixed linter errors --- diabetes_regression/training/test_train.py | 1 - 1 file changed, 1 deletion(-) diff --git a/diabetes_regression/training/test_train.py b/diabetes_regression/training/test_train.py index eb0fa2b3..155d367a 100644 --- a/diabetes_regression/training/test_train.py +++ b/diabetes_regression/training/test_train.py @@ -25,4 +25,3 @@ def test_train_model(): preds = reg.predict([[1], [2]]) np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303]) - \ No newline at end of file From 9719eb6f114577e0570fe7797ada205498b9b356 Mon Sep 17 00:00:00 2001 From: Bryan Smith Date: Mon, 10 Feb 2020 12:07:28 -0800 Subject: [PATCH 6/6] fixed unit test path --- .pipelines/azdo-base-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/azdo-base-pipeline.yml b/.pipelines/azdo-base-pipeline.yml index 0eb05b98..479596f1 100644 --- a/.pipelines/azdo-base-pipeline.yml +++ b/.pipelines/azdo-base-pipeline.yml @@ -4,7 +4,7 @@ steps: displayName: 'Run lint tests' - script: | - python -m pytest tests/unit --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml + python -m pytest . --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml displayName: 'Run unit tests' - task: PublishTestResults@2