Пример #1
0
def test_argparse(name, properties, input_string, parsed):
    s = Setting(name, **properties)
    flag, args = s.as_parser_args()
    parser = argparse.ArgumentParser()
    parser.add_argument(flag, **args)
    p_args = parser.parse_args(input_string.split())
    assert getattr(p_args, name) == parsed
Пример #2
0
    def test_property(self):
        s = Setting('key', 0, custom=1)
        assert s.property('choices') is None
        assert s.property('custom') == 1
        assert s.property('default') == 0

        with pytest.raises(KeyError):
            s.property('unknown')
Пример #3
0
 def test_minmax(self, value, minmax, valid, invalid):
     s = Setting('key', value, minmax=minmax)
     for i in valid:
         s.set(i)
     for i in invalid:
         with pytest.raises(SettingsError):
             s.set(i)
Пример #4
0
 def test_choices(self, value, choices, invalid):
     s = Setting('key', value, choices=choices)
     for i in choices:
         s.set(i)
     for i in invalid:
         with pytest.raises(SettingsError):
             s.set(i)
Пример #5
0
 def test_label(self):
     assert Setting('custom_key', 0).property('label') == 'custom key'
     assert Setting('key', 0, label='Label').property('label') == 'Label'
Пример #6
0
def test_create_setting_error(properties):
    with pytest.raises(SettingsError):
        Setting('key', **properties)
Пример #7
0
 def test_hidden(self):
     assert Setting('key', 0).property('hidden') is False
     assert Setting('key', 0, hidden=True).property('hidden') is True
Пример #8
0
 def test_is_modified(self, value, alt_value, modified):
     s = Setting('key', value)
     assert s.is_modified() is False
     s.set(alt_value)
     assert s.is_modified() is modified
Пример #9
0
 def test_nullable(self, value, properties, nullable):
     assert Setting('key', value, **
                    properties).property('nullable') is nullable
Пример #10
0
 def test_hash(self):
     assert hash(Setting('key', 1)) == hash('key')
Пример #11
0
 def test_equals(self):
     assert Setting('key', 1) == 'key'
Пример #12
0
 def test_reset(self, value, alt_value):
     s = Setting('key', value)
     s.set(alt_value)
     assert s.get() == alt_value
     s.reset()
     assert s.get() == value
Пример #13
0
 def test_name(self):
     assert Setting('key', 0).name == 'key'
Пример #14
0
 def test_multi_choice(self, value, choices, minmax):
     Setting('key', value, choices=choices, minmax=minmax)
Пример #15
0
 def test_default(self, default, alternate):
     s = Setting('key', default)
     assert s.property('default') == default
     s.set(alternate)
     assert s.property('default') == default
Пример #16
0
 def test_multi_choice_invalid(self, value, choices, minmax):
     with pytest.raises(SettingsError):
         Setting('key', value, choices=choices, minmax=minmax)
Пример #17
0
def test_create_setting(properties):
    Setting('key', **properties)
Пример #18
0
 def test_nullable_invalid(self):
     with pytest.raises(SettingsError):
         Setting('key', None)
Пример #19
0
 def test_has_property(self):
     s = Setting('key', 0, custom=1)
     assert s.has_property('custom') is True
     assert s.has_property('unknown') is False