Skip to content

Commit

Permalink
Add tests for all the registries
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsoa committed Nov 30, 2022
1 parent 8e57315 commit 03b64dc
Showing 1 changed file with 94 additions and 27 deletions.
121 changes: 94 additions & 27 deletions tests/test_registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_generic_register():
def solver(*args, **kwargs):
pass

assert "a-solver" in REGISTRY
assert REGISTRY["a-solver"] == solver

with pytest.raises(ValueError):
Expand All @@ -46,53 +45,121 @@ def second_solver(*args, **kwargs):
assert REGISTRY["a-solver"] == second_solver


def test_register_action():
def test_register_action(mocker):
from solcore import registries

@registries.register_action("pre-process")
def pre_process_cell(*args, **kwargs):
mock_gr = mocker.patch("solcore.registries.generic_register")
name = "pre-process"
overwrite = False
reason_to_exclude = None

@registries.register_action(
name, overwrite=overwrite, reason_to_exclude=reason_to_exclude
)
def solver(*args, **kwargs):
pass

assert "pre-process" in registries.ACTIONS_REGISTRY
mock_gr.assert_called_once_with(
name=name,
registrator_name="Action",
registry=registries.ACTIONS_REGISTRY,
signature=registries.ACTIONS_SIGNATURE,
overwrite=overwrite,
reason_to_exclude=reason_to_exclude,
)

with pytest.raises(ValueError):

@registries.register_action("pre-process")
def custom_pre_process_cell(*args, **kwargs):
pass
def test_register_optics(mocker):
from solcore import registries

mock_gr = mocker.patch("solcore.registries.generic_register")
name = "custom_optics"
overwrite = False
reason_to_exclude = None

@registries.register_action("pre-process", overwrite=True)
def another_pre_process_cell(*args, **kwargs):
@registries.register_optics(
name, overwrite=overwrite, reason_to_exclude=reason_to_exclude
)
def solver(*args, **kwargs):
pass

assert registries.ACTIONS_REGISTRY["pre-process"] == another_pre_process_cell
mock_gr.assert_called_once_with(
name=name,
registrator_name="Optics solver",
registry=registries.OPTICS_METHOD_REGISTRY,
signature=registries.OPTICS_METHOD_SIGNATURE,
overwrite=overwrite,
reason_to_exclude=reason_to_exclude,
)


def test_register_optics():
def test_register_short_circuit_solver(mocker):
from solcore import registries

@registries.register_optics("approximate")
def approximate_optics(*args, **kwargs):
mock_gr = mocker.patch("solcore.registries.generic_register")
name = "custom_short_circuit"
overwrite = False
reason_to_exclude = None

@registries.register_short_circuit_solver(
name, overwrite=overwrite, reason_to_exclude=reason_to_exclude
)
def solver(*args, **kwargs):
pass

assert "approximate" in registries.OPTICS_METHOD_REGISTRY
mock_gr.assert_called_once_with(
name=name,
registrator_name="Short circuit solver",
registry=registries.SHORT_CIRCUIT_SOLVER_REGISTRY,
signature=registries.SHORT_CIRCUIT_SOLVER_SIGNATURE,
overwrite=overwrite,
reason_to_exclude=reason_to_exclude,
)

with pytest.raises(ValueError):

@registries.register_optics("approximate")
def custom_approximate_optics(*args, **kwargs):
pass
def test_register_equilibrium_solver(mocker):
from solcore import registries

mock_gr = mocker.patch("solcore.registries.generic_register")
name = "custom_equilibrium"
overwrite = False
reason_to_exclude = None

@registries.register_optics("approximate", overwrite=True)
def another_approximate_optics(*args, **kwargs):
@registries.register_equilibrium_solver(
name, overwrite=overwrite, reason_to_exclude=reason_to_exclude
)
def solver(*args, **kwargs):
pass

assert (
registries.OPTICS_METHOD_REGISTRY["approximate"] == another_approximate_optics
mock_gr.assert_called_once_with(
name=name,
registrator_name="Equilibrium solver",
registry=registries.EQUILIBRIUM_SOLVER_REGISTRY,
signature=registries.EQUILIBRIUM_SOLVER_SIGNATURE,
overwrite=overwrite,
reason_to_exclude=reason_to_exclude,
)

@registries.register_optics("final_approximate", reason_to_exclude="Doesn't work")
def final_approximate_optics(*args, **kwargs):

def test_register_iv_solver(mocker):
from solcore import registries

mock_gr = mocker.patch("solcore.registries.generic_register")
name = "custom_iv_solver"
overwrite = False
reason_to_exclude = None

@registries.register_iv_solver(
name, overwrite=overwrite, reason_to_exclude=reason_to_exclude
)
def solver(*args, **kwargs):
pass

assert "final_approximate" not in registries.OPTICS_METHOD_REGISTRY
mock_gr.assert_called_once_with(
name=name,
registrator_name="IV solver",
registry=registries.IV_SOLVER_REGISTRY,
signature=registries.IV_SOLVER_SIGNATURE,
overwrite=overwrite,
reason_to_exclude=reason_to_exclude,
)

0 comments on commit 03b64dc

Please sign in to comment.