Michael Merickel
2013-03-21 924888ed7c8a953d427517bbd6bc3ae4dcd2e27b
add some tests for options within ini files
1 files added
2 files modified
48 ■■■■ changed files
pyramid/paster.py 12 ●●●● patch | view | raw | blame | history
pyramid/tests/fixtures/dummy.ini 4 ●●●● patch | view | raw | blame | history
pyramid/tests/test_paster.py 32 ●●●● patch | view | raw | blame | history
pyramid/paster.py
@@ -24,7 +24,11 @@
    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 @@
    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):
pyramid/tests/fixtures/dummy.ini
New file
@@ -0,0 +1,4 @@
[app:myapp]
use = call:pyramid.tests.test_paster:make_dummyapp
foo = %(bar)s
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 @@
        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}
@@ -89,6 +96,13 @@
        self.assertEqual(appconfig.section_name, 'yourapp')
        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):
@@ -168,6 +182,12 @@
    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 = ''