-
Notifications
You must be signed in to change notification settings - Fork 6
Adding error messags for ps costign when key does not exist #14
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1200,3 +1200,86 @@ def test_fraction_with_custom_total_key(self): | |
| ] | ||
| total = sum(np.asarray(f.data) for f in fracs) | ||
| np.testing.assert_array_almost_equal(total, [100.0, 100.0]) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # _check_discovery_status | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestCheckDiscoveryStatus: | ||
| def test_no_error_when_all_keys_found(self, bgw_dm): | ||
| """When all requested keys match, _check_discovery_status should not raise.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
| g.add_unit("ROUnits", capex_keys=["capital_cost"]) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| cm._discover_keys() | ||
| # Should not raise | ||
| cm._check_discovery_status() | ||
|
|
||
| def test_error_on_unfound_capex_key(self, bgw_dm): | ||
| """A capex key suffix that matches nothing should raise KeyError.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
| g.add_unit("ROUnits", capex_keys=["nonexistent_cost_key"]) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| cm._discover_keys() | ||
| with pytest.raises(KeyError, match="nonexistent_cost_key"): | ||
| cm._check_discovery_status() | ||
|
|
||
| def test_error_on_unfound_fixed_opex_key(self, bgw_dm): | ||
| """A fixed_opex key suffix that matches nothing should raise KeyError.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
| g.add_unit("ROUnits", fixed_opex_keys=["nonexistent_opex"]) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| cm._discover_keys() | ||
| with pytest.raises(KeyError, match="nonexistent_opex"): | ||
| cm._check_discovery_status() | ||
|
|
||
| def test_error_on_unfound_flow_key(self, bgw_dm): | ||
| """A flow key suffix that matches nothing should raise KeyError.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
| g.add_unit( | ||
| "ROUnits", | ||
| flow_keys={"electricity": ["nonexistent_flow"]}, | ||
| ) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| cm._discover_keys() | ||
| with pytest.raises(KeyError, match="nonexistent_flow"): | ||
| cm._check_discovery_status() | ||
|
|
||
| def test_build_raises_on_unfound_key(self, bgw_dm): | ||
| """Full build() should raise KeyError when a requested key is not found.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
| g.add_unit("ROUnits", capex_keys=["capital_cost", "bogus_key"]) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| with pytest.raises(KeyError, match="bogus_key"): | ||
| cm.build() | ||
|
|
||
| def test_mixed_found_and_unfound(self, bgw_dm): | ||
| """Only unfound keys should appear in the error — found ones should not.""" | ||
| pkg = PsCostingPackage() | ||
| g = PsCostingGroup("Membrane") | ||
|
Comment on lines
+1269
to
+1271
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot apply changes based on this feedback
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 7928d04. The test now captures the |
||
| g.add_unit( | ||
| "ROUnits", | ||
| capex_keys=["capital_cost"], | ||
| fixed_opex_keys=["missing_opex_key"], | ||
| ) | ||
|
|
||
| cm = PsCostingManager(bgw_dm, pkg, [g]) | ||
| cm._discover_keys() | ||
| # capital_cost should have been found | ||
| assert len(cm._group_capex_keys["Membrane"]) >= 1 | ||
| # missing_opex_key should be unfound; capital_cost (found) must NOT appear | ||
| with pytest.raises(KeyError, match="missing_opex_key") as exc_info: | ||
| cm._check_discovery_status() | ||
| assert "capital_cost" not in str(exc_info.value) | ||
Uh oh!
There was an error while loading. Please reload this page.