Skip to content

Commit 40c178a

Browse files
committed
Improve testing setup
Signed-off-by: Beat Buesser <[email protected]>
1 parent 62f72d7 commit 40c178a

File tree

6 files changed

+47
-51
lines changed

6 files changed

+47
-51
lines changed

art/attacks/evasion/laser_attack/laser_attack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from collections.abc import Callable
2626
import logging
27+
import math
2728
from typing import Any
2829

2930
import numpy as np
@@ -221,7 +222,7 @@ def __call__(self, x: int, y: int) -> np.ndarray:
221222
if distance <= self.width / 2.0:
222223
return self.rgb
223224
if self.width / 2.0 <= distance <= 5 * self.width:
224-
return np.math.sqrt(self.width) / np.math.pow(distance, 2) * self.rgb # type: ignore
225+
return math.sqrt(self.width) / math.pow(distance, 2) * self.rgb # type: ignore
225226

226227
return np.array([0.0, 0.0, 0.0])
227228

art/attacks/evasion/laser_attack/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from abc import ABC, abstractmethod
2626
from collections.abc import Callable
2727
from logging import Logger
28+
import math
2829
from pathlib import Path
2930
import string
3031
from typing import Any
@@ -46,7 +47,7 @@ def __init__(self, angle: float, bias: float):
4647
self.bias = bias
4748

4849
def __call__(self, x: float) -> float:
49-
return np.math.tan(self.angle) * x + self.bias # type: ignore
50+
return math.tan(self.angle) * x + self.bias # type: ignore
5051

5152
def distance_of_point_from_the_line(self, x: float, y: float) -> float:
5253
"""
@@ -58,8 +59,8 @@ def distance_of_point_from_the_line(self, x: float, y: float) -> float:
5859
:returns: Distance.
5960
"""
6061
y_difference = np.abs(self(x) - y)
61-
slope_squared = np.math.pow(np.math.tan(self.angle), 2) # type: ignore
62-
return y_difference / np.math.sqrt(1.0 + slope_squared) # type: ignore
62+
slope_squared = math.pow(math.tan(self.angle), 2) # type: ignore
63+
return y_difference / math.sqrt(1.0 + slope_squared) # type: ignore
6364

6465
def to_numpy(self) -> np.ndarray:
6566
"""

conftest.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -495,29 +495,22 @@ def _image_dl_estimator(functional=False, **kwargs):
495495
@pytest.fixture
496496
def art_warning(request):
497497
def _art_warning(exception):
498-
if type(exception) is ARTTestFixtureNotImplemented:
499-
if request.node.get_closest_marker("framework_agnostic"):
500-
if not request.node.get_closest_marker("parametrize"):
501-
raise Exception(
502-
"This test has marker framework_agnostic decorator which means it will only be ran "
503-
"once. However the ART test exception was thrown, hence it is never run fully. "
504-
)
505-
elif (
506-
request.node.get_closest_marker("only_with_platform")
507-
and len(request.node.get_closest_marker("only_with_platform").args) == 1
508-
):
498+
499+
if request.node.get_closest_marker("framework_agnostic"):
500+
if not request.node.get_closest_marker("parametrize"):
509501
raise Exception(
510-
"This test has marker only_with_platform decorator which means it will only be ran "
511-
"once. However the ARTTestFixtureNotImplemented exception was thrown, hence it is "
512-
"never run fully. "
502+
"This test has marker framework_agnostic decorator which means it will only be ran "
503+
"once. However the ART test exception was thrown, hence it is never run fully. "
513504
)
514-
515-
# NotImplementedErrors are raised in ART whenever a test model does not exist for a specific
516-
# model/framework combination. By catching there here, we can provide a report at the end of each
517-
# pytest run list all models requiring to be implemented.
518-
warnings.warn(UserWarning(exception))
519-
else:
520-
raise exception
505+
elif (
506+
request.node.get_closest_marker("only_with_platform")
507+
and len(request.node.get_closest_marker("only_with_platform").args) == 1
508+
):
509+
raise Exception(
510+
"This test has marker only_with_platform decorator which means it will only be ran "
511+
"once. However the ARTTestFixtureNotImplemented exception was thrown, hence it is "
512+
"never run fully. "
513+
)
521514

522515
return _art_warning
523516

requirements_test.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# base
44

5-
numpy
6-
scipy
5+
numpy==1.26.4
6+
scipy==1.12.0
77
matplotlib==3.10.3
88
scikit-learn==1.6.1
99
six==1.17.0
@@ -50,6 +50,7 @@ jax[cpu]==0.4.30
5050
pytest~=8.3.2
5151
pytest-mock~=3.14.0
5252
pytest-cov~=6.1.1
53+
pytest-profiling==1.8.1
5354
pylint==3.2.6
5455
mypy==1.11.1
5556
pycodestyle==2.12.1

run_tests.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,70 @@ then
1919
echo "############### Running tests with framework $framework ###############"
2020
echo "#######################################################################"
2121

22-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/evasion --framework=$framework --durations=0
22+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/evasion --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
2323
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/detector/evasion tests"; fi
2424

25-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/poison/test_spectral_signature_defense.py --framework=$framework --durations=0
25+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/poison/test_spectral_signature_defense.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
2626
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/detector/poison/test_spectral_signature_defense.py tests"; fi
2727

28-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/preprocessor --framework=$framework --durations=0
28+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/preprocessor --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
2929
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/preprocessor tests"; fi
3030

31-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/trainer --framework=$framework --durations=0
31+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/trainer --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
3232
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/trainer tests"; fi
3333

34-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/transformer --framework=$framework --durations=0
34+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/transformer --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
3535
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/transformer tests"; fi
3636

37-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/audio --framework=$framework --durations=0
37+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/audio --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
3838
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed preprocessing/audio tests"; fi
3939

40-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/image --framework=$framework --durations=0
40+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/image --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
4141
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed preprocessing/image tests"; fi
4242

43-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/expectation_over_transformation --framework=$framework --durations=0
43+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/preprocessing/expectation_over_transformation --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
4444
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed preprocessing/expectation_over_transformation tests"; fi
4545

46-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/utils --framework=$framework --durations=0
46+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/utils --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
4747
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed utils tests"; fi
4848

49-
pytest --cov-report=xml --cov=art --cov-append -q -vv -s tests/attacks/poison/ --framework=$framework --durations=0
49+
pytest --cov-report=xml --cov=art --cov-append -q -vv -s tests/attacks/poison/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
5050
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed attacks/poison tests"; fi
5151

52-
pytest --cov-report=xml --cov=art --cov-append -q -vv -s tests/attacks/evasion/ --framework=$framework --durations=0
52+
pytest --cov-report=xml --cov=art --cov-append -q -vv -s tests/attacks/evasion/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
5353
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed attacks/evasion"; fi
5454

55-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/speech_recognition/ --framework=$framework --durations=0
55+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/speech_recognition/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
5656
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/speech_recognition tests"; fi
5757

58-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/attacks/inference/ --framework=$framework --durations=0
58+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/attacks/inference/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
5959
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed attacks/inference"; fi
6060

61-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/classifiersFrameworks/ --framework=$framework --durations=0
61+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/classifiersFrameworks/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
6262
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed classifiersFrameworks tests"; fi
6363

64-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_deeplearning_common.py --framework=$framework --durations=0
64+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_deeplearning_common.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
6565
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/classification/test_deeplearning_common.py $framework"; fi
6666

67-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_deeplearning_specific.py --framework=$framework --durations=0
67+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_deeplearning_specific.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
6868
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/classification tests for framework $framework"; fi
6969

70-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/certification/ --framework=$framework --durations=0
70+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/certification/ --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
7171
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/certification tests for framework $framework"; fi
7272

73-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_blackbox_existing_predictions.py --framework=$framework --durations=0
73+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/classification/test_blackbox_existing_predictions.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
7474
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/classification/test_blackbox_existing_predictions.py $framework"; fi
7575

76-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/regression/test_blackbox.py --framework=$framework --durations=0
76+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/regression/test_blackbox.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
7777
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/regression/test_blackbox.py $framework"; fi
7878

79-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/metrics/privacy --framework=$framework --durations=0
79+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/metrics/privacy --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
8080
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed metrics/privacy tests"; fi
8181

82-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/evaluations --framework=$framework --durations=0
82+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/evaluations --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
8383
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed evaluations tests"; fi
8484

85-
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/test_summary_writer.py --framework=$framework --durations=0
85+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/test_summary_writer.py --framework=$framework --durations=20 --durations-min=0 --setup-show --profile-svg
8686
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed summary writer tests"; fi
8787

8888
else
@@ -174,7 +174,7 @@ else
174174
echo "######################################################################"
175175
echo ${test}
176176
echo "######################################################################"
177-
pytest --cov-report=xml --cov=art --cov-append -q -vv ${test} --durations=0
177+
pytest --cov-report=xml --cov=art --cov-append -q -vv ${test} --durations=20 --durations-min=0 --setup-show --profile-svg
178178
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed $test"; fi
179179
}
180180

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
description-file = README.md
33

4-
[tool:pytest]
4+
[tool:flake8]
55
flake8-max-line-length = 120
66
flake8-ignore =
77
*.py E402 W503 E203 E231 E251 E701

0 commit comments

Comments
 (0)