Permalink
Browse files

add some tests for options within ini files

  • Loading branch information...
1 parent ea1f057 commit 924888ed7c8a953d427517bbd6bc3ae4dcd2e27b @mmerickel mmerickel committed Mar 21, 2013
Showing with 40 additions and 8 deletions.
  1. +10 −2 pyramid/paster.py
  2. +4 −0 pyramid/tests/fixtures/dummy.ini
  3. +26 −6 pyramid/tests/test_paster.py
View
@@ -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):
@@ -0,0 +1,4 @@
+[app:myapp]
+use = call:pyramid.tests.test_paster:make_dummyapp
+
+foo = %(bar)s
@@ -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 @@ def test_it_with_options(self):
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 @@ def test_it_with_hash_and_name_override(self):
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 = ''

0 comments on commit 924888e

Please sign in to comment.