'C': equipment.SynchronousMachineSinglePhase(mrid='1', name='mach1', phase='B', controllable=True, p=-38.67891, q=18.12342, rated_s=100000), } } with self.assertLogs(logger=app.LOG, level='ERROR'): app._update_diesel_dg_state_in_glm(glm_mgr=mgr, machines=mach1) @unittest.skipIf(not utils.gld_installed(), reason='GridLAB-D is not installed.') @unittest.skipIf(not DB_ENVIRON_PRESENT, reason='Database environment variables are not present.') class AllGLMModificationsRunTestCase(unittest.TestCase): """Test running the 9500 node model after making the modifications made in app.py as well as ga.py. """ @classmethod def setUpClass(cls): # Initialize inverters and switches. inverter_df = _df.read_pickle(_df.INVERTERS_9500) inverters = equipment.initialize_inverters(inverter_df) inverter_meas = _df.read_pickle(_df.INVERTER_MEAS_9500) inverter_mgr = equipment.PQEquipmentManager( eq_dict=inverters,
from pyvvo import zip from pyvvo import glm from pyvvo import utils import pandas as pd import numpy as np import os import math from scipy.optimize import OptimizeResult # BAD PRACTICE: file dependencies across tests. from tests.test_utils import TEST_ZIP1 # Get model directory. from tests.models import MODEL_DIR # Determine if GridLAB-D is at our disposal GLD_PRESENT = utils.gld_installed() TEST_FILE = os.path.join(MODEL_DIR, 'test_zip.glm') # Define tolerances for using numpy's isclose function. Use different # tolerances for P and Q. These values are the maximum relative # differences found for the TestZipFitSLSQPAlt test case. # R_TOL_P = 0.047 R_TOL_P = 0.012 # R_TOL_Q = 0.03 R_TOL_Q = 0.011 A_TOL = 0 # More tolerances, but same tolerance for P and Q. This will be used for # comparing GridLAB-D and zip_model for the same parameters. R_TOL = 0.001
def test_gld_installed_simple(self): """Simply put, GridLAB-D should be installed in the docker container, so should always evaluate to True. """ self.assertTrue(utils.gld_installed(env=None))
def test_gld_installed_bad_path(self): """Override the path so we can't find GridLAB-D.""" self.assertFalse(utils.gld_installed(env={'PATH': '/usr/bin'}))
class GLDInstalledTestCase(unittest.TestCase): """Test gld_installed.""" def test_gld_installed_simple(self): """Simply put, GridLAB-D should be installed in the docker container, so should always evaluate to True. """ self.assertTrue(utils.gld_installed(env=None)) def test_gld_installed_bad_path(self): """Override the path so we can't find GridLAB-D.""" self.assertFalse(utils.gld_installed(env={'PATH': '/usr/bin'})) @unittest.skipUnless(utils.gld_installed(), reason='GridLAB-D is not installed.') class RunGLDTestCase(unittest.TestCase): """Test run_gld.""" def test_run_gld_simple(self): """Ensure the model runs.""" result = utils.run_gld(TEST_GLM2) self.assertEqual(0, result.returncode) def test_run_gld_bad_model(self): result = utils.run_gld(os.path.join(MODEL_DIR, 'nonexistent.glm')) self.assertNotEqual(0, result.returncode) def test_run_gld_bad_dir(self): with self.assertRaises(FileNotFoundError): utils.run_gld('/some/bad/path.glm')