def test_errors(self): data = { "buildings": { "default": { "load_model": "rc", "load_model_parameters": { "rc": { "order": 6 } }, } } } with self.assertRaises(Exception) as exc: SystemParameters.loadd(data) self.assertRegex(str(exc.exception), "Invalid system parameter file.*") sp = SystemParameters.loadd(data, validate_on_load=False) self.assertEqual(len(sp.validate()), 6) self.assertIn("'fraction_latent_person' is a required property", sp.validate()) self.assertIn("'mos_weather_filename' is a required property", sp.validate()) self.assertIn("'temp_hw_supply' is a required property", sp.validate()) self.assertIn("'temp_setpoint_cooling' is a required property", sp.validate()) self.assertIn("'temp_setpoint_heating' is a required property", sp.validate()) self.assertIn("6 is not one of [1, 2, 3, 4]", sp.validate())
def test_get_param_with_default(self): data = {"buildings": {"default": {"load_model": "Spawn"}}} sp = SystemParameters.loadd(data) value = sp.get_param( "buildings.default.load_model_parameters.rc.order", default=2) self.assertEqual(value, 2) value = sp.get_param("not.a.real.path", default=2) self.assertEqual(value, 2)
def test_get_param_with_default(self): data = {"buildings": {"default": {"load_model": "spawn"}}} sp = SystemParameters.loadd(data) # this path doesn't exist, but there is a default value = sp.get_param( "buildings.default.load_model_parameters.rc.order", default=2) self.assertEqual(2, value) value = sp.get_param("not.a.real.path", default=2) self.assertEqual(2, value)
def test_errors(self): data = { "buildings": { "default": { "load_model": "ROM/RC", "load_model_parameters": { "rc": { "order": 6 } }, } } } with self.assertRaises(Exception) as exc: SystemParameters.loadd(data) self.assertRegex(str(exc.exception), "Invalid system parameter file.*") sp = SystemParameters.loadd(data, validate_on_load=False) self.assertEqual(sp.validate()[0], "6 is not one of [1, 2, 3, 4]")
def test_get_param(self): data = { "buildings": { "default": { "load_model": "rc", "load_model_parameters": { "rc": { "order": 4, "mos_weather_filename": "path-to-file", "fraction_latent_person": 1.25, "temp_hw_supply": 40, "temp_setpoint_heating": 40, "temp_setpoint_cooling": 24 } }, } } } sp = SystemParameters.loadd(data) # $.buildings.*[?load_model=spawn].load_model_parameters.spawn.idf_filename value = sp.get_param( "$.buildings.default.load_model_parameters.rc.order") self.assertEqual(value, 4) value = sp.get_param("buildings.default.load_model") self.assertEqual(value, "rc") value = sp.get_param("buildings.default") self.assertDictEqual( value, { "load_model": "rc", "load_model_parameters": { "rc": { "order": 4, "mos_weather_filename": "path-to-file", "fraction_latent_person": 1.25, "temp_hw_supply": 40, "temp_setpoint_heating": 40, "temp_setpoint_cooling": 24 } } }) value = sp.get_param("") self.assertIsNone(value) value = sp.get_param("not.a.real.path") self.assertIsNone(value)
def test_get_param(self): data = { "buildings": { "default": { "load_model": "ROM/RC", "load_model_parameters": { "rc": { "order": 4 } }, } } } sp = SystemParameters.loadd(data) value = sp.get_param( "buildings.default.load_model_parameters.rc.order") self.assertEqual(value, 4) value = sp.get_param("buildings.default.load_model") self.assertEqual(value, "ROM/RC") value = sp.get_param("buildings.default") self.assertDictEqual( value, { "load_model": "ROM/RC", "load_model_parameters": { "rc": { "order": 4 } } }, ) value = sp.get_param("") self.assertIsNone(value) value = sp.get_param("not.a.real.path") self.assertIsNone(value)
def test_to_modelica_rc_order_4(self): self.results_path = os.path.abspath("tests/output/rc_order_4") if os.path.exists(self.results_path): shutil.rmtree(self.results_path) filename = os.path.abspath("tests/geojson/data/geojson_1.json") gj = GeoJsonModelicaTranslator.from_geojson(filename) sys_params = SystemParameters.loadd({ "buildings": { "default": { "load_model_parameters": { "rc": { "order": 4 } } } } }) self.assertEqual(len(sys_params.validate()), 0) gj.set_system_parameters(sys_params) gj.to_modelica("rc_order_4", "tests/output") # setup what we are going to check model_names = [ "Floor", "ICT", "Meeting", "Office", "package", "Restroom", "Storage", ] building_paths = [ os.path.join(gj.scaffold.loads_path.files_dir, b.dirname) for b in gj.buildings ] path_checks = [ f"{os.path.sep.join(r)}.mo" for r in itertools.product(building_paths, model_names) ] for p in path_checks: self.assertTrue(os.path.exists(p), f"Path not found: {p}") resource_names = [ "InternalGains_Floor", "InternalGains_ICT", "InternalGains_Meeting", "InternalGains_Office", "InternalGains_Restroom", "InternalGains_Storage", ] for b in gj.buildings: for resource_name in resource_names: # TEASER 0.7.2 used .txt for schedule files path = os.path.join( gj.scaffold.loads_path.files_dir, "Resources", "Data", b.dirname, f"{resource_name}.txt", ) self.assertTrue(os.path.exists(path), f"Path not found: {path}")