better error handling for errors during conf import

This commit is contained in:
Mark McClain
2011-03-06 10:44:39 -05:00
parent 0b52a1c723
commit 5bfef3a9dd
4 changed files with 7 additions and 8 deletions

View File

@@ -110,17 +110,10 @@ def import_module(conf):
try:
module = __import__(name, fromlist=fromlist)
conf_mod = getattr(module, parts[-1])
except ImportError, e:
raise ImportError('No module named %s' % conf)
except AttributeError, e:
raise ImportError('No module named %s' % conf)
else:
name = conf
try:
conf_mod = __import__(name)
except ImportError, e:
raise ImportError('No module named %s' % conf)
conf_mod = __import__(conf)
return conf_mod

View File

@@ -101,6 +101,8 @@ class TestConf(TestCase):
self.assertRaises(ImportError, conf.update_with_module, 'doesnotexist')
self.assertRaises(ImportError, conf.update_with_module, 'bad.doesnotexists')
self.assertRaises(ImportError, conf.update_with_module, 'bad.bad.doesnotexist')
self.assertRaises(SyntaxError, conf.update_with_module, 'bad.syntaxerror')
self.assertRaises(ImportError, conf.update_with_module, 'bad.importerror')
def test_config_set_from_file(self):
path = os.path.join(os.path.dirname(__file__), 'test_config', 'empty.py')

View File

@@ -0,0 +1 @@
import pecan.thismoduledoesnotexist

View File

@@ -0,0 +1,3 @@
if false
var = 3