From ba57f104ffd74fa707c7f6ddc03dfb1630dd212e Mon Sep 17 00:00:00 2001 From: Ulrich Petri Date: Sat, 24 Nov 2012 14:53:06 +0100 Subject: [PATCH 1/2] Switched config file loading to import lib to allow dotted "paths" to settings modules --- rq/scripts/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rq/scripts/__init__.py b/rq/scripts/__init__.py index d02f26d..94441ab 100644 --- a/rq/scripts/__init__.py +++ b/rq/scripts/__init__.py @@ -1,3 +1,4 @@ +import importlib import redis from rq import use_connection @@ -19,7 +20,7 @@ def add_standard_arguments(parser): def read_config_file(module): """Reads all UPPERCASE variables defined in the given module file.""" - settings = __import__(module, [], [], [], -1) + settings = importlib.import_module(module) return dict([(k, v) for k, v in settings.__dict__.items() if k.upper() == k]) From 43038d3150b3ec47abfbc55b2c843bf1d30489e3 Mon Sep 17 00:00:00 2001 From: Ulrich Petri Date: Sat, 24 Nov 2012 14:53:22 +0100 Subject: [PATCH 2/2] Added tests for config file loading --- tests/dummy_settings.py | 1 + tests/test_scripts.py | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/dummy_settings.py create mode 100644 tests/test_scripts.py diff --git a/tests/dummy_settings.py b/tests/dummy_settings.py new file mode 100644 index 0000000..1404250 --- /dev/null +++ b/tests/dummy_settings.py @@ -0,0 +1 @@ +REDIS_HOST = "testhost.example.com" diff --git a/tests/test_scripts.py b/tests/test_scripts.py new file mode 100644 index 0000000..de266ef --- /dev/null +++ b/tests/test_scripts.py @@ -0,0 +1,8 @@ +from unittest import TestCase +from rq.scripts import read_config_file + +class TestScripts(TestCase): + def test_config_file(self): + settings = read_config_file("tests.dummy_settings") + self.assertIn("REDIS_HOST", settings) + self.assertEqual(settings['REDIS_HOST'], "testhost.example.com")