You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
# -*- coding: utf-8 -*-
|
|
import unittest
|
|
|
|
import testenv
|
|
from papers import configs
|
|
from papers.configs import config
|
|
from papers.p3 import configparser
|
|
|
|
class TestConfig(unittest.TestCase):
|
|
|
|
def test_create_config(self):
|
|
a = configs.Config()
|
|
a.as_global()
|
|
self.assertEqual(a, config())
|
|
|
|
def test_config_content(self):
|
|
a = configs.Config()
|
|
a.as_global()
|
|
self.assertEqual(config().papers_dir, configs.DFT_PAPERS_DIR)
|
|
self.assertEqual(config().color, configs.str2bool(configs.DFT_COLOR))
|
|
|
|
def test_set(self):
|
|
a = configs.Config()
|
|
a.as_global()
|
|
config().color = 'no'
|
|
self.assertEqual(config().color, False)
|
|
# booleans type for new variables are memorized, but not saved.
|
|
config().bla = True
|
|
self.assertEqual(config().bla, True)
|
|
|
|
with self.assertRaises(configparser.NoOptionError):
|
|
config()._cfg.get(configs.MAIN_SECTION, '_section')
|
|
|
|
def test_reload(self):
|
|
|
|
a = configs.Config()
|
|
a.as_global()
|
|
a.color = False
|
|
a.bla = 'foo'
|
|
config.color = not configs.str2bool(configs.DFT_COLOR)
|
|
self.assertEqual(config().color, not configs.str2bool(configs.DFT_COLOR))
|
|
|
|
b = configs.Config()
|
|
b.as_global()
|
|
self.assertEqual(b, config())
|
|
self.assertEqual(config().color, configs.str2bool(configs.DFT_COLOR))
|
|
|
|
def test_exception(self):
|
|
|
|
a = configs.Config()
|
|
a.as_global()
|
|
|
|
with self.assertRaises(configparser.NoOptionError):
|
|
config().color2
|
|
self.assertEqual(config().get('color2', default = 'blue'), 'blue')
|
|
|
|
with self.assertRaises(configparser.NoSectionError):
|
|
config(section = 'bla3').color
|
|
self.assertEqual(config(section = 'bla3').get('color', default = 'green'), 'green')
|
|
self.assertEqual(config(section = 'bla3').get('color', default = config().color), True)
|
|
|
|
def test_keywords(self):
|
|
a = configs.Config(papers_dir = '/blabla')
|
|
self.assertEqual(a.papers_dir, '/blabla')
|