Testing helpers¶
Helpers for testing studies, hooks and plugins without a database or solver.
- class flexorchestrator.testing.FakeModel(spec, overrides=<factory>, solved=False)[source]¶
Bases:
objectWhat
fake_build()returns: the spec and overrides it was given.- solved¶
Set by
fake_solve().- Type:
- flexorchestrator.testing.fake_build(spec, **overrides)[source]¶
Build a
FakeModel.- Parameters:
- Returns:
The fake model.
- Return type:
Example
>>> fake_build({"a": 1}, x=2).overrides {'x': 2}
- flexorchestrator.testing.fake_solve(model, *, status='ok', **options)[source]¶
Pretend to solve, ending however
statussays.- Parameters:
- Returns:
The outcome.
- Raises:
RuntimeError – If
statusis"error".- Return type:
Example
>>> fake_solve(None, status="failed").termination 'infeasible'
- flexorchestrator.testing.memory_orchestrator(*, study='test', plugins=None, hooks=None, **kwargs)[source]¶
Return an orchestrator on a fresh in-memory backend.
- Parameters:
study (str | None) – A study to create and select;
Nonefor none.plugins (Any) – Plugins to load; their orchestrator subclass is built.
FLEXORCH_PLUGINSis ignored, so tests don’t depend on it.hooks (HookSet | None) – The hooks;
FAKE_HOOKSby default.**kwargs (Any) – Passed to the orchestrator.
- Return type:
Example
>>> orch = memory_orchestrator() >>> orch.study 'test'
- flexorchestrator.testing.run_command_in_test(cmd, params=None, *, orch=None, progress=None, **fields)[source]¶
Run a command on a memory orchestrator and return what it returned.
- Parameters:
- Return type:
Example
>>> from flexorchestrator.ext import command >>> @command() ... def ping(orch) -> str: ... return "pong" >>> run_command_in_test(ping) 'pong'
- flexorchestrator.testing.orchestrators.FAKE_HOOKS¶
Build and solve without a model library or a solver.
- Type:
Specs¶
flex-pse specs as plain data, for tests that build a model.
- flexorchestrator.testing.specs.DEMO_SPEC: dict¶
A six-hour version of flex-pse’s
plant_config_demo.json(schema 0.1.1) with a flat energy price instead of a tariff file, so it builds from any working directory.- Type:
- flexorchestrator.testing.specs.LINEAR_POWER: dict¶
A multilinear surrogate for
demo.pump’s power relation: 0.6 kWh/m^3, no offset.- Type:
- flexorchestrator.testing.specs.LOGIC_SPEC: dict¶
Three RO trains as an indexed unit (
p.ro[0..2], over the set elementp.trains = [0, 1, 2]) with status and startup/shutdown logic; 6 points.- Type: