2 from twisted.trial import unittest |
2 from twisted.trial import unittest |
3 import signal |
3 import signal |
4 import io |
4 import io |
5 import ConfigParser |
5 import ConfigParser |
6 from iro import config |
6 from iro import config |
|
7 from iro.offer.provider import Provider, providers |
7 |
8 |
8 class TestConfig(unittest.TestCase): |
9 class TestConfig(unittest.TestCase): |
9 '''test config class''' |
10 '''test config class''' |
10 |
11 |
11 def setUp(self): |
12 def setUp(self): |
12 self._reloadList=config.config.reloadList |
13 self._reloadList=config.config.reloadList |
13 config.config.reloadlist=[] |
14 config.config.reloadList=[] |
14 |
15 |
15 def tearDown(self): |
16 def tearDown(self): |
16 config.config.reloadlist = self._reloadList |
17 config.config.reloadList = self._reloadList |
17 |
18 |
18 @patch('iro.config.config') |
19 @patch('iro.config.config') |
19 def testReadConfig(self,pConfig): |
20 def testReadConfig(self,pConfig): |
20 config.readConfig() |
21 config.readConfig() |
21 self.assertEqual([i[0] for i in pConfig.method_calls],["read","reload"]) |
22 self.assertEqual([i[0] for i in pConfig.method_calls],["read","reload"]) |
75 port = 8000 |
76 port = 8000 |
76 """ |
77 """ |
77 config.config.readfp(io.BytesIO(sample_config)) |
78 config.config.readfp(io.BytesIO(sample_config)) |
78 self.assertRaises(ConfigParser.NoOptionError, config.config.read, []) |
79 self.assertRaises(ConfigParser.NoOptionError, config.config.read, []) |
79 |
80 |
80 def testMust(self): |
81 @patch('iro.config.ConfigParser.read') |
81 pass |
82 def testMust(self,pRead): |
82 testMust.todo= "To implement" |
83 v=Mock() |
|
84 config.main["test"] = config.Option(v) |
|
85 try: |
|
86 sample_config = """[main] |
|
87 hostname = localhost |
|
88 port = 8000 |
|
89 """ |
|
90 config.config.readfp(io.BytesIO(sample_config)) |
|
91 config.config.read([]) |
|
92 self.assertEqual(v.called,0) |
|
93 sample_config = """[main] |
|
94 hostname = localhost |
|
95 port = 8000 |
|
96 test = foohu |
|
97 """ |
|
98 config.config.readfp(io.BytesIO(sample_config)) |
|
99 config.config.read([]) |
|
100 v.assert_called_once_with("foohu","test") |
|
101 finally: |
|
102 del(config.main["test"]) |
83 |
103 |
84 def testProviders(self): |
104 @patch('iro.config.ConfigParser.read') |
85 pass |
105 def testProviders(self, pRead): |
86 testProviders.todo = "to implement" |
106 v=Mock() |
|
107 class TestProvider(Provider): |
|
108 def __init__(self,name,c): |
|
109 Provider.__init__(self,name,c) |
|
110 self.options.update({"test":config.Option(v)}) |
|
111 self.loadConfig() |
|
112 providers["test"]=TestProvider |
|
113 try: |
|
114 sample_config = """[p] |
|
115 """ |
|
116 config.config.readfp(io.BytesIO(sample_config)) |
|
117 self.assertRaises(ConfigParser.NoOptionError, config.config.read, []) |
|
118 self.assertEqual(v.called,0) |
|
119 sample_config = """[p] |
|
120 typ= test |
|
121 test= foo |
|
122 """ |
|
123 config.config.readfp(io.BytesIO(sample_config)) |
|
124 config.config.read([]) |
|
125 v.assert_called_once_with("foo","test") |
|
126 finally: |
|
127 del(providers["test"]) |