diff options
Diffstat (limited to 'tests/unit/config/test_configtypes.py')
-rw-r--r-- | tests/unit/config/test_configtypes.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 4dd7837fb..930234425 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -533,6 +533,14 @@ class FlagListSubclass(configtypes.FlagList): 'foo', 'bar', 'baz') +class FromObjType(configtypes.BaseType): + + """Config type to test from_obj for List/Dict.""" + + def from_obj(self, obj): + return int(obj) + + class TestList: """Test List and FlagList.""" @@ -647,6 +655,12 @@ class TestList: with pytest.raises(AssertionError): typ.to_doc([['foo']]) + def test_from_obj_sub(self): + """Make sure the list calls from_obj() on sub-types.""" + typ = configtypes.List(valtype=FromObjType()) + value = typ.from_obj(['1', '2']) + assert value == [1, 2] + class TestFlagList: @@ -1665,6 +1679,13 @@ class TestDict: print(doc) assert doc == expected + def test_from_obj_sub(self): + """Make sure the dict calls from_obj() on sub-types.""" + typ = configtypes.Dict(keytype=configtypes.String(), + valtype=FromObjType()) + value = typ.from_obj({'1': '2'}) + assert value == {'1': 2} + def unrequired_class(**kwargs): return configtypes.File(required=False, **kwargs) |