summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Deza <alfredodeza@gmail.com>2013-01-22 22:38:51 -0500
committerAlfredo Deza <alfredodeza@gmail.com>2013-01-22 22:38:51 -0500
commitb91e4fad59387051b8a71900412302adeb8acbb5 (patch)
treed77955d68b98dce34802f9eb346d1ce67580acb3
parentd18b7266087fa595efa9e7e973d8232fb5b74f34 (diff)
downloadpecan-b91e4fad59387051b8a71900412302adeb8acbb5.tar.gz
a bunch of tests for the env var support
-rw-r--r--pecan/tests/test_conf.py46
1 files changed, 42 insertions, 4 deletions
diff --git a/pecan/tests/test_conf.py b/pecan/tests/test_conf.py
index 4b276cb..5aad67f 100644
--- a/pecan/tests/test_conf.py
+++ b/pecan/tests/test_conf.py
@@ -110,7 +110,7 @@ class TestConf(TestCase):
from pecan import configuration
path = ('doesnotexist.py',)
configuration.Config({})
- self.assertRaises(IOError, configuration.conf_from_file, os.path.join(
+ self.assertRaises(RuntimeError, configuration.conf_from_file, os.path.join(
__here__,
'config_fixtures',
*path
@@ -121,7 +121,7 @@ class TestConf(TestCase):
path = ('bad', 'bad', 'doesnotexist.py',)
configuration.Config({})
- self.assertRaises(IOError, configuration.conf_from_file, os.path.join(
+ self.assertRaises(RuntimeError, configuration.conf_from_file, os.path.join(
__here__,
'config_fixtures',
*path
@@ -274,6 +274,44 @@ class TestGlobalConfig(TestCase):
)
assert dict(configuration._runtime_conf) == {'foo': 'bar'}
- def test_set_config_invalid_type(self):
+ def test_set_config_none_type(self):
from pecan import configuration
- self.assertRaises(TypeError, configuration.set_config, None)
+ self.assertRaises(RuntimeError, configuration.set_config, None)
+
+ def test_set_config_to_dir(self):
+ from pecan import configuration
+ self.assertRaises(RuntimeError, configuration.set_config, '/')
+
+
+class TestConfFromEnv(TestCase):
+
+ def setUp(self):
+ self.conf_from_env = self.get_conf_from_env()
+ os.environ['PECAN_CONFIG'] = ''
+
+ def get_conf_from_env(self):
+ from pecan import configuration
+ return configuration.conf_from_env
+
+ def assertRaisesMessage(self, msg, exc, func, *args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ self.assertFail()
+ except Exception as error:
+ assert issubclass(exc, error.__class__)
+ assert error.message == msg
+
+ def test_invalid_path(self):
+ os.environ['PECAN_CONFIG'] = '/'
+ msg = "PECAN_CONFIG was set to an invalid path: /"
+ self.assertRaisesMessage(msg, RuntimeError, self.conf_from_env)
+
+ def test_is_not_set(self):
+ msg = "PECAN_CONFIG is not set and " \
+ "no config file was passed as an argument."
+ self.assertRaisesMessage(msg, RuntimeError, self.conf_from_env)
+
+ def test_return_valid_path(self):
+ here = os.path.abspath(__file__)
+ os.environ['PECAN_CONFIG'] = here
+ assert self.conf_from_env() == here