diff --git a/noxfile.py b/noxfile.py index e960e264..6319fed8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -52,7 +52,7 @@ def tests(session:nox.Session): # package and test dependencies session.install("-e", ".") - session.install("pytest") + session.install("pytest", "coverage") session.run("pytest", "-q") diff --git a/LabGym/tests/pytest.ini b/pytest.ini similarity index 68% rename from LabGym/tests/pytest.ini rename to pytest.ini index 385a3fef..f75122ee 100644 --- a/LabGym/tests/pytest.ini +++ b/pytest.ini @@ -1,5 +1,12 @@ # pytest.ini [pytest] +testpaths = tests + +markers = + slow: marks tests as slow + integration: markts integration tests + gui: marks tests requiring wx + # Avoid two coverage warnings from detectron2's import of cv2. # (see Notes.opencv-python-and-coverage-warnings.txt) filterwarnings = diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..a4e59139 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,45 @@ +""" +/tests/conftest.py + +Shared pytest fixtures for LabGym tests +""" + +# Standard library imports +import sys + +# Related third party imports +import pytest + +@pytest.fixture(scope="session") +def wx_app(): + from LabGym.ui.gui import wxutils + import wx + app = wx.App() + yield app + + +@pytest.fixture +def mock_argv(monkeypatch): + monkeypatch.setattr(sys, 'argv', ['LabGym']) + + +@pytest.fixture +def sample_greyscale_frame(): + import numpy as np + import cv2 + frame = np.full((100, 100), 200, dtype = np.uint8) + cv2.circle(frame, (50, 50), 15, 50, -1) + return frame + +@pytest.fixture +def sample_video_frames(): + import numpy as np + import cv2 + frames = [] + + for i in range(60): + frame = np.full((100, 100), 200, dtype = np.uint8) + cv2.circle(frame, (20 + i % 60, 50), 15, 50, -1) + frames.append(frame) + + return frames \ No newline at end of file diff --git a/LabGym/tests/coveragerc b/tests/coveragerc similarity index 100% rename from LabGym/tests/coveragerc rename to tests/coveragerc diff --git a/LabGym/tests/__init__.py b/tests/integration/__init__.py similarity index 100% rename from LabGym/tests/__init__.py rename to tests/integration/__init__.py diff --git a/LabGym/tests/INIT.sh b/tests/linting/INIT.sh similarity index 92% rename from LabGym/tests/INIT.sh rename to tests/linting/INIT.sh index 1475db15..50df101c 100644 --- a/LabGym/tests/INIT.sh +++ b/tests/linting/INIT.sh @@ -10,7 +10,7 @@ IS_VENV () { [ -n "$VIRTUAL_ENV+1" ]; } # works in sh, bash, and zsh AWK () { awk "$@"; } -PYFILES=$(cd .. && echo *.py) +PYFILES=$(cd ../../LabGym && echo *.py) # printf "%s: %s\n" "\$PYFILES" "$PYFILES" return diff --git a/LabGym/tests/pylint.sh b/tests/linting/pylint.sh similarity index 99% rename from LabGym/tests/pylint.sh rename to tests/linting/pylint.sh index 373b2ed6..2b1ebded 100644 --- a/LabGym/tests/pylint.sh +++ b/tests/linting/pylint.sh @@ -10,7 +10,7 @@ source INIT.sh -PYFILES=$(echo ../*.py ../mywx/*.py) +PYFILES=$(echo ../../LabGym/*.py ../../LabGym/mywx/*.py) OP=pylint # default OP while [ $# -gt 0 ]; do diff --git a/LabGym/tests/pylintrc b/tests/linting/pylintrc similarity index 100% rename from LabGym/tests/pylintrc rename to tests/linting/pylintrc diff --git a/LabGym/tests/pylintrc- b/tests/linting/pylintrc- similarity index 100% rename from LabGym/tests/pylintrc- rename to tests/linting/pylintrc- diff --git a/LabGym/tests/Notes.importtime.txt b/tests/notes/Notes.importtime.txt similarity index 100% rename from LabGym/tests/Notes.importtime.txt rename to tests/notes/Notes.importtime.txt diff --git a/LabGym/tests/Notes.opencv-python-and-coverage-warnings.txt b/tests/notes/Notes.opencv-python-and-coverage-warnings.txt similarity index 100% rename from LabGym/tests/Notes.opencv-python-and-coverage-warnings.txt rename to tests/notes/Notes.opencv-python-and-coverage-warnings.txt diff --git a/LabGym/tests/Notes.pytest.txt b/tests/notes/Notes.pytest.txt similarity index 100% rename from LabGym/tests/Notes.pytest.txt rename to tests/notes/Notes.pytest.txt diff --git a/LabGym/tests/pylint.Notes.txt b/tests/notes/pylint.Notes.txt similarity index 100% rename from LabGym/tests/pylint.Notes.txt rename to tests/notes/pylint.Notes.txt diff --git a/LabGym/tests/test_probes/cacert.fouled.pem b/tests/unit/__init__.py similarity index 100% rename from LabGym/tests/test_probes/cacert.fouled.pem rename to tests/unit/__init__.py diff --git a/LabGym/tests/exitstatus.py b/tests/unit/exitstatus.py similarity index 100% rename from LabGym/tests/exitstatus.py rename to tests/unit/exitstatus.py diff --git a/LabGym/tests/test___main__.py b/tests/unit/test___main__.py similarity index 100% rename from LabGym/tests/test___main__.py rename to tests/unit/test___main__.py diff --git a/LabGym/tests/test_central_logging.py b/tests/unit/test_central_logging.py similarity index 100% rename from LabGym/tests/test_central_logging.py rename to tests/unit/test_central_logging.py diff --git a/LabGym/tests/test_config.py b/tests/unit/test_config.py similarity index 100% rename from LabGym/tests/test_config.py rename to tests/unit/test_config.py diff --git a/LabGym/tests/test_config/bad.yaml b/tests/unit/test_config/bad.yaml similarity index 100% rename from LabGym/tests/test_config/bad.yaml rename to tests/unit/test_config/bad.yaml diff --git a/tests/test_load.py b/tests/unit/test_load.py similarity index 100% rename from tests/test_load.py rename to tests/unit/test_load.py diff --git a/tests/test_main.py b/tests/unit/test_main.py similarity index 100% rename from tests/test_main.py rename to tests/unit/test_main.py diff --git a/LabGym/tests/test_myargparse.py b/tests/unit/test_myargparse.py similarity index 100% rename from LabGym/tests/test_myargparse.py rename to tests/unit/test_myargparse.py diff --git a/LabGym/tests/test_mylogging.py b/tests/unit/test_mylogging.py similarity index 100% rename from LabGym/tests/test_mylogging.py rename to tests/unit/test_mylogging.py diff --git a/LabGym/tests/test_mypkg_resources.py b/tests/unit/test_mypkg_resources.py similarity index 100% rename from LabGym/tests/test_mypkg_resources.py rename to tests/unit/test_mypkg_resources.py diff --git a/LabGym/tests/test_mywx.py b/tests/unit/test_mywx.py similarity index 100% rename from LabGym/tests/test_mywx.py rename to tests/unit/test_mywx.py diff --git a/LabGym/tests/test_pkghash.py b/tests/unit/test_pkghash.py similarity index 100% rename from LabGym/tests/test_pkghash.py rename to tests/unit/test_pkghash.py diff --git a/LabGym/tests/test_probes.py b/tests/unit/test_probes.py similarity index 100% rename from LabGym/tests/test_probes.py rename to tests/unit/test_probes.py diff --git a/LabGym/tests/tmp.pylint/.gitkeep b/tests/unit/test_probes/cacert.fouled.pem similarity index 100% rename from LabGym/tests/tmp.pylint/.gitkeep rename to tests/unit/test_probes/cacert.fouled.pem diff --git a/LabGym/tests/test_probes/cacert.pem b/tests/unit/test_probes/cacert.pem similarity index 100% rename from LabGym/tests/test_probes/cacert.pem rename to tests/unit/test_probes/cacert.pem diff --git a/LabGym/tests/test_registration.py b/tests/unit/test_registration.py similarity index 100% rename from LabGym/tests/test_registration.py rename to tests/unit/test_registration.py diff --git a/LabGym/tests/test_registration/registration.yaml b/tests/unit/test_registration/registration.yaml similarity index 100% rename from LabGym/tests/test_registration/registration.yaml rename to tests/unit/test_registration/registration.yaml diff --git a/LabGym/tests/test_userdata_survey.py b/tests/unit/test_userdata_survey.py similarity index 100% rename from LabGym/tests/test_userdata_survey.py rename to tests/unit/test_userdata_survey.py