From 9d6d6d3c355f2e46e121473afcc033e1f7c7715a Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 16:41:30 +0100 Subject: [PATCH 1/7] Add some missing tests --- tests/unit_tests/python/qt/test_error_catcher.py | 5 +++++ tests/unit_tests/python/qt/test_model.py | 8 ++++++++ .../unit_tests/python/qt/test_table_item_delegates.py | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/tests/unit_tests/python/qt/test_error_catcher.py b/tests/unit_tests/python/qt/test_error_catcher.py index 4b572d8c..7a92e16d 100644 --- a/tests/unit_tests/python/qt/test_error_catcher.py +++ b/tests/unit_tests/python/qt/test_error_catcher.py @@ -2,6 +2,7 @@ # Authored by Robert Applin, 2020 import pytest +from n_body_simulations.qt.error_catcher import ErrorReporter from n_body_simulations.test_helpers.dummy_class_helper import DummyErrorProneClass from n_body_simulations.test_helpers.setup_test_helper import enable_test_mode @@ -39,3 +40,7 @@ def test_that_a_function_returning_nothing_will_not_cause_an_error_when_decorate def test_that_a_function_will_return_the_correct_value_when_decorated_by_the_error_catcher(dummy_class): assert dummy_class.function_that_returns_a_value() == 1.0 + + +def test_ErrorReporter_can_be_instantiated_without_an_error(): + _ = ErrorReporter() diff --git a/tests/unit_tests/python/qt/test_model.py b/tests/unit_tests/python/qt/test_model.py index d4a175e3..dc4b4bb6 100644 --- a/tests/unit_tests/python/qt/test_model.py +++ b/tests/unit_tests/python/qt/test_model.py @@ -188,3 +188,11 @@ def test_that_set_y_velocity_fails_silently_if_an_invalid_body_name_is_provided( def test_that_running_a_simulation_does_not_raise_when_a_successful_simulation_is_run(model): model.start() model.wait() + + +def test_that_simulation_results_returns_the_expected_masses_positions_and_velocities(model): + masses, positions, velocities = model.simulation_results() + + assert len(masses) == 2 + assert len(positions) == 2 + assert len(velocities) == 2 diff --git a/tests/unit_tests/python/qt/test_table_item_delegates.py b/tests/unit_tests/python/qt/test_table_item_delegates.py index 753737e5..4ac46459 100644 --- a/tests/unit_tests/python/qt/test_table_item_delegates.py +++ b/tests/unit_tests/python/qt/test_table_item_delegates.py @@ -19,6 +19,16 @@ def test_that_creating_a_DoubleItemDelegate_does_not_raise_an_exception(): _ = DoubleItemDelegate(table, DoubleItemDelegate.Mass) +def test_DoubleItemDelegate_handle_item_exited_sets_hovered_row_to_minus_one(): + table = DummyBodyTable() + delegate = DoubleItemDelegate(table, DoubleItemDelegate.Mass) + + delegate.hovered_row = 0 + delegate.handle_item_exited(None) + + assert delegate.hovered_row == -1 + + def test_that_creating_a_StringItemDelegate_does_not_raise_an_exception(): table = DummyBodyTable() _ = StringItemDelegate(table) From 1ba6e9b9cc32b873b3b0632961f33377a7bdd6c6 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 16:41:54 +0100 Subject: [PATCH 2/7] Increase test coverage minimum to 80 --- .coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 7fcad77a..4e6a36ed 100644 --- a/.coveragerc +++ b/.coveragerc @@ -9,5 +9,5 @@ omit = n_body_simulations/qt/view.py [report] -fail_under=75 +fail_under=80 show_missing=true From 2f1f152b11f14391a62ee87871fcc9208bd3c521 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 16:43:39 +0100 Subject: [PATCH 3/7] Run coverage test on ubuntu workflow --- .github/workflows/ubuntu.yml | 8 +++++++- .github/workflows/windows.yml | 8 +------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 172114c3..7aa7282c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -55,7 +55,13 @@ jobs: env: QT_QPA_PLATFORM: offscreen # Prevent 'DISPLAY is undefined' and 'Fatal Python error' errors related to instantiating xcb plugin. run: | - xvfb-run --server-args="-core -noreset -screen 0 640x480x24" --server-num=101 pytest tests/unit_tests/python/ + xvfb-run --server-args="-core -noreset -screen 0 640x480x24" --server-num=101 coverage run -m pytest tests/unit_tests/python/ + - name: Report Unit Test Coverage + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + coveralls --service=github + coverage report - name: Python System Tests env: QT_QPA_PLATFORM: offscreen # Prevent 'DISPLAY is undefined' and 'Fatal Python error' errors related to instantiating xcb plugin. diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 26615f3b..06386050 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -53,13 +53,7 @@ jobs: $TESTPATH/NBodySimulationsSystemTests.exe - name: Python Unit Tests run: | - coverage run -m pytest tests/unit_tests/python/ - - name: Report Unit Test Coverage - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - coveralls --service=github - coverage report + pytest tests/unit_tests/python/ - name: Python System Tests run: | pytest tests/system_tests/python/ From 92bfe79a8f30f50ce9ba7adc37a362f8b696a69f Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 17:07:12 +0100 Subject: [PATCH 4/7] Move tools to pyproject toml --- .coveragerc | 13 ------------- pyproject.toml | 18 ++++++++++++++++++ pytest.ini | 4 ---- 3 files changed, 18 insertions(+), 17 deletions(-) delete mode 100644 .coveragerc delete mode 100644 pytest.ini diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 4e6a36ed..00000000 --- a/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -include = - n_body_simulations/plotting/* - n_body_simulations/qt/* - -omit = - n_body_simulations/plotting/interactive_plot.py - n_body_simulations/qt/ui/* - n_body_simulations/qt/view.py - -[report] -fail_under=80 -show_missing=true diff --git a/pyproject.toml b/pyproject.toml index aa59ea41..ab50b501 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,3 +21,21 @@ classifiers = [ [project.urls] "Homepage" = "https://github.com/robertapplin/N-Body-Simulations" + +[tool.pytest.ini_options] +filterwarnings = ["error"] + +[tool.coverage.report] +include = [ + "*/n_body_simulations/plotting/*", + "*/n_body_simulations/qt/*" +] + +omit = [ + "*/n_body_simulations/plotting/interactive_plot.py", + "*/n_body_simulations/qt/ui/*", + "*/n_body_simulations/qt/view.py" +] + +fail_under = 85 +show_missing = "true" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index e6046e25..00000000 --- a/pytest.ini +++ /dev/null @@ -1,4 +0,0 @@ -[pytest] -minversion = 6.2.1 -filterwarnings = - error From 75f5a26c3c854c64e539d72f0c77c0d32648d90b Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 17:10:49 +0100 Subject: [PATCH 5/7] Add test to model --- tests/unit_tests/python/qt/test_model.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit_tests/python/qt/test_model.py b/tests/unit_tests/python/qt/test_model.py index dc4b4bb6..f6544d31 100644 --- a/tests/unit_tests/python/qt/test_model.py +++ b/tests/unit_tests/python/qt/test_model.py @@ -190,6 +190,10 @@ def test_that_running_a_simulation_does_not_raise_when_a_successful_simulation_i model.wait() +def test_that_running_a_simulation_does_not_raise_an_error(model): + model.run() + + def test_that_simulation_results_returns_the_expected_masses_positions_and_velocities(model): masses, positions, velocities = model.simulation_results() From 123684ed9e0fff6f7ddf07e52432e7d503915578 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 17:15:34 +0100 Subject: [PATCH 6/7] Move setup cfg to pyproject toml --- pyproject.toml | 3 +++ setup.cfg | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index ab50b501..364205b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,9 @@ classifiers = [ [project.urls] "Homepage" = "https://github.com/robertapplin/N-Body-Simulations" +[tool.setuptools.packages.find] +include = ["n_body_simulations*"] + [tool.pytest.ini_options] filterwarnings = ["error"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b6aa695d..00000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[options] -packages = find: - -[options.packages.find] -include = n_body_simulations* From d1a66dd15aa58be890497e9200776ebb73e77fd3 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 6 Apr 2023 17:17:07 +0100 Subject: [PATCH 7/7] Install testing yaml instead of developer --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 658d806b..d04b194e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -43,7 +43,7 @@ RUN cd /usr && \ # Initialize conda and create an environment RUN cd /usr/N-Body-Simulations && \ conda init && \ - conda env create -f conda/developer.yml + conda env create -f conda/testing.yml # Activate conda environment, and install the N-Body-Simulations package SHELL ["conda", "run", "-n", "n-body-env", "python", "/usr/N-Body-Simulations/setup.py", "install"]