class MyConfig(DummyMemoryConfig): test_array = ArrayOption('TestArray', env_name='TEST_ARRAY', default=["1", "2", "3"]) path_array = ArrayOption('PathArray', value_option=PathOption( 'PathOption', path_type=Path, choices=[Path("."), Path("..")])) float_array = ArrayOption('FloatArray', value_option=FloatOption('FloatOption'))
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('ArrayOption2', value_option=ArrayOption('test')) with self.assertRaises(InitializationError): c = MyConfig.get_instance() c.array_option = self.OPTION_TYPE('ArrayOption2', value_option=DictOption('test'))
def test_json_serialization_deserialization_keeps_value(self): o = ArrayOption('test', value_option=PathOption('_', path_type=Path)) v = [Path('.'), Path('..')] j = o.serialize_json(v) self.assertEqual(o.deserialize_json(j), v)
def test_json_deserialization_of_null(self): o = ArrayOption('test', value_option=PathOption('_', path_type=Path)) self.assertEqual(o.deserialize_json('null'), None)
def test_json_serialization_of_None(self): o = ArrayOption('test', value_option=PathOption('_', path_type=Path)) self.assertEqual(o.serialize_json(None), 'null')
def test_choices_cannot_be_empty(self): c = MyConfig.get_instance() with self.assertRaises(InitializationError): c.empty_choices = ArrayOption('EmptyChoices', choices=[])
class Arrays(DummyMemoryConfig): test_array = ArrayOption('ArrayOption', env_name='TEST_ARRAY')
class Arrays(DummyMemoryConfig): test_array = ArrayOption('TestArray', choices=[[1, 2, 3], [4, 5, 6]], env_name='TEST_ARRAY')