Пример #1
0
    def test_get_from_fallback(self):
        cf = JSONConfigParser()
        cf.add_section('section')

        # returns from fallback if section exists
        self.assertEqual(cf.get('section', 'unset', 'fallback'), 'fallback')

        try:
            cf.get('nosection', 'unset', 'fallback')
        except NoSectionError:
            pass
        else:  # pragma: no cover
            self.fail()
    def test_get_from_fallback(self):
        cf = JSONConfigParser()
        cf.add_section('section')

        # returns from fallback if section exists
        self.assertEqual(cf.get('section', 'unset', 'fallback'), 'fallback')

        try:
            cf.get('nosection', 'unset', 'fallback')
        except NoSectionError:
            pass
        else:
            self.fail()
    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')
Пример #4
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")
Пример #6
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")
Пример #9
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")
Пример #10
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')
Пример #12
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')