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_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_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_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')