From 03ba38578e611bef8921a863daa613396f9a1e4b Mon Sep 17 00:00:00 2001 From: Patric Schmitz Date: Sat, 28 Nov 2015 18:29:21 +0100 Subject: [PATCH] set valid_values after __init__ consistently, move type validation out of class into pytest --- qutebrowser/config/configtypes.py | 3 --- tests/unit/config/test_configtypes.py | 17 +++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 5a7c3f72e..d4d498358 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -220,9 +220,6 @@ class MappingType(BaseType): valid_values=None): super().__init__(none_ok) self.valid_values = valid_values - if list(sorted(self.MAPPING)) != list(sorted(self.valid_values)): - raise ValueError("Mapping {!r} doesn't match valid values " - "{!r}".format(self.MAPPING, self.valid_values)) def validate(self, value): super().validate(value.lower()) diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 219519638..5a596747e 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -235,9 +235,8 @@ class GoodMappingSubclass(configtypes.MappingType): } def __init__(self, none_ok=False): - super().__init__( - none_ok, - valid_values = configtypes.ValidValues('one', 'two')) + super().__init__(none_ok) + self.valid_values = configtypes.ValidValues('one', 'two') class BadMappingSubclass(configtypes.MappingType): @@ -250,7 +249,7 @@ class BadMappingSubclass(configtypes.MappingType): def __init__(self, none_ok=False): super().__init__(none_ok) - self.valid_values = configtypes.ValidValues('one', 'two')) + self.valid_values = configtypes.ValidValues('one', 'two') class TestMappingType: @@ -281,11 +280,13 @@ class TestMappingType: def test_transform(self, klass, val, expected): assert klass().transform(val) == expected - def test_bad_subclass_init(self): - with pytest.raises(ValueError): - BadMappingSubclass() - + @pytest.mark.parametrize('typ', [configtypes.ColorSystem(), + configtypes.Position(), + configtypes.SelectOnRemove()]) + def test_mapping_type_matches_valid_values(self, typ): + assert list(sorted(typ.MAPPING)) == list(sorted(typ.valid_values)) + class TestString: """Test String."""