Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unittest to pytest #192

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:

- name: Test
run: |
python -m unittest discover -s tests
pytest tests -m "not slow" --durations=0
schmoelder marked this conversation as resolved.
Show resolved Hide resolved

- name: Install pypa/build
run: |
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ docs = [
"sphinx_copybutton>=0.5.1",
"sphinx-sitemap>=2.5.0",
]

ax = [
"ax-platform >=0.3.5"
]
Expand All @@ -78,3 +77,9 @@ line-length = 88
testpaths = [
"tests",
]
pythonpath = [
"tests",
schmoelder marked this conversation as resolved.
Show resolved Hide resolved
]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
]
3 changes: 3 additions & 0 deletions tests/optimization_problem_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def allow_test_failure_percentage(


class TestProblem(OptimizationProblem):
# To prevent Pytest interpreting this class as test:
__test__ = False

@property
def optimal_solution(self):
"""Must return X, F, and if it has, G."""
Expand Down
3 changes: 0 additions & 3 deletions tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

class Test_Binding(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):

component_system = ComponentSystem(2)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_buffer_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

class TestBufferCapacity(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.components_simple = ComponentSystem(2, charges=[1, 2])

Expand Down
2 changes: 0 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@


class TestCache(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.cache_dict = ResultsCache(use_diskcache=False)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_cadet_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def detect_cadet(install_path: Optional[Path] = None):

class Test_Adapter(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

@unittest.skipIf(found_cadet is False, "Skip if CADET is not installed.")
def test_check_cadet(self):
simulator = Cadet(install_path)
Expand Down Expand Up @@ -155,6 +152,7 @@ def simulation_results(request: pytest.FixtureRequest):
return simulation_results

@pytest.mark.parametrize("process", test_cases, indirect=True)
@pytest.mark.slow
class TestProcessWithLWE:

def return_process_config(self, process: Process) -> dict:
Expand Down Expand Up @@ -566,6 +564,7 @@ def test_sensitivity_config(self, process: Process):


@pytest.mark.parametrize("simulation_results", test_cases, indirect=True)
@pytest.mark.slow
class TestResultsWithLWE:
def test_trigger_simulation(self, simulation_results):
"""
Expand Down
3 changes: 0 additions & 3 deletions tests/test_carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

class Test_Carousel(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(2)

Expand Down
3 changes: 0 additions & 3 deletions tests/test_compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class Test_CompartmentBuilder(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(2)

Expand Down
12 changes: 0 additions & 12 deletions tests/test_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

from CADETProcess.comparison import SSE
class TestSSE(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def test_metric(self):
# Compare with itself
Expand Down Expand Up @@ -76,8 +74,6 @@ def test_metric(self):

from CADETProcess.comparison import NRMSE
class TestNRMSE(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def test_metric(self):
# Compare with itself
Expand Down Expand Up @@ -112,8 +108,6 @@ def test_metric(self):

from CADETProcess.comparison import PeakHeight
class TestPeakHeight(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
# 2 Components, gaussian peaks, constant flow
Expand Down Expand Up @@ -202,8 +196,6 @@ def test_metric(self):

from CADETProcess.comparison import PeakPosition
class TestPeakPosition(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
# 2 Components, gaussian peaks, constant flow
Expand Down Expand Up @@ -275,8 +267,6 @@ def test_metric(self):

from CADETProcess.comparison import Shape
class TestShape(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
# 2 Components, gaussian peaks, constant flow
Expand Down Expand Up @@ -396,8 +386,6 @@ def test_metric(self):


class TestFractionation(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
fraction_1 = Fraction(
Expand Down
4 changes: 0 additions & 4 deletions tests/test_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@


class TestReactionEquilibrium(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
component_system = ComponentSystem(2)
Expand Down Expand Up @@ -171,8 +169,6 @@ def test_reaction_equilibrium(self):


class TestAdsorptionEquilibrium(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
component_system_mono = ComponentSystem()
Expand Down
17 changes: 8 additions & 9 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Notes
-----
Since the EventHandler defines an interface, that requires the
implementation of some methods, a TestHandler class is defined.
implementation of some methods, a HandlerFixture class is defined.

Maybe this is too complicated, just use Process instead?
"""
Expand All @@ -31,7 +31,8 @@
plot = True


class TestPerformer(Structure):
class PerformerFixture(Structure):

n_entries = 4
n_coeff = 4

Expand Down Expand Up @@ -79,10 +80,11 @@ def section_dependent_parameters(self):
return parameters


class TestHandler(CADETProcess.dynamicEvents.EventHandler):
class HandlerFixture(CADETProcess.dynamicEvents.EventHandler):

def __init__(self):
self.name = None
self.performer = TestPerformer()
self.performer = PerformerFixture()
super().__init__()

@property
Expand All @@ -100,7 +102,7 @@ def parameters(self, parameters):
except KeyError:
pass

super(TestHandler, self.__class__).parameters.fset(self, parameters)
super(HandlerFixture, self.__class__).parameters.fset(self, parameters)

@property
def section_dependent_parameters(self):
Expand All @@ -117,11 +119,8 @@ def polynomial_parameters(self):

class Test_Events(unittest.TestCase):

def __init__(self, methodName='runTest'):
daklauss marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(methodName)

def setup_event_handler(self, add_events=False):
event_handler = TestHandler()
event_handler = HandlerFixture()
event_handler.cycle_time = 20

if add_events:
Expand Down
16 changes: 0 additions & 16 deletions tests/test_flow_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ def setup_ssr_flow_sheet(component_system=None):
class TestFlowSheet(unittest.TestCase):
"""Test general functionatlity of `FlowSheet` class."""

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(2)

Expand Down Expand Up @@ -995,9 +992,6 @@ class TestCstrFlowRate(unittest.TestCase):
is set, it has properties similar to an `Inlet`.
"""

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(2)

Expand Down Expand Up @@ -1100,8 +1094,6 @@ def test_state_update(self):
np.testing.assert_almost_equal(cstr_out, cstr_out_expected)

class TestPorts(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.setup_mct_flow_sheet()
Expand Down Expand Up @@ -1561,9 +1553,6 @@ def test_set_output_state(self):
class TestFlowRateMatrix(unittest.TestCase):
"""Test calculation of flow rates with another simple testcase by @daklauss"""

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(1)

Expand Down Expand Up @@ -1698,8 +1687,6 @@ def test_matrix_example(self):

class TestFlowRateSelfMatrix(unittest.TestCase):
"""Test special case where one unit is connected to itself."""
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
self.component_system = ComponentSystem(1)
Expand Down Expand Up @@ -1794,9 +1781,6 @@ class TestSingularFlowMatrix(unittest.TestCase):

"""

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):

self.component_system = ComponentSystem(1)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

class Test_Fractions(unittest.TestCase):

def __init__(self, methodName='runTest'):
super().__init__(methodName)

def create_fractions(self):
m_0 = np.array([0, 0])
frac0 = CADETProcess.fractionation.Fraction(m_0, 1)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def test_hash_array(self):


class TestIndividual(unittest.TestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName)

def setUp(self):
x = [1, 2]
f = [-1]
Expand Down
Loading
Loading