From 924888ed7c8a953d427517bbd6bc3ae4dcd2e27b Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 20 Mar 2013 22:53:00 -0500 Subject: add some tests for options within ini files --- pyramid/paster.py | 12 ++++++++++-- pyramid/tests/fixtures/dummy.ini | 4 ++++ pyramid/tests/test_paster.py | 32 ++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 pyramid/tests/fixtures/dummy.ini diff --git a/pyramid/paster.py b/pyramid/paster.py index edc0d406f..967543849 100644 --- a/pyramid/paster.py +++ b/pyramid/paster.py @@ -24,7 +24,11 @@ def get_app(config_uri, name=None, options=None, loadapp=loadapp): config_name = 'config:%s' % path here_dir = os.getcwd() - app = loadapp(config_name, name=section, relative_to=here_dir, global_conf=options) + app = loadapp( + config_name, + name=section, + relative_to=here_dir, + global_conf=options) return app @@ -42,7 +46,11 @@ def get_appsettings(config_uri, name=None, options=None, appconfig=appconfig): path, section = _getpathsec(config_uri, name) config_name = 'config:%s' % path here_dir = os.getcwd() - return appconfig(config_name, name=section, relative_to=here_dir, global_conf=options) + return appconfig( + config_name, + name=section, + relative_to=here_dir, + global_conf=options) def setup_logging(config_uri, fileConfig=fileConfig, configparser=configparser): diff --git a/pyramid/tests/fixtures/dummy.ini b/pyramid/tests/fixtures/dummy.ini new file mode 100644 index 000000000..bc2281168 --- /dev/null +++ b/pyramid/tests/fixtures/dummy.ini @@ -0,0 +1,4 @@ +[app:myapp] +use = call:pyramid.tests.test_paster:make_dummyapp + +foo = %(bar)s diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py index 7c9243e9d..5e341172c 100644 --- a/pyramid/tests/test_paster.py +++ b/pyramid/tests/test_paster.py @@ -1,12 +1,12 @@ import os import unittest +here = os.path.dirname(__file__) + class Test_get_app(unittest.TestCase): - def _callFUT(self, config_file, section_name, options=None, loadapp=None): + def _callFUT(self, config_file, section_name, **kw): from pyramid.paster import get_app - return get_app( - config_file, section_name, options=options, loadapp=loadapp - ) + return get_app(config_file, section_name, **kw) def test_it(self): app = DummyApp() @@ -55,10 +55,17 @@ class Test_get_app(unittest.TestCase): self.assertEqual(loadapp.kw, {'global_conf':options}) self.assertEqual(result, app) + def test_it_with_dummyapp_requiring_options(self): + options = {'bar': 'baz'} + app = self._callFUT( + os.path.join(here, 'fixtures', 'dummy.ini'), + 'myapp', options=options) + self.assertEqual(app.settings['foo'], 'baz') + class Test_get_appsettings(unittest.TestCase): - def _callFUT(self, config_file, section_name, options=None, appconfig=None): + def _callFUT(self, config_file, section_name, **kw): from pyramid.paster import get_appsettings - return get_appsettings(config_file, section_name, options, appconfig) + return get_appsettings(config_file, section_name, **kw) def test_it(self): values = {'a':1} @@ -90,6 +97,13 @@ class Test_get_appsettings(unittest.TestCase): self.assertEqual(appconfig.relative_to, os.getcwd()) self.assertEqual(result, values) + def test_it_with_dummyapp_requiring_options(self): + options = {'bar': 'baz'} + result = self._callFUT( + os.path.join(here, 'fixtures', 'dummy.ini'), + 'myapp', options=options) + self.assertEqual(result['foo'], 'baz') + class Test_setup_logging(unittest.TestCase): def _callFUT(self, config_file): from pyramid.paster import setup_logging @@ -168,6 +182,12 @@ class DummyApp: def __init__(self): self.registry = dummy_registry +def make_dummyapp(global_conf, **settings): + app = DummyApp() + app.settings = settings + app.global_conf = global_conf + return app + class DummyRequest: application_url = 'http://example.com:5432' script_name = '' -- cgit v1.2.3