def test_remove_option(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'normal', 'set-normally')
        cf.set(cf.default_section, 'default', 'set-in-defaults')

        # can remove normal options
        self.assertTrue(cf.remove_option('section', 'normal'))
        self.assertFalse(cf.has_option('section', 'normal'))

        # can't remove defaults accidentally (maybe there should be shadowing)
        self.assertFalse(cf.remove_option('section', 'default'))
        self.assertEqual(cf.get('section', 'default'), 'set-in-defaults')
Esempio n. 2
0
    def test_remove_option(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'normal', 'set-normally')
        cf.set(cf.default_section, 'default', 'set-in-defaults')

        # can remove normal options
        self.assertTrue(cf.remove_option('section', 'normal'))
        self.assertFalse(cf.has_option('section', 'normal'))

        # can't remove defaults accidentally (maybe there should be shadowing)
        self.assertFalse(cf.remove_option('section', 'default'))
        self.assertEqual(cf.get('section', 'default'), 'set-in-defaults')
    def test_get_from_vars(self):
        cf = JSONConfigParser()
        cf.add_section('section')
        cf.set('section', 'option', 'set-in-section')

        self.assertEqual(cf.get('section', 'option',
                                vars={'option': 'set-in-vars'}),
                         'set-in-vars',
                         msg="vars should take priority over options in \
                              section")

        self.assertEqual(cf.get('section', 'option', vars={}),
                         'set-in-section',
                         msg="get should fall back to section if option not \
                              in vars")
Esempio n. 4
0
    def test_get_from_vars(self):
        cf = JSONConfigParser()
        cf.add_section('section')
        cf.set('section', 'option', 'set-in-section')

        self.assertEqual(cf.get('section', 'option',
                                vars={'option': 'set-in-vars'}),
                         'set-in-vars',
                         msg="vars should take priority over options in \
                              section")

        self.assertEqual(cf.get('section', 'option', vars={}),
                         'set-in-section',
                         msg="get should fall back to section if option not \
                              in vars")
    def test_has_option(self):
        cf = JSONConfigParser()

        # option in nonexistant section does not exist
        self.assertFalse(cf.has_option('nonexistant', 'unset'))

        cf.add_section('section')
        self.assertFalse(cf.has_option('section', 'unset'),
                         msg="has_option should return False if section \
                              exists but option is unset")

        cf.set('section', 'set', 'set-normally')
        self.assertTrue(cf.has_option('section', 'set'),
                        msg="has option should return True if option is set \
                             normally")

        cf.set(cf.default_section, 'default', 'set-in-defaults')
        self.assertTrue(cf.has_option('section', 'default'),
                        msg="has_option should return True if option set in \
                             defaults")
    def test_get_from_defaults(self):
        cf = JSONConfigParser()

        cf.set(cf.default_section, 'option', 'set-in-defaults')
        try:
            cf.get('section', 'option')
        except NoSectionError:
            pass
        else:
            self.fail("Only fall back to defaults if section exists")

        cf.add_section('section')
        self.assertEqual(cf.get('section', 'option'), 'set-in-defaults',
                         msg="get should fall back to defaults if value not \
                              set in section")

        cf.set('section', 'option', 'set-normally')
        self.assertEqual(cf.get('section', 'option'), 'set-normally',
                         msg="get shouldn't fall back if option is set \
                              normally")
Esempio n. 7
0
    def test_has_option(self):
        cf = JSONConfigParser()

        # option in nonexistant section does not exist
        self.assertFalse(cf.has_option('nonexistant', 'unset'))

        cf.add_section('section')
        self.assertFalse(cf.has_option('section', 'unset'),
                         msg="has_option should return False if section \
                              exists but option is unset")

        cf.set('section', 'set', 'set-normally')
        self.assertTrue(cf.has_option('section', 'set'),
                        msg="has option should return True if option is set \
                             normally")

        cf.set(cf.default_section, 'default', 'set-in-defaults')
        self.assertTrue(cf.has_option('section', 'default'),
                        msg="has_option should return True if option set in \
                             defaults")
Esempio n. 8
0
    def test_get_from_defaults(self):
        cf = JSONConfigParser()

        cf.set(cf.default_section, 'option', 'set-in-defaults')
        try:
            cf.get('section', 'option')
        except NoSectionError:
            pass
        else:  # pragma: no cover
            self.fail("Only fall back to defaults if section exists")

        cf.add_section('section')
        self.assertEqual(cf.get('section', 'option'), 'set-in-defaults',
                         msg="get should fall back to defaults if value not \
                              set in section")

        cf.set('section', 'option', 'set-normally')
        self.assertEqual(cf.get('section', 'option'), 'set-normally',
                         msg="get shouldn't fall back if option is set \
                              normally")
    def test_get(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'section', 'set-in-section')
        self.assertEqual(cf.get('section', 'section'), 'set-in-section')
Esempio n. 10
0
    def test_get(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'section', 'set-in-section')
        self.assertEqual(cf.get('section', 'section'), 'set-in-section')