Skip to content

Commit 6efc12c

Browse files
bjcmitdtzar
andauthored
Fixed and rearranged unit tests (#184)
* 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 * Removed test/unit directory Co-authored-by: David Tesar <[email protected]>
1 parent fb1d951 commit 6efc12c

File tree

8 files changed

+15
-22
lines changed

8 files changed

+15
-22
lines changed

.pipelines/azdo-base-pipeline.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
steps:
2-
- script: |
3-
./lint-and-test.sh
4-
displayName: 'Linting & unit tests'
2+
- script: |
3+
flake8 --output-file=lint-testresults.xml --format junit-xml
4+
displayName: 'Run lint tests'
5+
6+
- script: |
7+
python -m pytest . --cov=diabetes_regression --cov-report=html --cov-report=xml --junitxml=unit-testresults.xml
8+
displayName: 'Run unit tests'
59

610
- task: PublishTestResults@2
711
condition: succeededOrFailed()

tests/unit/data_test.py renamed to data/data_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_absPath(filename):
3535
path = os.path.abspath(
3636
os.path.join(
3737
os.path.dirname(
38-
__file__), os.path.pardir, os.path.pardir, "data", filename
38+
__file__), os.path.pardir, "data", filename
3939
)
4040
)
4141
return path

diabetes_regression/ci_dependencies.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ dependencies:
2525
- flake8==3.7.9
2626
- flake8_formatter_junit_xml==0.0.6
2727
- azure-cli==2.0.81
28-
- tox==3.14.3

tests/unit/code_test.py renamed to diabetes_regression/training/test_train.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ def test_train_model():
1515
run = Mock(Run)
1616
reg = train_model(run, data, alpha=1.2)
1717

18-
run.log.assert_called_with("mse", 0.029843893480257067,
19-
description='Mean squared error metric')
18+
_, call2 = run.log.call_args_list
19+
nameValue, descriptionDict = call2
20+
name, value = nameValue
21+
description = descriptionDict['description']
22+
assert (name == 'mse')
23+
np.testing.assert_almost_equal(value, 0.029843893480257067)
24+
assert (description == 'Mean squared error metric')
2025

2126
preds = reg.predict([[1], [2]])
2227
np.testing.assert_equal(preds, [9.93939393939394, 9.03030303030303])

docs/development_setup.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,3 @@ BUILD_BUILDID is a variable used to uniquely identify the ML pipeline between th
3838
set to the current build number. In a local environment, we can use a command such as
3939
`uuidgen` so set a different random identifier on each run, ensuring there are
4040
no collisions.
41-
42-
### Local testing
43-
44-
Before committing, run `tox` to execute linter and unit test checks.

lint-and-test.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/unit/__init__.py

Whitespace-only changes.

tox.ini

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)