From 4ce10e3d5ca353282d21cd11434021cb89f7d7d1 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Thu, 27 Apr 2023 13:48:36 -0400 Subject: [PATCH 1/5] Reorganized integration tests to match unit test structure. --- test/integration_tests/__init__.py | 0 test/{ => integration_tests}/test_mincde.py | 0 test/{ => integration_tests}/test_model.py | 0 test/{ => integration_tests}/test_solver.py | 2 +- test/{ => integration_tests}/test_threads.py | 0 test/run_integration_tests.py | 6 +++--- 6 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 test/integration_tests/__init__.py rename test/{ => integration_tests}/test_mincde.py (100%) rename test/{ => integration_tests}/test_model.py (100%) rename test/{ => integration_tests}/test_solver.py (99%) rename test/{ => integration_tests}/test_threads.py (100%) diff --git a/test/integration_tests/__init__.py b/test/integration_tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/test_mincde.py b/test/integration_tests/test_mincde.py similarity index 100% rename from test/test_mincde.py rename to test/integration_tests/test_mincde.py diff --git a/test/test_model.py b/test/integration_tests/test_model.py similarity index 100% rename from test/test_model.py rename to test/integration_tests/test_model.py diff --git a/test/test_solver.py b/test/integration_tests/test_solver.py similarity index 99% rename from test/test_solver.py rename to test/integration_tests/test_solver.py index 01a72455..e3f3cfd1 100644 --- a/test/test_solver.py +++ b/test/integration_tests/test_solver.py @@ -204,7 +204,7 @@ def test_solver_expressions(self): Ensure that expression conversions to C++ result in (roughly) equivalent values as Python. """ tmpdir = tempfile.mkdtemp() - src_path = os.path.join(os.path.dirname(__file__), "assets", "evaluate.c") + src_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "assets", "evaluate.c") exe_path = os.path.join(tmpdir, "test") def build(expr_args: "list[str]", expr_str: "str", use_bool=False): diff --git a/test/test_threads.py b/test/integration_tests/test_threads.py similarity index 100% rename from test/test_threads.py rename to test/integration_tests/test_threads.py diff --git a/test/run_integration_tests.py b/test/run_integration_tests.py index ed430f1f..fe33b21a 100644 --- a/test/run_integration_tests.py +++ b/test/run_integration_tests.py @@ -28,9 +28,9 @@ print('Running tests in develop mode. Appending repository directory to system path.') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - import test_model - import test_solver - #import test_mincde + from integration_tests import test_model + from integration_tests import test_solver + #from integration_tests import test_mincde modules = [ test_model, From e6b040113b9cb51e167268aa592f57b43fa50b28 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Thu, 27 Apr 2023 13:49:35 -0400 Subject: [PATCH 2/5] Added the spatial birth death model to testing models. --- test/models/birth_death.py | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/models/birth_death.py diff --git a/test/models/birth_death.py b/test/models/birth_death.py new file mode 100644 index 00000000..c30ca4f1 --- /dev/null +++ b/test/models/birth_death.py @@ -0,0 +1,50 @@ +# SpatialPy is a Python 3 package for simulation of +# spatial deterministic/stochastic reaction-diffusion-advection problems +# Copyright (C) 2019 - 2023 SpatialPy developers. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU GENERAL PUBLIC LICENSE Version 3 as +# published by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU GENERAL PUBLIC LICENSE Version 3 for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +''' spatialpy model file for the spatial birth death example. ''' +import spatialpy + +def create_birth_death(): + ''' Create the spatial birth death model. ''' + model = spatialpy.Model(name='Spatial Birth-Death') + + model.HABITAT = "Habitat" + + domain = spatialpy.Domain.create_2D_domain( + xlim=(0, 1), ylim=(0, 1), numx=10, numy=10, type_id=model.HABITAT, fixed=True + ) + model.add_domain(domain) + + rabbits = spatialpy.Species(name='Rabbits', diffusion_coefficient=0.1) + model.add_species(rabbits) + + init_rabbit_pop = spatialpy.ScatterInitialCondition(species='Rabbits', count=100) + model.add_initial_condition(init_rabbit_pop) + + k_birth = spatialpy.Parameter(name='k_birth', expression=10) + k_death = spatialpy.Parameter(name='k_death', expression=0.1) + model.add_parameter([k_birth, k_death]) + + birth = spatialpy.Reaction( + name='birth', reactants={}, products={"Rabbits":1}, rate="k_birth" + ) + death = spatialpy.Reaction( + name='death', reactants={"Rabbits":1}, products={}, rate="k_death" + ) + model.add_reaction([birth, death]) + + tspan = spatialpy.TimeSpan.linspace(t=10, num_points=11, timestep_size=1) + model.timespan(tspan) + return model From f3c0f6ef794bea0bd35f1e8d65dc53a54b47c1aa Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Thu, 27 Apr 2023 13:50:28 -0400 Subject: [PATCH 3/5] Added system test for testing compiler. --- .github/workflows/run_system_tests.yaml | 30 ++++++++++++++++ test/__init__.py | 0 test/run_system_tests.py | 46 +++++++++++++++++++++++++ test/system_tests/__init__.py | 0 test/system_tests/test_compiler.py | 40 +++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 .github/workflows/run_system_tests.yaml create mode 100644 test/__init__.py create mode 100644 test/run_system_tests.py create mode 100644 test/system_tests/__init__.py create mode 100755 test/system_tests/test_compiler.py diff --git a/.github/workflows/run_system_tests.yaml b/.github/workflows/run_system_tests.yaml new file mode 100644 index 00000000..9ca38c8c --- /dev/null +++ b/.github/workflows/run_system_tests.yaml @@ -0,0 +1,30 @@ +name: Run SpatialPy System Tests + +on: + push: + branches: [staging, develop] + +jobs: + run-tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + + steps: + - name: Initialize environment + uses: actions/checkout@v2 + + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + + - name: Install Python dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + python3 -m pip install coverage + + - name: Run tests + run: coverage run --source=spatialpy test/run_system_tests.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/run_system_tests.py b/test/run_system_tests.py new file mode 100644 index 00000000..7a550bfe --- /dev/null +++ b/test/run_system_tests.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# SpatialPy is a Python 3 package for simulation of +# spatial deterministic/stochastic reaction-diffusion-advection problems +# Copyright (C) 2019 - 2023 SpatialPy developers. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU GENERAL PUBLIC LICENSE Version 3 as +# published by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU GENERAL PUBLIC LICENSE Version 3 for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import os +import sys +import unittest +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument('-m', '--mode', default='develop', choices=['develop', 'release'], + help='Run system tests in develop mode or release mode.') + +if __name__ == '__main__': + args = parser.parse_args() + if args.mode == 'develop': + print('Running system tests in develop mode. Appending repository directory to system path.') + sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + + from system_tests import test_compiler + + modules = [ + test_compiler + ] + + for module in modules: + suite = unittest.TestLoader().loadTestsFromModule(module) + runner = unittest.TextTestRunner(failfast=args.mode == 'develop') + + print(f"Executing: {module}") + result = runner.run(suite) + print('=' * 70) + if not result.wasSuccessful(): + sys.exit(not result.wasSuccessful()) diff --git a/test/system_tests/__init__.py b/test/system_tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/system_tests/test_compiler.py b/test/system_tests/test_compiler.py new file mode 100755 index 00000000..4b37c57e --- /dev/null +++ b/test/system_tests/test_compiler.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# SpatialPy is a Python 3 package for simulation of +# spatial deterministic/stochastic reaction-diffusion-advection problems +# Copyright (C) 2019 - 2023 SpatialPy developers. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU GENERAL PUBLIC LICENSE Version 3 as +# published by the Free Software Foundation. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU GENERAL PUBLIC LICENSE Version 3 for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +''' Tests from the compiler. ''' +import os +import sys +print(os.getcwd()) +sys.path.insert(1, os.path.abspath(os.getcwd())) +import unittest + +from test.models.birth_death import create_birth_death + +class TestCompiler(unittest.TestCase): + ''' + ################################################################################################ + System test for compiler. + ################################################################################################ + ''' + def setUp(self): + self.model = create_birth_death() + + def test_constructor(self): + """ Test the compiler. """ + _ = self.model.run() + +if __name__ == '__main__': + unittest.main() From bf282982ab6fb2f5e1eccc7fc5676833fea97ec0 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Thu, 27 Apr 2023 13:51:06 -0400 Subject: [PATCH 4/5] Added system tests to coverage. --- run_coverage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run_coverage.sh b/run_coverage.sh index b566b0e3..718b4211 100755 --- a/run_coverage.sh +++ b/run_coverage.sh @@ -4,4 +4,5 @@ coverage run --source=spatialpy test/run_unit_tests.py -m develop coverage run --source=spatialpy test/run_integration_tests.py -m develop +coverage run --source=spatialpy test/run_system_tests.py -m develop coverage html From 18b043a3f4fe1af88ea06b0fb75c310bd6b0abc5 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Thu, 27 Apr 2023 14:09:54 -0400 Subject: [PATCH 5/5] Pylint updates. --- test/run_integration_tests.py | 14 ++++++++------ test/run_system_tests.py | 3 ++- test/system_tests/test_compiler.py | 5 ++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/run_integration_tests.py b/test/run_integration_tests.py index fe33b21a..0360b12f 100644 --- a/test/run_integration_tests.py +++ b/test/run_integration_tests.py @@ -14,8 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - -import unittest, sys, os +''' Testing suite for integration tests. ''' +import os +import sys +import unittest import argparse parser = argparse.ArgumentParser() @@ -28,9 +30,9 @@ print('Running tests in develop mode. Appending repository directory to system path.') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - from integration_tests import test_model - from integration_tests import test_solver - #from integration_tests import test_mincde + from test.integration_tests import test_model + from test.integration_tests import test_solver + #from test.integration_tests import test_mincde modules = [ test_model, @@ -42,7 +44,7 @@ suite = unittest.TestLoader().loadTestsFromModule(module) runner = unittest.TextTestRunner(failfast=args.mode == 'develop') - print("Executing: {}".format(module)) + print(f"Executing: {module}") result = runner.run(suite) print('=' * 70) if not result.wasSuccessful(): diff --git a/test/run_system_tests.py b/test/run_system_tests.py index 7a550bfe..fbbee335 100644 --- a/test/run_system_tests.py +++ b/test/run_system_tests.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +''' Testing suite for system tests. ''' import os import sys import unittest @@ -29,7 +30,7 @@ print('Running system tests in develop mode. Appending repository directory to system path.') sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - from system_tests import test_compiler + from test.system_tests import test_compiler modules = [ test_compiler diff --git a/test/system_tests/test_compiler.py b/test/system_tests/test_compiler.py index 4b37c57e..3e6bdf78 100755 --- a/test/system_tests/test_compiler.py +++ b/test/system_tests/test_compiler.py @@ -17,11 +17,10 @@ ''' Tests from the compiler. ''' import os import sys -print(os.getcwd()) -sys.path.insert(1, os.path.abspath(os.getcwd())) import unittest -from test.models.birth_death import create_birth_death +sys.path.insert(1, os.path.abspath(os.getcwd())) +from test.models.birth_death import create_birth_death # pylint: disable=wrong-import-position class TestCompiler(unittest.TestCase): '''