From d5628d2700fd60da3674b1b58770939fb7266949 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Mon, 5 Apr 2021 11:44:12 -0700 Subject: [PATCH 1/2] test: add test for Scenario init with bad descriptor --- powersimdata/scenario/tests/test_scenario.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 powersimdata/scenario/tests/test_scenario.py diff --git a/powersimdata/scenario/tests/test_scenario.py b/powersimdata/scenario/tests/test_scenario.py new file mode 100644 index 000000000..393b590ee --- /dev/null +++ b/powersimdata/scenario/tests/test_scenario.py @@ -0,0 +1,10 @@ +import pytest + +from powersimdata.scenario.scenario import Scenario + + +@pytest.mark.ssh +def test_bad_scenario_name(): + # This test will fail if we do add a scenario with this name + with pytest.raises(ValueError): + Scenario("this_scenario_does_not_exist") From 36b0f69f02344ef5b9e2301dc8391c516fb6dc45 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Mon, 5 Apr 2021 11:44:38 -0700 Subject: [PATCH 2/2] fix: correct bug for Scenario init with bad descriptor --- powersimdata/scenario/scenario.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/powersimdata/scenario/scenario.py b/powersimdata/scenario/scenario.py index 6bb07db1a..3181a1491 100644 --- a/powersimdata/scenario/scenario.py +++ b/powersimdata/scenario/scenario.py @@ -85,8 +85,12 @@ def _set_info(self, descriptor): :param str descriptor: scenario descriptor. """ info = self._scenario_list_manager.get_scenario(descriptor) - if info is not None: - self.info = info + if info is None: + raise ValueError( + f"{descriptor} not found in Scenario List. " + "See available scenarios with Scenario().get_scenario_table()" + ) + self.info = info def _set_status(self): """Sets execution status of scenario."""