Accept uncomplete configuration file, fall back to default value
darcs-hash:20080515064539-86b55-23b6f5dfb124f10c8f5eebdfdcdcc10b83e08564.gz
This commit is contained in:
@@ -130,12 +130,14 @@ class JCLRunner(object):
|
||||
(section, set_func) = cleanopts[opt]
|
||||
if section is not None:
|
||||
attr = opt.replace("-", "_")
|
||||
config_property = self.config.get(section, attr)
|
||||
self.logger.debug("Setting " + attr + " = " +
|
||||
config_property +
|
||||
" from configuration file " +
|
||||
self.config_file)
|
||||
set_func(config_property)
|
||||
if self.config.has_section(section) \
|
||||
and self.config.has_option(section, attr):
|
||||
config_property = self.config.get(section, attr)
|
||||
self.logger.debug("Setting " + attr + " = " +
|
||||
config_property +
|
||||
" from configuration file " +
|
||||
self.config_file)
|
||||
set_func(config_property)
|
||||
|
||||
def configure(self):
|
||||
"""
|
||||
@@ -154,7 +156,9 @@ class JCLRunner(object):
|
||||
else:
|
||||
cleanopts[option[1]] = (option[2], option[4])
|
||||
|
||||
commandline_args = self.__configure_commandline_args(shortopts, longopts, cleanopts)
|
||||
commandline_args = self.__configure_commandline_args(shortopts,
|
||||
longopts,
|
||||
cleanopts)
|
||||
if commandline_args.has_key("debug") or commandline_args.has_key("d"):
|
||||
self.debug = True
|
||||
self.logger.debug("Debug activated")
|
||||
@@ -245,7 +249,7 @@ class JCLRunner(object):
|
||||
model.db_connection_str = self.db_url
|
||||
model.db_connect()
|
||||
self.setup_db()
|
||||
ipshell = IPShellEmbed(["-pi1", self.component_short_name + "[\\#]: "],
|
||||
ipshell = IPShellEmbed(["-pi1", self.component_short_name + "[\\#]: "],
|
||||
"Starting " + self.component_name + " v" \
|
||||
+ self.component_version + " console.",
|
||||
"Ending " + self.component_name + " v" \
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
## Login : David Rousselie <dax@happycoders.org>
|
||||
## Started on Fri May 18 13:43:37 2007 David Rousselie
|
||||
## $Id$
|
||||
##
|
||||
##
|
||||
## Copyright (C) 2007 David Rousselie
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 2 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
@@ -45,7 +45,7 @@ class JCLRunner_TestCase(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self.runner = None
|
||||
sys.argv = [""]
|
||||
|
||||
|
||||
def test_configure_default(self):
|
||||
self.runner.configure()
|
||||
self.assertEquals(self.runner.config_file, "jcl.conf")
|
||||
@@ -70,6 +70,19 @@ class JCLRunner_TestCase(unittest.TestCase):
|
||||
self.assertEquals(self.runner.pid_file, "/var/run/jabber/test_jcl.pid")
|
||||
self.assertFalse(self.runner.debug)
|
||||
|
||||
def test_configure_uncomplete_configfile(self):
|
||||
self.runner.config_file = "src/jcl/tests/uncomplete_jcl.conf"
|
||||
self.runner.configure()
|
||||
self.assertEquals(self.runner.server, "test_localhost")
|
||||
self.assertEquals(self.runner.port, 42)
|
||||
self.assertEquals(self.runner.secret, "test_secret")
|
||||
self.assertEquals(self.runner.service_jid, "test_jcl.localhost")
|
||||
self.assertEquals(self.runner.language, "test_en")
|
||||
self.assertEquals(self.runner.db_url, "test_sqlite://root@localhost/var/spool/jabber/test_jcl.db")
|
||||
# pid_file is not in uncmplete_jcl.conf, must be default value
|
||||
self.assertEquals(self.runner.pid_file, "/var/run/jabber/jcl.pid")
|
||||
self.assertFalse(self.runner.debug)
|
||||
|
||||
def test_configure_commandline_shortopt(self):
|
||||
sys.argv = ["", "-c", "src/jcl/tests/jcl.conf", \
|
||||
"-S", "test2_localhost", \
|
||||
@@ -161,10 +174,10 @@ class JCLRunner_TestCase(unittest.TestCase):
|
||||
os.unlink(db_path)
|
||||
self.assertFalse(os.access("/tmp/jcl.pid", os.F_OK))
|
||||
self.assertEquals(self.i, 2)
|
||||
|
||||
|
||||
def test__get_help(self):
|
||||
self.assertNotEquals(self.runner._get_help(), None)
|
||||
|
||||
|
||||
def suite():
|
||||
test_suite = unittest.TestSuite()
|
||||
test_suite.addTest(unittest.makeSuite(JCLRunner_TestCase, 'test'))
|
||||
@@ -172,4 +185,3 @@ def suite():
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='suite')
|
||||
|
||||
|
||||
19
src/jcl/tests/uncomplete_jcl.conf
Normal file
19
src/jcl/tests/uncomplete_jcl.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
[jabber]
|
||||
server: test_localhost
|
||||
port: 42
|
||||
secret: test_secret
|
||||
service_jid: test_jcl.localhost
|
||||
#supported language: en, fr (See src/jmc/lang.py to add more)
|
||||
language: test_en
|
||||
|
||||
[db]
|
||||
#type: mysql
|
||||
type: test_sqlite
|
||||
#host: root@localhost
|
||||
host: root@localhost
|
||||
name: /var/spool/jabber/test_jcl.db
|
||||
#url: %(type)%(host)%(name)?debug=1&debugThreading=1
|
||||
db_url: %(type)s://%(host)s%(name)s
|
||||
|
||||
[component]
|
||||
log_file: /tmp/jcl.log
|
||||
Reference in New Issue
Block a user