Esempio n. 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
Esempio n. 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')
Esempio n. 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)
Esempio n. 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)
Esempio n. 5
0
 def test_label(self):
     assert Setting('custom_key', 0).property('label') == 'custom key'
     assert Setting('key', 0, label='Label').property('label') == 'Label'
Esempio n. 6
0
def test_create_setting_error(properties):
    with pytest.raises(SettingsError):
        Setting('key', **properties)
Esempio n. 7
0
 def test_hidden(self):
     assert Setting('key', 0).property('hidden') is False
     assert Setting('key', 0, hidden=True).property('hidden') is True
Esempio n. 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
Esempio n. 9
0
 def test_nullable(self, value, properties, nullable):
     assert Setting('key', value, **
                    properties).property('nullable') is nullable
Esempio n. 10
0
 def test_hash(self):
     assert hash(Setting('key', 1)) == hash('key')
Esempio n. 11
0
 def test_equals(self):
     assert Setting('key', 1) == 'key'
Esempio n. 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
Esempio n. 13
0
 def test_name(self):
     assert Setting('key', 0).name == 'key'
Esempio n. 14
0
 def test_multi_choice(self, value, choices, minmax):
     Setting('key', value, choices=choices, minmax=minmax)
Esempio n. 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
Esempio n. 16
0
 def test_multi_choice_invalid(self, value, choices, minmax):
     with pytest.raises(SettingsError):
         Setting('key', value, choices=choices, minmax=minmax)
Esempio n. 17
0
def test_create_setting(properties):
    Setting('key', **properties)
Esempio n. 18
0
 def test_nullable_invalid(self):
     with pytest.raises(SettingsError):
         Setting('key', None)
Esempio n. 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