Example #1
0
    def test_subsection_getitem(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        cs = c.section(self.section)

        self.assertEqual(self.value, cs[self.param])
Example #2
0
    def test_subsection_items(self):
        c = Configuration()
        c.set('%s.param1' % self.section, 'value1')
        c.set_default('%s.param2' % self.section, 'value2')

        self.assertEqual([('param1', 'value1'), ('param2', 'value2')],
                         sorted(c.section(self.section).items()))
Example #3
0
    def test_template_substitution(self):
        c = Configuration()
        c.set('a', 'x')
        c.set('b', '$a')
        c.set('c', '$b')

        self.assertEqual('x', c.get('c'))
Example #4
0
    def test_parameter_names_containing_sections(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(
            self.value, c.get('%s.%s' %
                              (self.section, self.param)))
Example #5
0
    def test_contains(self):
        c = Configuration()

        self.assertFalse(self.section in c)

        c.set(self.fullparam, self.value)
        self.assertTrue(self.section in c)
Example #6
0
    def test_contains(self):
        c = Configuration()

        self.assertFalse(self.section in c)

        c.set(self.fullparam, self.value)
        self.assertTrue(self.section in c)
Example #7
0
    def test_getting_raw_values(self):
        c = Configuration()

        c.set('a', '$b')
        c.set('b', 'x')

        self.assertEqual('$b', c.get('a', raw=True))
Example #8
0
    def test_template_substitution(self):
        c = Configuration()
        c.set('a', 'x')
        c.set('b', '$a')
        c.set('c', '$b')

        self.assertEqual('x', c.get('c'))
Example #9
0
    def test_cycle_template_substitution_resolves_in_empty_string(self):
        c = Configuration()
        c.set('a', 'a$c')
        c.set('b', 'b$a')
        c.set('c', 'c$b')

        self.assertEqual('cba', c.get('c'))
Example #10
0
    def test_subsection_keys(self):
        c = Configuration()
        c.set_default('%s.param1' % self.section, '123')
        c.set('%s.param2' % self.section, '456')

        self.assertEqual(['param1', 'param2'],
                         sorted(c.section(self.section).keys()))
Example #11
0
    def test_subsection_getitem(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        cs = c.section(self.section)

        self.assertEqual(self.value, cs[self.param])
Example #12
0
    def test_cycle_template_substitution_resolves_in_empty_string(self):
        c = Configuration()
        c.set('a', 'a$c')
        c.set('b', 'b$a')
        c.set('c', 'c$b')

        self.assertEqual('cba', c.get('c'))
Example #13
0
    def test_subsection_keys(self):
        c = Configuration()
        c.set_default('%s.param1' % self.section, '123')
        c.set('%s.param2' % self.section, '456')

        self.assertEqual(
            ['param1', 'param2'], sorted(c.section(self.section).keys()))
Example #14
0
    def test_getting_raw_values(self):
        c = Configuration()

        c.set('a', '$b')
        c.set('b', 'x')

        self.assertEqual('$b', c.get('a', raw=True))
Example #15
0
    def test_type_for_unknown_param(self):
        schema = ConfigSchema('test', '1.0', 'ini', [])

        c = Configuration(schema)

        c.set('param1', '123')

        self.assertEqual('123', c.get('param1'))
Example #16
0
    def test_subsection_items(self):
        c = Configuration()
        c.set('%s.param1' % self.section, 'value1')
        c.set_default('%s.param2' % self.section, 'value2')

        self.assertEqual(
            [('param1', 'value1'), ('param2', 'value2')],
            sorted(c.section(self.section).items()))
Example #17
0
    def test_validate_returns_none_for_unknown_param(self):
        schema = ConfigSchema('test', '1.0', 'ini', [])

        c = Configuration(schema)

        c.set('param1', '123')

        self.assertIsNone(c.validate('param1'))
Example #18
0
    def test_subsection_contains(self):
        c = Configuration()

        c.set('section1.param1', '123')
        c.set_default('section2.param2', '234')

        self.assertTrue('param1' in c.section('section1'))
        self.assertTrue('param2' in c.section('section2'))
        self.assertFalse('param1' in c.section('section2'))
Example #19
0
    def test_subsection_contains(self):
        c = Configuration()

        c.set('section1.param1', '123')
        c.set_default('section2.param2', '234')

        self.assertTrue('param1' in c.section('section1'))
        self.assertTrue('param2' in c.section('section2'))
        self.assertFalse('param1' in c.section('section2'))
Example #20
0
    def test_getting_typed_param_raw_value(self):
        schema = ConfigSchema('test', '1.0', 'ini', [
            ConfigParameterSchema('param1', type='integer', section='DEFAULT')
        ])

        c = Configuration(schema)

        c.set('param1', '123')

        self.assertEqual('123', c.get('param1', raw=True))
Example #21
0
    def test_validate_returns_error_if_valid_is_invalid(self):
        schema = ConfigSchema('test', '1.0', 'ini', [
            ConfigParameterSchema('param1', type='integer', section='DEFAULT')
        ])

        c = Configuration(schema)

        c.set('param1', 'abc')

        self.assertTrue(isinstance(c.validate('param1'), InvalidValueError))
Example #22
0
    def test_typed_param_with_invalid_value_returns_string_value(self):
        schema = ConfigSchema('test', '1.0', 'ini', [
            ConfigParameterSchema('param1', type='integer', section='DEFAULT')
        ])

        c = Configuration(schema)

        c.set('param1', '123a')

        self.assertEqual('123a', c.get('param1'))
Example #23
0
    def test_validate_returns_none_if_value_is_valid(self):
        schema = ConfigSchema('test', '1.0', 'ini', [
            ConfigParameterSchema('param1', type='integer', section='DEFAULT')
        ])

        c = Configuration(schema)

        c.set('param1', '123')

        self.assertIsNone(c.validate('param1'))
Example #24
0
    def test_typed_params(self):
        schema = ConfigSchema('test', '1.0', 'ini', [
            ConfigParameterSchema('param1', type='integer', section='DEFAULT')
        ])

        c = Configuration(schema)

        c.set('param1', '123')

        self.assertEqual(123, c.get('param1'))
Example #25
0
    def test_parameter_with_default_section(self):
        c = Configuration()
        c.set(self.param, self.value)

        self.assertEqual(self.value, c.get(self.param))
Example #26
0
    def test_normal_overrides_default(self):
        c = Configuration()
        c.set(self.fullparam, self.value)
        c.set_default(self.fullparam, self.default_value)

        self.assertEqual(self.value, c.get(self.fullparam))
Example #27
0
    def test_keys(self):
        c = Configuration()
        c.set_default('section1.param1', '123')
        c.set('section2.param1', '456')

        self.assertEqual(['section1', 'section2'], sorted(c.keys()))
Example #28
0
    def test_parameter_names_containing_sections(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(self.value,
                         c.get('%s.%s' % (self.section, self.param)))
Example #29
0
    def test_storage(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(self.value, c.get(self.fullparam))
Example #30
0
    def test_getitem(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(self.value, c[self.fullparam])
Example #31
0
    def test_normal_overrides_default(self):
        c = Configuration()
        c.set(self.fullparam, self.value)
        c.set_default(self.fullparam, self.default_value)

        self.assertEqual(self.value, c.get(self.fullparam))
Example #32
0
    def test_contains_normal(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertTrue(c.contains(self.fullparam))
        self.assertTrue(c.contains(self.fullparam, ignoreDefault=True))
Example #33
0
    def test_storage(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(self.value, c.get(self.fullparam))
Example #34
0
    def test_contains_normal(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertTrue(c.contains(self.fullparam))
        self.assertTrue(c.contains(self.fullparam, ignoreDefault=True))
Example #35
0
    def test_getitem(self):
        c = Configuration()
        c.set(self.fullparam, self.value)

        self.assertEqual(self.value, c[self.fullparam])
Example #36
0
    def test_is_default_returns_false_if_both_values_set(self):
        c = Configuration()
        c.set_default(self.fullparam, self.default_value)
        c.set(self.fullparam, self.value)

        self.assertFalse(c.is_default(self.fullparam))
Example #37
0
    def test_keys(self):
        c = Configuration()
        c.set_default('section1.param1', '123')
        c.set('section2.param1', '456')

        self.assertEqual(['section1', 'section2'], sorted(c.keys()))
Example #38
0
    def test_is_default_returns_false_if_both_values_set(self):
        c = Configuration()
        c.set_default(self.fullparam, self.default_value)
        c.set(self.fullparam, self.value)

        self.assertFalse(c.is_default(self.fullparam))
Example #39
0
    def test_parameter_with_default_section(self):
        c = Configuration()
        c.set(self.param, self.value)

        self.assertEqual(self.value, c.get(self.param))