Add commaSeperatedIntegers/commaSeperatedStrings validator functions to configuration. Rename testsuite collection test.py to testsuite.py to prevent name collision with test module test.py
This commit is contained in:
18
config.py
18
config.py
@@ -87,9 +87,25 @@ class Config(object):
|
|||||||
self.__dict__[section].__dict__[name] = vdefault
|
self.__dict__[section].__dict__[name] = vdefault
|
||||||
|
|
||||||
def x2bool(s):
|
def x2bool(s):
|
||||||
"""Helper function to convert strings from the config to bool"""
|
"""
|
||||||
|
Helper function to convert strings from the config to bool
|
||||||
|
"""
|
||||||
if isinstance(s, bool):
|
if isinstance(s, bool):
|
||||||
return s
|
return s
|
||||||
elif isinstance(s, basestring):
|
elif isinstance(s, basestring):
|
||||||
return s.lower() in ['1', 'true']
|
return s.lower() in ['1', 'true']
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
|
def commaSeperatedIntegers(s):
|
||||||
|
"""
|
||||||
|
Helper function to convert a string from the config
|
||||||
|
containing comma seperated integers into a list of integers
|
||||||
|
"""
|
||||||
|
return map(int, s.split(','))
|
||||||
|
|
||||||
|
def commaSeperatedStrings(s):
|
||||||
|
"""
|
||||||
|
Helper function to convert a string from the config
|
||||||
|
containing comma seperated strings into a list of strings
|
||||||
|
"""
|
||||||
|
return map(str.strip, s.split(','))
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from config import Config, x2bool
|
from config import Config, x2bool, commaSeperatedIntegers, commaSeperatedStrings
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -97,6 +97,13 @@ value = True
|
|||||||
assert(x2bool("10") == False)
|
assert(x2bool("10") == False)
|
||||||
assert(x2bool("notabool") == False)
|
assert(x2bool("notabool") == False)
|
||||||
|
|
||||||
|
def testCommaSeperatedIntegers(self):
|
||||||
|
assert(commaSeperatedIntegers(" 1,2 , 333 ") == [1,2,333])
|
||||||
|
self.assertRaises(ValueError, commaSeperatedIntegers, "1,2,a")
|
||||||
|
|
||||||
|
def testCommaSeperatedStrings(self):
|
||||||
|
assert(commaSeperatedStrings("Bernd, the, bred !") == ["Bernd", "the", "bred !"])
|
||||||
|
|
||||||
def testConfig(self):
|
def testConfig(self):
|
||||||
path = create_file(self.cfg_content)
|
path = create_file(self.cfg_content)
|
||||||
try:
|
try:
|
||||||
|
6
mumo.py
6
mumo.py
@@ -32,7 +32,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import Ice
|
import Ice
|
||||||
import logging
|
import logging
|
||||||
from config import Config, x2bool
|
from config import (Config,
|
||||||
|
x2bool,
|
||||||
|
commaSeperatedIntegers)
|
||||||
|
|
||||||
from threading import Timer
|
from threading import Timer
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
@@ -57,7 +59,7 @@ default.update({'ice':(('host', str, '127.0.0.1'),
|
|||||||
('watchdog', int, 30)),
|
('watchdog', int, 30)),
|
||||||
|
|
||||||
'iceraw':None,
|
'iceraw':None,
|
||||||
'murmur':(('servers', lambda x:map(int, x.split(',')), []),),
|
'murmur':(('servers', commaSeperatedIntegers, []),),
|
||||||
'log':(('level', int, logging.DEBUG),
|
'log':(('level', int, logging.DEBUG),
|
||||||
('file', str, 'mumo.log'))})
|
('file', str, 'mumo.log'))})
|
||||||
|
|
||||||
|
@@ -29,7 +29,11 @@
|
|||||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
from config import Config, x2bool
|
from config import (Config,
|
||||||
|
x2bool,
|
||||||
|
commaSeperatedIntegers,
|
||||||
|
commaSeperatedStrings)
|
||||||
|
|
||||||
from worker import Worker
|
from worker import Worker
|
||||||
|
|
||||||
class MumoModule(Worker):
|
class MumoModule(Worker):
|
||||||
|
Reference in New Issue
Block a user