From 11c3833f781b1076e57c4a2325833ac1dcb1b7b2 Mon Sep 17 00:00:00 2001 From: jinningwang Date: Thu, 14 Nov 2024 22:57:43 -0500 Subject: [PATCH] Add tests on module omodel --- tests/test_omodel.py | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_omodel.py diff --git a/tests/test_omodel.py b/tests/test_omodel.py new file mode 100644 index 00000000..48d24cad --- /dev/null +++ b/tests/test_omodel.py @@ -0,0 +1,64 @@ +import unittest + +import ams + + +class TestOModelWrappers(unittest.TestCase): + """ + Test wrappers in module `omodel`. + """ + + def setUp(self) -> None: + self.ss = ams.load(ams.get_case("matpower/case5.m"), + setup=True, + default_config=True, + no_output=True, + ) + + def test_ensure_symbols(self): + """ + Test `ensure_symbols` wrapper. + """ + self.assertFalse(self.ss.DCOPF._syms, "Symbols should not be ready before generation!") + self.ss.DCOPF.pd.parse() + self.assertTrue(self.ss.DCOPF._syms, "Symbols should be ready after generation!") + + def test_ensure_mats_and_parsed(self): + """ + Test `ensure_mats_and_parsed` wrapper. + """ + self.assertFalse(self.ss.mats.initialized, "MatProcessor should not be initialized before initialization!") + self.assertFalse(self.ss.DCOPF.om.parsed, "OModel should be parsed after parsing!") + self.ss.DCOPF.pd.evaluate() + self.assertTrue(self.ss.mats.initialized, "MatProcessor should be initialized after parsing!") + self.assertTrue(self.ss.DCOPF.om.parsed, "OModle should be parsed after parsing!") + + +class TestOModel(unittest.TestCase): + """ + Test class `OModel`. + """ + + def setUp(self) -> None: + self.ss = ams.load(ams.get_case("matpower/case5.m"), + setup=True, + default_config=True, + no_output=True, + ) + + def test_initialized(self): + """ + Test `OModel` initialization. + """ + self.assertFalse(self.ss.DCOPF.om.initialized, "OModel shoud not be initialized before initialziation!") + self.ss.DCOPF.om.init() + self.assertTrue(self.ss.DCOPF.om.initialized, "OModel should be initialized!") + + def test_uninitialized_after_nonparametric_update(self): + """ + Test `OModel` initialization after nonparametric update. + """ + self.ss.DCOPF.om.init() + self.assertTrue(self.ss.DCOPF.om.initialized, "OModel should be initialized after initialization!") + self.ss.DCOPF.update('ug') + self.assertTrue(self.ss.DCOPF.om.initialized, "OModel should be initialized after nonparametric update!")