Skip to content

Commit

Permalink
Merge pull request #142 from robertapplin/0-add-missing-tests
Browse files Browse the repository at this point in the history
A slight refactor
  • Loading branch information
robertapplin authored Apr 6, 2023
2 parents 82128a6 + d1a66dd commit 13b1001
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 31 deletions.
13 changes: 0 additions & 13 deletions .coveragerc

This file was deleted.

8 changes: 7 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,24 @@ 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"]

[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"
4 changes: 0 additions & 4 deletions pytest.ini

This file was deleted.

5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

5 changes: 5 additions & 0 deletions tests/unit_tests/python/qt/test_error_catcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
12 changes: 12 additions & 0 deletions tests/unit_tests/python/qt/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,15 @@ 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_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()

assert len(masses) == 2
assert len(positions) == 2
assert len(velocities) == 2
10 changes: 10 additions & 0 deletions tests/unit_tests/python/qt/test_table_item_delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 13b1001

Please sign in to comment.