class MyConfig(DummyMemoryConfig): test_dict = DictOption('TestDict', env_name='TEST_DICT', default={ "key1": "value1", "key2": "value2" }) path_dict = DictOption('PathDict', value_option=PathOption('PathOption', path_type=Path)) float_dict = DictOption('FloatDict', value_option=FloatOption('FloatOption'))
class Dicts(DummyMemoryConfig): dict_option = DictOption('DictOption', choices=[{ "key1": "value1" }, { "key2": "value2" }], env_name='DICT_OPTION')
def test_value_option_must_not_be_array_or_dict(self): with self.assertRaises(InitializationError): c = MyConfig.get_instance() c.array_option = self.OPTION_TYPE('DictOption', value_option=ArrayOption('test')) with self.assertRaises(InitializationError): c = MyConfig.get_instance() c.array_option = self.OPTION_TYPE('DictOption', value_option=DictOption('test'))
def test_json_deserialization_of_null(self): o = DictOption("test", value_option=PathOption("_", path_type=Path)) self.assertEqual(o.deserialize_json("null"), None)
def test_json_serialization_of_None(self): o = DictOption("test", value_option=PathOption("_", path_type=Path)) self.assertEqual(o.serialize_json(None), "null")
def test_json_serialization_deserialization_keeps_value(self): o = DictOption("test", value_option=PathOption("_", path_type=Path)) v = {"a": Path("."), "b": Path("..")} j = o.serialize_json(v) self.assertEqual(o.deserialize_json(j), v)
def test_choices_cannot_be_empty(self): c = MyConfig.get_instance() with self.assertRaises(InitializationError): c.empty_choices = DictOption('EmptyChoices', choices=[])
class Dicts(DummyMemoryConfig): dict_option = DictOption('DictOption', env_name='DICT_OPTION')