diff options
author | Chris Dent <chris.dent@gmail.com> | 2018-11-21 20:30:27 +0000 |
---|---|---|
committer | Chris Dent <chris.dent@gmail.com> | 2018-11-21 20:30:27 +0000 |
commit | 9cbc584a86bd1ae425bd0c0c3c00617d7e59475d (patch) | |
tree | 26a91b060f6fde552674dcf2b26f0ca2e4e901aa | |
parent | df1431cb1b62a93e6306725de4b303375c3044ae (diff) | |
parent | 7b5a71096c7a2815d46d05db9ce3cdc4d88d2fbb (diff) | |
download | pastedeploy-git-9cbc584a86bd1ae425bd0c0c3c00617d7e59475d.tar.gz |
Merged in aodag/pastedeploy-fix17/fix-17 (pull request #11)
fix paste_deploy paster template for python3
-rw-r--r-- | paste/deploy/loadwsgi.py | 10 | ||||
-rw-r--r-- | pytest.ini | 3 | ||||
-rw-r--r-- | tests/sample_configs/test_filter.ini | 4 | ||||
-rw-r--r-- | tests/test_config.py | 66 | ||||
-rw-r--r-- | tests/test_config_middleware.py | 5 | ||||
-rw-r--r-- | tests/test_filter.py | 10 | ||||
-rw-r--r-- | tox.ini | 7 |
7 files changed, 63 insertions, 42 deletions
diff --git a/paste/deploy/loadwsgi.py b/paste/deploy/loadwsgi.py index fc766b0..9f3dd0e 100644 --- a/paste/deploy/loadwsgi.py +++ b/paste/deploy/loadwsgi.py @@ -19,7 +19,13 @@ __all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig'] def import_string(s): - return pkg_resources.EntryPoint.parse("x=" + s).load(False) + ep = pkg_resources.EntryPoint.parse("x=" + s) + if hasattr(ep, 'resolve'): + # this is available on setuptools >= 10.2 + return ep.resolve() + else: + # this causes a DeprecationWarning on setuptools >= 11.3 + return ep.load(False) def _aslist(obj): @@ -551,7 +557,7 @@ class ConfigLoader(_Loader): raise LookupError( "The [%s] pipeline section in %s has extra " "(disallowed) settings: %s" - % (', '.join(local_conf.keys()))) + % (section, self.filename, ', '.join(local_conf.keys()))) context = LoaderContext(None, PIPELINE, None, global_conf, local_conf, self) context.app_context = self.get_context( diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..69d62a0 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +addopts = --cov=paste/deploy --cov-report=xml --cov-report=html --cov-report=term-missing +testpaths = tests diff --git a/tests/sample_configs/test_filter.ini b/tests/sample_configs/test_filter.ini index bfad8dc..733c0aa 100644 --- a/tests/sample_configs/test_filter.ini +++ b/tests/sample_configs/test_filter.ini @@ -20,3 +20,7 @@ next = normal [app:inv] use = egg:FakeApp#basic_app filter-with = egg:FakeApp#caps + +[pipeline:piped3] +pipeline = egg:FakeApp#caps normal +extra_config_option = bad diff --git a/tests/test_config.py b/tests/test_config.py index f64dd21..3acbc5b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,5 +1,3 @@ -from nose.tools import eq_ - from paste.deploy import loadapp, appconfig from tests.fixture import * import fakeapp.configapps as fc @@ -19,29 +17,29 @@ def test_config_egg(): def test_config1(): app = loadapp(ini_file, relative_to=here, name='test1') - eq_(app.local_conf, { + assert app.local_conf == { 'setting1': 'foo', 'setting2': 'bar', - 'apppath': os.path.join(config_path, 'app')}) - eq_(app.global_conf, { + 'apppath': os.path.join(config_path, 'app')} + assert app.global_conf == { 'def1': 'a', 'def2': 'b', 'basepath': config_path, 'here': config_path, - '__file__': config_filename}) + '__file__': config_filename} def test_config2(): app = loadapp(ini_file, relative_to=here, name='test2') - eq_(app.local_conf, { - 'local conf': 'something'}) - eq_(app.global_conf, { + assert app.local_conf == { + 'local conf': 'something'} + assert app.global_conf == { 'def1': 'test2', 'def2': 'b', 'basepath': config_path, 'another': 'TEST', 'here': config_path, - '__file__': config_filename}) + '__file__': config_filename} # Run this to make sure the global-conf-modified test2 # didn't mess up the general global conf test_config1() @@ -50,16 +48,16 @@ def test_config2(): def test_config3(): app = loadapp(ini_file, relative_to=here, name='test3') assert isinstance(app, fc.SimpleApp) - eq_(app.local_conf, { + assert app.local_conf == { 'local conf': 'something', - 'another': 'something more\nacross several\nlines'}) - eq_(app.global_conf, { + 'another': 'something more\nacross several\nlines'} + assert app.global_conf == { 'def1': 'test3', 'def2': 'b', 'basepath': config_path, 'another': 'TEST', 'here': config_path, - '__file__': config_filename}) + '__file__': config_filename} test_config2() @@ -93,10 +91,10 @@ def test_composit(): def test_foreign_config(): app = loadapp(ini_file, relative_to=here, name='test_foreign_config') assert isinstance(app, fc.SimpleApp) - eq_(app.local_conf, { + assert app.local_conf == { 'another': 'FOO', - 'bob': 'your uncle'}) - eq_(app.global_conf, { + 'bob': 'your uncle'} + assert app.global_conf == { 'def1': 'a', # Note overwrite of DEFAULT value from foreign config 'def2': 'b', @@ -104,52 +102,52 @@ def test_foreign_config(): 'basepath': config_path, 'glob': 'override', 'here': config_path, - '__file__': os.path.join(config_path, 'test_config.ini')}) + '__file__': os.path.join(config_path, 'test_config.ini')} def test_config_get(): app = loadapp(ini_file, relative_to=here, name='test_get') assert isinstance(app, fc.SimpleApp) - eq_(app.local_conf, { + assert app.local_conf == { 'def1': 'a', - 'foo': 'TEST'}) - eq_(app.global_conf, { + 'foo': 'TEST'} + assert app.global_conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, - '__file__': config_filename}) + '__file__': config_filename} def test_appconfig(): conf = appconfig(ini_file, relative_to=here, name='test_get') - eq_(conf, { + assert conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, '__file__': config_filename, - 'foo': 'TEST'}) - eq_(conf.local_conf, { + 'foo': 'TEST'} + assert conf.local_conf == { 'def1': 'a', - 'foo': 'TEST'}) - eq_(conf.global_conf, { + 'foo': 'TEST'} + assert conf.global_conf == { 'def1': 'a', 'def2': 'TEST', 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, - '__file__': config_filename}) + '__file__': config_filename} def test_appconfig_filter_with(): conf = appconfig('config:test_filter_with.ini', relative_to=config_path) - eq_(conf['example'], 'test') + assert conf['example'] == 'test' def test_global_conf(): conf = appconfig(ini_file, relative_to=here, name='test_global_conf', global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'}) - eq_(conf, { + assert conf == { 'def1': 'a', # Note overwrite of DEFAULT value 'def2': 'TEST DEF 2', @@ -158,9 +156,9 @@ def test_global_conf(): 'inherit': 'bazbar', '__file__': config_filename, 'test_interp': 'this:bazbar', - }) - eq_(conf.local_conf, { - 'test_interp': 'this:bazbar'}) + } + assert conf.local_conf == { + 'test_interp': 'this:bazbar'} def test_interpolate_exception(): @@ -169,6 +167,6 @@ def test_interpolate_exception(): except Exception: e = sys.exc_info()[1] expected = "Error in file %s" % os.path.join(config_path, 'test_error.ini') - eq_(str(e).split(':')[0], expected) + assert str(e).split(':')[0] == expected else: assert False, 'Should have raised an exception' diff --git a/tests/test_config_middleware.py b/tests/test_config_middleware.py index 28b8b72..56c3d04 100644 --- a/tests/test_config_middleware.py +++ b/tests/test_config_middleware.py @@ -1,5 +1,4 @@ -from nose.tools import assert_raises -from nose.plugins.skip import SkipTest +import pytest from paste.deploy.config import ConfigMiddleware @@ -25,4 +24,4 @@ def test_error(): wrapped = ConfigMiddleware(app_with_exception, {'test': 1}) test_app = TestApp(wrapped) - assert_raises(Bug, test_app.get, '/') + pytest.raises(Bug, test_app.get, '/') diff --git a/tests/test_filter.py b/tests/test_filter.py index a76af7c..470a9dd 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -51,3 +51,13 @@ def test_filter_with_filter_with(): assert isinstance(app, fakeapp.apps.CapFilter) assert isinstance(app.app, fakeapp.apps.CapFilter) assert app.app.app is fakeapp.apps.basic_app + + +def test_bad_pipeline(): + try: + app = loadapp('config:sample_configs/test_filter.ini#piped3', + relative_to=here) + except LookupError as err: + assert 'has extra (disallowed) settings' in err.args[0] + else: + assert False, 'should have raised LookupError' @@ -3,8 +3,9 @@ envlist = py26, py27, py33, py34, py35, pypy [testenv] deps = - nose # Paste works on Python 3 since Paste 2.0 Paste -commands = {envpython} setup.py test - + pytest + pytest-cov +commands = + py.test {posargs} |