Example #1
0
class TestOptions2(unittest.TestCase):

    def setUp(self):
        self.conf = UserConfig('testconfig2', OPTIONS2, load=False)
        
    def tearDown(self):
        self.conf.cleanup()
        
    def test_get_float(self):
        o_float = self.conf.get('category1', 'float')
        self.assertEquals(o_float, 12.3)

    def test_set_float(self):
        self.conf.set('category1', 'float', 14.5)
        o_float = self.conf.get('category1', 'float')
        self.assertEquals(o_float, 14.5)

    def test_get_int(self):
        o_int = self.conf.get('category2', 'int')
        self.assertEquals(o_int, 50)

    def test_get_bool(self):
        o_bool = self.conf.get('category1', 'bool')
        self.assertEquals(o_bool, True)

    def test_get_str(self):
        o_str = self.conf.get('category2', 'str')
        self.assertEquals(o_str, 'text text')

    def test_get_unicode(self):
        o_unicode = self.conf.get('category3', 'unicode')
        self.assertEquals(o_unicode, u'ééǿùùàà')

    def test_get_default(self):
        o_default = self.conf.get('category3', 'unknown', default=23)
        self.assertEquals(o_default, 23)
Example #2
0
# (note that this will be the version number of the configuration file,
#  not of your application! -- at least if you want to keep user old settings)
# (when the version number change, the deprecated options are removed --
#  here 'deprecated' means: not present in defaults values - here 'OPTIONS')
CONFIG = UserConfig('app_name', OPTIONS, version='1.0.2')


# How to get options from .ini file:
print 'Custom font:', 'yes' if CONFIG.get('Font', 'custom') else 'no'
print 'Font family:', CONFIG.get('Font', 'family')

# How to get an option default value:
# (if .ini file wasn't modified externaly, result will be the same
# as the two previous lines)
print 'Custom font:', 'yes' if CONFIG.get_default('Font', 'custom') else 'no'
print 'Font family:', CONFIG.get_default('Font', 'family')

# Set an option:
CONFIG.set('Font', 'size', 18)

# Reset configuration to default options:
# (i.e. overwrite the current .ini file with default settings)
CONFIG.reset_to_defaults()

# Reset configuration to default options without overwriting
# the current .ini file settings:
CONFIG.reset_to_defaults(save=False)

# Removing .ini file (e.g. before uninstalling the application):
CONFIG.cleanup()
Example #3
0
 def test_cleanup(self):
     conf = UserConfig('testconfig1', OPTIONS1)
     conf.cleanup()
     self.assertTrue( not os.path.isfile(conf.filename()) )
Example #4
0
class TestOptions1(unittest.TestCase):

    def setUp(self):
        self.conf = UserConfig('testconfig1', OPTIONS1)
        
    def tearDown(self):
        self.conf.cleanup()
        
    def test_get_list(self):
        o_list = self.conf.get(None, 'category1/list')
        self.assertEquals(o_list, [5, "kk"])

    def test_set_list(self):
        self.conf.set(None, 'category1/list', [14.5, "jj"])
        o_list = self.conf.get(None, 'category1/list')
        self.assertEquals(o_list, [14.5, "jj"])

    def test_get_tuple(self):
        o_tuple = self.conf.get(None, 'category1/tuple')
        self.assertEquals(o_tuple, (None, "foo"))

    def test_set_tuple(self):
        self.conf.set(None, 'category1/tuple', (False, 1238, 3.5))
        o_tuple = self.conf.get(None, 'category1/tuple')
        self.assertEquals(o_tuple, (False, 1238, 3.5))
        
    def test_get_float(self):
        o_float = self.conf.get(None, 'category1/float')
        self.assertEquals(o_float, 12.3)

    def test_set_float(self):
        self.conf.set(None, 'category1/float', 14.5)
        o_float = self.conf.get(None, 'category1/float')
        self.assertEquals(o_float, 14.5)

    def test_get_int(self):
        o_int = self.conf.get(None, 'category2/int')
        self.assertEquals(o_int, 50)

    def test_set_int(self):
        self.conf.set(None, 'category2/int', 10.0)
        o_int = self.conf.get(None, 'category2/int')
        self.assertEquals(o_int, 10)

    def test_get_bool(self):
        o_bool = self.conf.get(None, 'category1/bool')
        self.assertEquals(o_bool, True)

    def test_set_bool(self):
        self.conf.set(None, 'category1/bool', False)
        o_bool = self.conf.get(None, 'category1/bool')
        self.assertEquals(o_bool, False)

    def test_get_str(self):
        o_str = self.conf.get(None, 'category2/str')
        self.assertEquals(o_str, 'text text')

    def test_set_str(self):
        self.conf.set(None, 'category2/str', 'foobar')
        o_str = self.conf.get(None, 'category2/str')
        self.assertEquals(o_str, 'foobar')

    def test_get_unicode(self):
        o_unicode = self.conf.get(None, 'category3/unicode')
        self.assertEquals(o_unicode, u'ééǿùùàà')

    def test_set_unicode(self):
        self.conf.set(None, 'category3/unicode', u'ééǿùùàà')
        o_unicode = self.conf.get(None, 'category3/unicode')
        self.assertEquals(o_unicode, u'ééǿùùàà')