def test_custom_kw_config_construction_with_definition(self): definition = { "VALUE_1": float, "VALUE_2": str } custom_kw_config = CustomKWConfig("TEST", None, definition=definition) self.assertEqual(len(custom_kw_config.getKeys()), 2) self.assertTrue(custom_kw_config.keyIsDouble("VALUE_1")) self.assertFalse(custom_kw_config.keyIsDouble("VALUE_2")) self.assertIn("VALUE_1", custom_kw_config) self.assertIn("VALUE_2", custom_kw_config) self.assertNotIn("VALUE_3", custom_kw_config)
def test_custom_kw_config_creation(self): data = {"VALUE_1": 2345.234, "VALUE_2": 0.001234, "VALUE_3": "string_1", "VALUE_4": "string_2"} with TestAreaContext("python/enkf/data/custom_kw_config") as test_area: self.createResultFile("result_file", data) custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file", "output_file") self.assertEqual(custom_kw_config.getName(), "CUSTOM_KW") self.assertEqual(custom_kw_config.getResultFile(), "result_file") self.assertEqual(custom_kw_config.getOutputFile(), "output_file") self.assertEqual(len(custom_kw_config), 0) result = StringList() success = custom_kw_config.parseResultFile("result_file", result) self.assertTrue(success) self.assertEqual(len(custom_kw_config), 4) for index, key in enumerate(data): self.assertTrue(key in custom_kw_config) key_is_string = isinstance(data[key], str) self.assertTrue(custom_kw_config.keyIsDouble(key) != key_is_string) self.assertEqual(index, custom_kw_config.indexOfKey(key)) self.assertEqual(result[index], str(data[key])) self.assertTrue(len(custom_kw_config.getKeys()) == 4) for key in custom_kw_config: self.assertTrue(key in data)