Skip to content

Adds tests exercising validators - #128

Merged
mikejturner merged 39 commits into
mainfrom
node-tests
Sep 29, 2026
Merged

mikejturner merged 39 commits into
mainfrom
node-tests

Conversation

@mikejturner

Copy link
Copy Markdown
Contributor

Adds tests exercising validators for

  • Node (and subclasses)
  • Edge, Window
  • Demand charges
  • Objective (and subclasses)

Relevant tests for Port and it's subclasses have all been handled.

Note: These unit tests on focus of validators and object instantiation (initialisation) and not any other methods on these classes.

@mikejturner

Copy link
Copy Markdown
Contributor Author

✅ Code coverage on node-tests is at 84% (compared to main being at 82%)

🎉 No files have reduced coverage 🎉

Full Coverage Report

File Details
src/echo/__init__.py ✅ 100% → 100%
src/echo/configuration.py ✅ 100% → 100%
src/echo/constants.py ✅ 100% → 100%
src/echo/exceptions.py ✅ 100% → 100%
src/echo/functional.py ✅ 100% → 100%
src/echo/models/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/aggregation.py ✅ 95% → 95%
src/echo/models/agnostic/base.py ✅ 94% → 94%
src/echo/models/agnostic/bounded.py ✅ 100% → 100%
src/echo/models/agnostic/controlled.py ✅ 100% → 100%
src/echo/models/agnostic/flex.py ✅ 100% → 100%
src/echo/models/agnostic/input_output.py ✅ 100% → 100%
src/echo/models/agnostic/storage.py ✅ 83% → 83%
src/echo/models/agnostic/tellegen/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/base.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/multi_commodity.py ✅ 38% → 38%
src/echo/models/agnostic/tellegen/partitioned_multi_commodity.py ✅ 96% → 96%
src/echo/models/agnostic/tellegen/three_way_valve.py ✅ 90% → 90%
src/echo/models/agnostic/time_delay.py ✅ 100% → 100%
src/echo/models/agnostic/time_varying.py ✅ 76% → 76%
src/echo/models/base/__init__.py ✅ 100% → 100%
src/echo/models/base/base_model.py ✅ 100% → 100%
src/echo/models/base/edge.py ✅ 69% → 69%
src/echo/models/base/node.py ✅ 98% → 98%
src/echo/models/base/optimisation_graph.py ✅ 76% → 76%
src/echo/models/base/path.py ✅ 92% → 92%
src/echo/models/base/port.py ✅ 98% → 98%
src/echo/models/base/transform.py ✅ 90% → 90%
src/echo/models/base/types.py ✅ 100% → 100%
src/echo/models/carbon/__init__.py ✅ 100% → 100%
src/echo/models/carbon/aggregation.py ✅ 100% → 100%
src/echo/models/carbon/base.py ✅ 100% → 100%
src/echo/models/electrical/__init__.py ✅ 100% → 100%
src/echo/models/electrical/base.py ✅ 100% → 100%
src/echo/models/electrical/ev/__init__.py ✅ 100% → 100%
src/echo/models/electrical/ev/base.py ✅ 94% → 94%
src/echo/models/electrical/ev/deprecated.py ✅ 33% → 33%
src/echo/models/electrical/ev/ev_with_profile.py ✅ 68% → 73%
src/echo/models/electrical/ev/v0g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v1g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v2g.py ✅ 100% → 100%
src/echo/models/electrical/generation.py ✅ 94% → 94%
src/echo/models/electrical/inverter.py ✅ 92% → 92%
src/echo/models/gas/__init__.py ✅ 100% → 100%
src/echo/models/gas/base.py ✅ 100% → 100%
src/echo/models/gas/boiler_fixedcop.py ✅ 86% → 86%
src/echo/models/gas/boiler_tempcontrolled.py ✅ 62% → 74%
src/echo/models/prebuilt/__init__.py ✅ 100% → 100%
src/echo/models/prebuilt/battery.py ✅ 71% → 71%
src/echo/models/prebuilt/diesel_generator.py ✅ 45% → 58%
src/echo/models/prebuilt/flex.py ✅ 79% → 79%
src/echo/models/prebuilt/load.py ✅ 91% → 91%
src/echo/models/prebuilt/scaled_solar.py ✅ 67% → 67%
src/echo/models/prebuilt/solar.py ✅ 50% → 50%
src/echo/models/scenario.py ✅ 100% → 100%
src/echo/models/thermal/__init__.py ✅ 100% → 100%
src/echo/models/thermal/base.py ✅ 0% → 49%
src/echo/models/thermal/parameterised_chiller.py ✅ 85% → 85%
src/echo/models/thermal/parameterised_heatpump.py ✅ 88% → 88%
src/echo/models/thermal/simple_chiller.py ✅ 85% → 88%
src/echo/models/thermal/simple_heatpump.py ✅ 92% → 92%
src/echo/models/thermal/simple_heatpump_dualoutput.py ✅ 92% → 92%
src/echo/models/thermal/storage.py ✅ 78% → 82%
src/echo/objectives/__init__.py ✅ 100% → 100%
src/echo/objectives/base.py ✅ 98% → 98%
src/echo/objectives/contingency.py ✅ 93% → 93%
src/echo/objectives/power.py ✅ 86% → 86%
src/echo/objectives/tariff.py ✅ 80% → 85%
src/echo/optimiser.py ✅ 73% → 73%
src/echo/tracker.py ✅ 43% → 43%
src/echo/utils.py ✅ 61% → 61%
src/echo/validators.py ✅ 94% → 95%
src/echo/visualization.py ✅ 91% → 91%
TOTAL ✅ 82% → 84%

1 similar comment
@mikejturner

Copy link
Copy Markdown
Contributor Author

✅ Code coverage on node-tests is at 84% (compared to main being at 82%)

🎉 No files have reduced coverage 🎉

Full Coverage Report

File Details
src/echo/__init__.py ✅ 100% → 100%
src/echo/configuration.py ✅ 100% → 100%
src/echo/constants.py ✅ 100% → 100%
src/echo/exceptions.py ✅ 100% → 100%
src/echo/functional.py ✅ 100% → 100%
src/echo/models/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/aggregation.py ✅ 95% → 95%
src/echo/models/agnostic/base.py ✅ 94% → 94%
src/echo/models/agnostic/bounded.py ✅ 100% → 100%
src/echo/models/agnostic/controlled.py ✅ 100% → 100%
src/echo/models/agnostic/flex.py ✅ 100% → 100%
src/echo/models/agnostic/input_output.py ✅ 100% → 100%
src/echo/models/agnostic/storage.py ✅ 83% → 83%
src/echo/models/agnostic/tellegen/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/base.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/multi_commodity.py ✅ 38% → 38%
src/echo/models/agnostic/tellegen/partitioned_multi_commodity.py ✅ 96% → 96%
src/echo/models/agnostic/tellegen/three_way_valve.py ✅ 90% → 90%
src/echo/models/agnostic/time_delay.py ✅ 100% → 100%
src/echo/models/agnostic/time_varying.py ✅ 76% → 76%
src/echo/models/base/__init__.py ✅ 100% → 100%
src/echo/models/base/base_model.py ✅ 100% → 100%
src/echo/models/base/edge.py ✅ 69% → 69%
src/echo/models/base/node.py ✅ 98% → 98%
src/echo/models/base/optimisation_graph.py ✅ 76% → 76%
src/echo/models/base/path.py ✅ 92% → 92%
src/echo/models/base/port.py ✅ 98% → 98%
src/echo/models/base/transform.py ✅ 90% → 90%
src/echo/models/base/types.py ✅ 100% → 100%
src/echo/models/carbon/__init__.py ✅ 100% → 100%
src/echo/models/carbon/aggregation.py ✅ 100% → 100%
src/echo/models/carbon/base.py ✅ 100% → 100%
src/echo/models/electrical/__init__.py ✅ 100% → 100%
src/echo/models/electrical/base.py ✅ 100% → 100%
src/echo/models/electrical/ev/__init__.py ✅ 100% → 100%
src/echo/models/electrical/ev/base.py ✅ 94% → 94%
src/echo/models/electrical/ev/deprecated.py ✅ 33% → 33%
src/echo/models/electrical/ev/ev_with_profile.py ✅ 68% → 73%
src/echo/models/electrical/ev/v0g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v1g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v2g.py ✅ 100% → 100%
src/echo/models/electrical/generation.py ✅ 94% → 94%
src/echo/models/electrical/inverter.py ✅ 92% → 92%
src/echo/models/gas/__init__.py ✅ 100% → 100%
src/echo/models/gas/base.py ✅ 100% → 100%
src/echo/models/gas/boiler_fixedcop.py ✅ 86% → 86%
src/echo/models/gas/boiler_tempcontrolled.py ✅ 62% → 74%
src/echo/models/prebuilt/__init__.py ✅ 100% → 100%
src/echo/models/prebuilt/battery.py ✅ 71% → 71%
src/echo/models/prebuilt/diesel_generator.py ✅ 45% → 58%
src/echo/models/prebuilt/flex.py ✅ 79% → 79%
src/echo/models/prebuilt/load.py ✅ 91% → 91%
src/echo/models/prebuilt/scaled_solar.py ✅ 67% → 67%
src/echo/models/prebuilt/solar.py ✅ 50% → 50%
src/echo/models/scenario.py ✅ 100% → 100%
src/echo/models/thermal/__init__.py ✅ 100% → 100%
src/echo/models/thermal/base.py ✅ 0% → 49%
src/echo/models/thermal/parameterised_chiller.py ✅ 85% → 85%
src/echo/models/thermal/parameterised_heatpump.py ✅ 88% → 88%
src/echo/models/thermal/simple_chiller.py ✅ 85% → 88%
src/echo/models/thermal/simple_heatpump.py ✅ 92% → 92%
src/echo/models/thermal/simple_heatpump_dualoutput.py ✅ 92% → 92%
src/echo/models/thermal/storage.py ✅ 78% → 82%
src/echo/objectives/__init__.py ✅ 100% → 100%
src/echo/objectives/base.py ✅ 98% → 98%
src/echo/objectives/contingency.py ✅ 93% → 93%
src/echo/objectives/power.py ✅ 86% → 86%
src/echo/objectives/tariff.py ✅ 80% → 85%
src/echo/optimiser.py ✅ 73% → 73%
src/echo/tracker.py ✅ 43% → 43%
src/echo/utils.py ✅ 61% → 61%
src/echo/validators.py ✅ 94% → 95%
src/echo/visualization.py ✅ 91% → 91%
TOTAL ✅ 82% → 84%

@explodingdinosaurs explodingdinosaurs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three very small comments/questions, but happy to merge.

node.ports = ports

# This should raise an error due to mixing of different units on ports
# with pytest.raises(ConfigurationError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this commented out code block be removed? Or is it a placeholder for something to be tested in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder for the future

# }
# if expected_error:
# with pytest.raises(ValidationError):
# with pytest.raises(expected_error):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this commented out code or keep it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a placeholder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should work. There is an Issue in github and the comment above the test links to that issue to be as clear as possible.

"reset_periods,expected_reset_index",
[
([], en.RangeSet(0, -1)), # TODO this passes but a negative index is probably not correct
(list(range(1)), en.RangeSet(0, 1 - 1)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the 1 - 1 (as opposed to using 0) due to some weird quirk of RangeSet?

@mikejturner mikejturner Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lefthand values should match the value passed to range i.e. 1.
It is probably a bit more obvious what I was going for in the other test cases. I'm happy to change it if you think it's all a bit too confusing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. Thank you. I reckon keep as is

@mikejturner

Copy link
Copy Markdown
Contributor Author

✅ Code coverage on node-tests is at 84% (compared to main being at 82%)

🎉 No files have reduced coverage 🎉

Full Coverage Report

File Details
src/echo/__init__.py ✅ 100% → 100%
src/echo/configuration.py ✅ 100% → 100%
src/echo/constants.py ✅ 100% → 100%
src/echo/exceptions.py ✅ 100% → 100%
src/echo/functional.py ✅ 100% → 100%
src/echo/models/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/aggregation.py ✅ 95% → 95%
src/echo/models/agnostic/base.py ✅ 94% → 94%
src/echo/models/agnostic/bounded.py ✅ 100% → 100%
src/echo/models/agnostic/controlled.py ✅ 100% → 100%
src/echo/models/agnostic/flex.py ✅ 100% → 100%
src/echo/models/agnostic/input_output.py ✅ 100% → 100%
src/echo/models/agnostic/storage.py ✅ 83% → 83%
src/echo/models/agnostic/tellegen/__init__.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/base.py ✅ 100% → 100%
src/echo/models/agnostic/tellegen/multi_commodity.py ✅ 38% → 38%
src/echo/models/agnostic/tellegen/partitioned_multi_commodity.py ✅ 96% → 96%
src/echo/models/agnostic/tellegen/three_way_valve.py ✅ 90% → 90%
src/echo/models/agnostic/time_delay.py ✅ 100% → 100%
src/echo/models/agnostic/time_varying.py ✅ 76% → 76%
src/echo/models/base/__init__.py ✅ 100% → 100%
src/echo/models/base/base_model.py ✅ 100% → 100%
src/echo/models/base/edge.py ✅ 69% → 69%
src/echo/models/base/node.py ✅ 98% → 98%
src/echo/models/base/optimisation_graph.py ✅ 76% → 76%
src/echo/models/base/path.py ✅ 92% → 92%
src/echo/models/base/port.py ✅ 98% → 98%
src/echo/models/base/transform.py ✅ 90% → 90%
src/echo/models/base/types.py ✅ 100% → 100%
src/echo/models/carbon/__init__.py ✅ 100% → 100%
src/echo/models/carbon/aggregation.py ✅ 100% → 100%
src/echo/models/carbon/base.py ✅ 100% → 100%
src/echo/models/electrical/__init__.py ✅ 100% → 100%
src/echo/models/electrical/base.py ✅ 100% → 100%
src/echo/models/electrical/ev/__init__.py ✅ 100% → 100%
src/echo/models/electrical/ev/base.py ✅ 94% → 94%
src/echo/models/electrical/ev/deprecated.py ✅ 33% → 33%
src/echo/models/electrical/ev/ev_with_profile.py ✅ 68% → 73%
src/echo/models/electrical/ev/v0g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v1g.py ✅ 100% → 100%
src/echo/models/electrical/ev/v2g.py ✅ 100% → 100%
src/echo/models/electrical/generation.py ✅ 94% → 94%
src/echo/models/electrical/inverter.py ✅ 92% → 92%
src/echo/models/gas/__init__.py ✅ 100% → 100%
src/echo/models/gas/base.py ✅ 100% → 100%
src/echo/models/gas/boiler_fixedcop.py ✅ 86% → 86%
src/echo/models/gas/boiler_tempcontrolled.py ✅ 62% → 74%
src/echo/models/prebuilt/__init__.py ✅ 100% → 100%
src/echo/models/prebuilt/battery.py ✅ 71% → 71%
src/echo/models/prebuilt/diesel_generator.py ✅ 45% → 58%
src/echo/models/prebuilt/flex.py ✅ 79% → 79%
src/echo/models/prebuilt/load.py ✅ 91% → 91%
src/echo/models/prebuilt/scaled_solar.py ✅ 67% → 67%
src/echo/models/prebuilt/solar.py ✅ 50% → 50%
src/echo/models/scenario.py ✅ 100% → 100%
src/echo/models/thermal/__init__.py ✅ 100% → 100%
src/echo/models/thermal/base.py ✅ 0% → 49%
src/echo/models/thermal/parameterised_chiller.py ✅ 85% → 85%
src/echo/models/thermal/parameterised_heatpump.py ✅ 88% → 88%
src/echo/models/thermal/simple_chiller.py ✅ 85% → 88%
src/echo/models/thermal/simple_heatpump.py ✅ 92% → 92%
src/echo/models/thermal/simple_heatpump_dualoutput.py ✅ 92% → 92%
src/echo/models/thermal/storage.py ✅ 78% → 82%
src/echo/objectives/__init__.py ✅ 100% → 100%
src/echo/objectives/base.py ✅ 98% → 98%
src/echo/objectives/contingency.py ✅ 93% → 93%
src/echo/objectives/power.py ✅ 86% → 86%
src/echo/objectives/tariff.py ✅ 80% → 85%
src/echo/optimiser.py ✅ 73% → 73%
src/echo/tracker.py ✅ 43% → 43%
src/echo/utils.py ✅ 61% → 61%
src/echo/validators.py ✅ 94% → 95%
src/echo/visualization.py ✅ 91% → 91%
TOTAL ✅ 82% → 84%

@mikejturner
mikejturner merged commit ff913a6 into main Sep 29, 2026
11 checks passed
@mikejturner
mikejturner deleted the node-tests branch September 29, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants