--- a/iro/config.py Thu Feb 23 16:57:57 2012 +0100
+++ b/iro/config.py Thu Feb 23 16:58:58 2012 +0100
@@ -1,4 +1,4 @@
-from ConfigParser import ConfigParser
+from ConfigParser import ConfigParser, NoOptionError
import signal
from functools import partial
@@ -11,20 +11,20 @@
self.reloadList=[]
def read(self,files):
- from offer import providers
+ from offer import getProvider
ConfigParser.read(self, files)
for s in self.sections():
if s == "main":
opts=main
+ for o in opts:
+ try:
+ opts[o].validate(self.get(s,o),o)
+ except (ValidateException, NoOptionError):
+ if opts[o].must:
+ raise
else:
- opts=providers[self.get(s,'typ')].options
+ getProvider("tmp", self.get(s,'typ'), self.items(s))
- for o in opts:
- try:
- opts[o].validate(self.get(s,o),o)
- except ValidateException:
- if opts[o].must:
- raise
def reload_(self):
for f in self.reloadList:
--- a/tests/config.py Thu Feb 23 16:57:57 2012 +0100
+++ b/tests/config.py Thu Feb 23 16:58:58 2012 +0100
@@ -4,16 +4,17 @@
import io
import ConfigParser
from iro import config
+from iro.offer.provider import Provider, providers
class TestConfig(unittest.TestCase):
'''test config class'''
def setUp(self):
self._reloadList=config.config.reloadList
- config.config.reloadlist=[]
+ config.config.reloadList=[]
def tearDown(self):
- config.config.reloadlist = self._reloadList
+ config.config.reloadList = self._reloadList
@patch('iro.config.config')
def testReadConfig(self,pConfig):
@@ -77,10 +78,50 @@
config.config.readfp(io.BytesIO(sample_config))
self.assertRaises(ConfigParser.NoOptionError, config.config.read, [])
- def testMust(self):
- pass
- testMust.todo= "To implement"
+ @patch('iro.config.ConfigParser.read')
+ def testMust(self,pRead):
+ v=Mock()
+ config.main["test"] = config.Option(v)
+ try:
+ sample_config = """[main]
+hostname = localhost
+port = 8000
+"""
+ config.config.readfp(io.BytesIO(sample_config))
+ config.config.read([])
+ self.assertEqual(v.called,0)
+ sample_config = """[main]
+hostname = localhost
+port = 8000
+test = foohu
+ """
+ config.config.readfp(io.BytesIO(sample_config))
+ config.config.read([])
+ v.assert_called_once_with("foohu","test")
+ finally:
+ del(config.main["test"])
- def testProviders(self):
- pass
- testProviders.todo = "to implement"
+ @patch('iro.config.ConfigParser.read')
+ def testProviders(self, pRead):
+ v=Mock()
+ class TestProvider(Provider):
+ def __init__(self,name,c):
+ Provider.__init__(self,name,c)
+ self.options.update({"test":config.Option(v)})
+ self.loadConfig()
+ providers["test"]=TestProvider
+ try:
+ sample_config = """[p]
+"""
+ config.config.readfp(io.BytesIO(sample_config))
+ self.assertRaises(ConfigParser.NoOptionError, config.config.read, [])
+ self.assertEqual(v.called,0)
+ sample_config = """[p]
+typ= test
+test= foo
+"""
+ config.config.readfp(io.BytesIO(sample_config))
+ config.config.read([])
+ v.assert_called_once_with("foo","test")
+ finally:
+ del(providers["test"])