forked from cy-zheng/pyCreeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_conf_settings.py
75 lines (60 loc) · 2.62 KB
/
test_conf_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding:utf-8 -*-
reload(__import__('sys')).setdefaultencoding('utf-8')
__author__ = 'zcy'
import unittest
from pycreeper.conf.settings import Settings
from tests.test_data import test_settings_data
CONF_PATH = 'tests.test_data.test_settings_data'
class SettingsTest(unittest.TestCase):
def test_basics(self):
settings = Settings()
self.assertEqual(settings['RETRY_COUNT'], 3)
settings = Settings(test_settings_data)
self.assertEqual(settings['TEST_INT'], 10)
def test_get_item(self):
settings = Settings(test_settings_data)
self.assertEqual(settings['TEST_STR'], 'foo,bar,baz')
self.assertEqual(settings['TEST_DICT'], {"foo": "bar"})
def test_load_config(self):
settings = Settings(test_settings_data)
self.assertEqual(settings['TEST_STR'], 'foo,bar,baz')
settings = Settings(CONF_PATH)
self.assertEqual(settings['TEST_STR'], 'foo,bar,baz')
self.assertRaises(KeyError, settings['test_lowercase'])
def test_set(self):
settings = Settings(test_settings_data)
self.assertRaises(KeyError, settings['TEST_SET'])
settings.set('TEST_SET', True)
self.assertEqual(settings['TEST_SET'], True)
def test_set_dict(self):
settings = Settings(test_settings_data)
self.assertRaises(KeyError, settings['TEST_SET_1'])
self.assertRaises(KeyError, settings['TEST_SET_2'])
settings.set_dict(
{
'TEST_SET_1': True,
'TEST_SET_2': False
}
)
self.assertEqual(settings['TEST_SET_1'], True)
self.assertEqual(settings['TEST_SET_2'], False)
def test_get(self):
settings = Settings(test_settings_data)
self.assertEqual(settings.get('TEST_GET'), None)
self.assertEqual(settings.get('TEST_GET', 'foo'), 'foo')
settings.set('TEST_GET', 'bar')
self.assertEqual(settings.get('TEST_GET', 'foo'), 'bar')
def test_get_int_and_float(self):
settings = Settings(test_settings_data)
self.assertIsInstance(settings.get_float('TEST_INT'), float)
self.assertIsInstance(settings.get_int('TEST_FLOAT'), int)
def test_get_list(self):
settings = Settings(test_settings_data)
self.assertIsInstance(settings.get_list('TEST_LIST'), list)
self.assertIsInstance(settings.get_list('TEST_STR'), list)
def test_get_dict(self):
settings = Settings(test_settings_data)
self.assertIsInstance(settings.get_dict('TEST_DICT'), dict)
self.assertIsInstance(settings.get_dict('TEST_JSON'), dict)
if __name__ == "__main__":
unittest.main()