diff options
author | Michael Merickel <michael@merickel.org> | 2022-05-15 21:09:16 -0500 |
---|---|---|
committer | Michael Merickel <michael@merickel.org> | 2022-05-15 21:23:28 -0500 |
commit | 32fb766fa01d436b98e7687f717f6e71c58b9a83 (patch) | |
tree | 2fa125334fea9a1ebdbd5381f875368636462afc /tests | |
parent | ac91794dfb7617b473c9d06d04900debfcdf585e (diff) | |
download | pastedeploy-git-32fb766fa01d436b98e7687f717f6e71c58b9a83.tar.gz |
blackify/isort/flake8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 3 | ||||
-rw-r--r-- | tests/fake_packages/FakeApp.egg/fakeapp/apps.py | 16 | ||||
-rw-r--r-- | tests/fake_packages/FakeApp.egg/fakeapp/configapps.py | 4 | ||||
-rw-r--r-- | tests/fake_packages/FakeApp.egg/setup.py | 14 | ||||
-rw-r--r-- | tests/fixture.py | 17 | ||||
-rw-r--r-- | tests/test_basic_app.py | 24 | ||||
-rw-r--r-- | tests/test_config.py | 77 | ||||
-rw-r--r-- | tests/test_config_middleware.py | 1 | ||||
-rw-r--r-- | tests/test_converters.py | 3 | ||||
-rw-r--r-- | tests/test_filter.py | 28 | ||||
-rw-r--r-- | tests/test_load_package.py | 3 |
11 files changed, 98 insertions, 92 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index cffe526..b555435 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -5,8 +5,7 @@ here = os.path.dirname(__file__) base = os.path.dirname(here) sys.path.insert(0, base) -# We can only import this after we adjust the paths -import pkg_resources +import pkg_resources # noqa E402 # Make absolutely sure we're testing *this* package, not # some other installed package diff --git a/tests/fake_packages/FakeApp.egg/fakeapp/apps.py b/tests/fake_packages/FakeApp.egg/fakeapp/apps.py index 9ab5183..18bf478 100644 --- a/tests/fake_packages/FakeApp.egg/fakeapp/apps.py +++ b/tests/fake_packages/FakeApp.egg/fakeapp/apps.py @@ -2,26 +2,33 @@ ## Apps ############################################################ + def simple_app(response, environ, start_response): start_response('200 OK', [('Content-type', 'text/html')]) return ['This is ', response] + def basic_app(environ, start_response): return simple_app('basic app', environ, start_response) + def make_basic_app(global_conf, **conf): return basic_app + def basic_app2(environ, start_response): return simple_app('basic app2', environ, start_response) - + + def make_basic_app2(global_conf, **conf): return basic_app2 + ############################################################ ## Composits ############################################################ + def make_remote_addr(loader, global_conf, **conf): apps = {} addrs = {} @@ -35,6 +42,7 @@ def make_remote_addr(loader, global_conf, **conf): dispatcher.map[addrs[name]] = apps[name] return dispatcher + class RemoteAddrDispatch: def __init__(self, map=None): self.map = map or {} @@ -44,17 +52,20 @@ class RemoteAddrDispatch: app = self.map.get(addr) or self.map['0.0.0.0'] return app(environ, start_response) + ############################################################ ## Filters ############################################################ + def make_cap_filter(global_conf, method_to_call='upper'): def cap_filter(app): return CapFilter(app, global_conf, method_to_call) + return cap_filter -class CapFilter: +class CapFilter: def __init__(self, app, global_conf, method_to_call='upper'): self.app = app self.method_to_call = method_to_call @@ -66,4 +77,3 @@ class CapFilter: yield getattr(item, self.method_to_call)() if hasattr(app_iter, 'close'): app_iter.close() - diff --git a/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py b/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py index 8e125e8..078a4d6 100644 --- a/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py +++ b/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py @@ -7,8 +7,8 @@ class SimpleApp: def __call__(self, environ, start_response): start_response('200 OK', [('Content-type', 'text/html')]) return ['I am: ', name] - + def make_app(cls, global_conf, **conf): return cls(global_conf, conf, 'basic') - make_app = classmethod(make_app) + make_app = classmethod(make_app) diff --git a/tests/fake_packages/FakeApp.egg/setup.py b/tests/fake_packages/FakeApp.egg/setup.py index 854483e..9d34edb 100644 --- a/tests/fake_packages/FakeApp.egg/setup.py +++ b/tests/fake_packages/FakeApp.egg/setup.py @@ -1,23 +1,23 @@ -from setuptools import setup, find_packages +from setuptools import find_packages, setup setup( name="FakeApp", version="1.0", packages=find_packages(), entry_points={ - 'paste.app_factory': """ + 'paste.app_factory': """ basic_app=fakeapp.apps:make_basic_app other=fakeapp.apps:make_basic_app2 configed=fakeapp.configapps:SimpleApp.make_app """, - 'paste.composit_factory': """ + 'paste.composit_factory': """ remote_addr=fakeapp.apps:make_remote_addr """, - 'paste.filter_factory': """ + 'paste.filter_factory': """ caps=fakeapp.apps:make_cap_filter """, - 'paste.filter_app_factory': """ + 'paste.filter_app_factory': """ caps2=fakeapp.apps:CapFilter """, - }, - ) + }, +) diff --git a/tests/fixture.py b/tests/fixture.py index 751659d..6d92260 100644 --- a/tests/fixture.py +++ b/tests/fixture.py @@ -1,20 +1,19 @@ import os -import sys import shutil +import sys test_dir = os.path.dirname(__file__) -egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', - 'EGG-INFO') -info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', - 'FakeApp.egg-info') +egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO') +info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info') if not os.path.exists(egg_info_dir): try: os.symlink(info_dir, egg_info_dir) - except: + except Exception: shutil.copytree(info_dir, egg_info_dir) sys.path.append(os.path.dirname(egg_info_dir)) -from pkg_resources import * -working_set.add_entry(os.path.dirname(egg_info_dir)) -require('FakeApp') +import pkg_resources # noqa E402 + +pkg_resources.working_set.add_entry(os.path.dirname(egg_info_dir)) +pkg_resources.require('FakeApp') diff --git a/tests/test_basic_app.py b/tests/test_basic_app.py index 1ddb52b..53cf7f2 100644 --- a/tests/test_basic_app.py +++ b/tests/test_basic_app.py @@ -1,36 +1,32 @@ -from paste.deploy import loadapp +import os -from tests.fixture import * import fakeapp.apps +from paste.deploy import loadapp here = os.path.dirname(__file__) def test_main(): - app = loadapp('config:sample_configs/basic_app.ini', - relative_to=here) + app = loadapp('config:sample_configs/basic_app.ini', relative_to=here) assert app is fakeapp.apps.basic_app - app = loadapp('config:sample_configs/basic_app.ini#main', - relative_to=here) + app = loadapp('config:sample_configs/basic_app.ini#main', relative_to=here) assert app is fakeapp.apps.basic_app - app = loadapp('config:sample_configs/basic_app.ini', - relative_to=here, name='main') + app = loadapp('config:sample_configs/basic_app.ini', relative_to=here, name='main') assert app is fakeapp.apps.basic_app - app = loadapp('config:sample_configs/basic_app.ini#ignored', - relative_to=here, name='main') + app = loadapp( + 'config:sample_configs/basic_app.ini#ignored', relative_to=here, name='main' + ) assert app is fakeapp.apps.basic_app def test_other(): - app = loadapp('config:sample_configs/basic_app.ini#other', - relative_to=here) + app = loadapp('config:sample_configs/basic_app.ini#other', relative_to=here) assert app is fakeapp.apps.basic_app2 def test_composit(): - app = loadapp('config:sample_configs/basic_app.ini#remote_addr', - relative_to=here) + app = loadapp('config:sample_configs/basic_app.ini#remote_addr', relative_to=here) assert isinstance(app, fakeapp.apps.RemoteAddrDispatch) assert app.map['127.0.0.1'] is fakeapp.apps.basic_app assert app.map['0.0.0.0'] is fakeapp.apps.basic_app2 diff --git a/tests/test_config.py b/tests/test_config.py index 3acbc5b..33eb808 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,8 +1,10 @@ -from paste.deploy import loadapp, appconfig -from tests.fixture import * -import fakeapp.configapps as fc +import os +import sys + import fakeapp.apps +import fakeapp.configapps as fc +from paste.deploy import appconfig, loadapp ini_file = 'config:sample_configs/test_config.ini' here = os.path.dirname(__file__) @@ -20,26 +22,28 @@ def test_config1(): assert app.local_conf == { 'setting1': 'foo', 'setting2': 'bar', - 'apppath': os.path.join(config_path, 'app')} + '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') - assert app.local_conf == { - 'local conf': 'something'} + 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,29 +54,27 @@ def test_config3(): assert isinstance(app, fc.SimpleApp) assert app.local_conf == { 'local conf': 'something', - 'another': 'something more\nacross several\nlines'} + '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() def test_main(): - app = loadapp('config:test_func.ini', - relative_to=config_path) + app = loadapp('config:test_func.ini', relative_to=config_path) assert app is fakeapp.apps.basic_app - app = loadapp('config:test_func.ini#main', - relative_to=config_path) + app = loadapp('config:test_func.ini#main', relative_to=config_path) assert app is fakeapp.apps.basic_app - app = loadapp('config:test_func.ini', - relative_to=config_path, name='main') + app = loadapp('config:test_func.ini', relative_to=config_path, name='main') assert app is fakeapp.apps.basic_app - app = loadapp('config:test_func.ini#ignored', - relative_to=config_path, name='main') + app = loadapp('config:test_func.ini#ignored', relative_to=config_path, name='main') assert app is fakeapp.apps.basic_app @@ -91,9 +93,7 @@ def test_composit(): def test_foreign_config(): app = loadapp(ini_file, relative_to=here, name='test_foreign_config') assert isinstance(app, fc.SimpleApp) - assert app.local_conf == { - 'another': 'FOO', - 'bob': 'your uncle'} + assert app.local_conf == {'another': 'FOO', 'bob': 'your uncle'} assert app.global_conf == { 'def1': 'a', # Note overwrite of DEFAULT value from foreign config @@ -102,21 +102,21 @@ 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) - assert app.local_conf == { - 'def1': 'a', - 'foo': 'TEST'} + assert app.local_conf == {'def1': 'a', '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(): @@ -127,16 +127,16 @@ def test_appconfig(): 'basepath': os.path.join(here, 'sample_configs'), 'here': config_path, '__file__': config_filename, - 'foo': 'TEST'} - assert conf.local_conf == { - 'def1': 'a', - 'foo': 'TEST'} + 'foo': 'TEST', + } + assert conf.local_conf == {'def1': 'a', '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(): @@ -145,8 +145,12 @@ def test_appconfig_filter_with(): def test_global_conf(): - conf = appconfig(ini_file, relative_to=here, name='test_global_conf', - global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'}) + conf = appconfig( + ini_file, + relative_to=here, + name='test_global_conf', + global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'}, + ) assert conf == { 'def1': 'a', # Note overwrite of DEFAULT value @@ -156,9 +160,8 @@ def test_global_conf(): 'inherit': 'bazbar', '__file__': config_filename, 'test_interp': 'this:bazbar', - } - assert conf.local_conf == { - 'test_interp': 'this:bazbar'} + } + assert conf.local_conf == {'test_interp': 'this:bazbar'} def test_interpolate_exception(): @@ -169,4 +172,4 @@ def test_interpolate_exception(): expected = "Error in file %s" % os.path.join(config_path, 'test_error.ini') assert str(e).split(':')[0] == expected else: - assert False, 'Should have raised an exception' + raise AssertionError('Should have raised an exception') diff --git a/tests/test_config_middleware.py b/tests/test_config_middleware.py index 52ba7d1..519837e 100644 --- a/tests/test_config_middleware.py +++ b/tests/test_config_middleware.py @@ -11,6 +11,7 @@ def app_with_exception(environ, start_response): def cont(): yield b"something" raise Bug + start_response('200 OK', [('Content-type', 'text/html')]) return cont() diff --git a/tests/test_converters.py b/tests/test_converters.py index 5361310..887ae32 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -1,5 +1,6 @@ def test_asbool_truthy(): from paste.deploy.converters import asbool + assert asbool('true') assert asbool('yes') assert asbool('on') @@ -7,8 +8,10 @@ def test_asbool_truthy(): assert asbool('t') assert asbool('1') + def test_asbool_falsy(): from paste.deploy.converters import asbool + assert not asbool('false') assert not asbool('no') assert not asbool('off') diff --git a/tests/test_filter.py b/tests/test_filter.py index 470a9dd..6a4a69a 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,53 +1,48 @@ -from paste.deploy import loadapp -from tests.fixture import * +import os + import fakeapp.apps +from paste.deploy import loadapp here = os.path.dirname(__file__) def test_filter_app(): - app = loadapp('config:sample_configs/test_filter.ini#filt', - relative_to=here) + app = loadapp('config:sample_configs/test_filter.ini#filt', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'lower' def test_pipeline(): - app = loadapp('config:sample_configs/test_filter.ini#piped', - relative_to=here) + app = loadapp('config:sample_configs/test_filter.ini#piped', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'upper' def test_filter_app2(): - app = loadapp('config:sample_configs/test_filter.ini#filt2', - relative_to=here) + app = loadapp('config:sample_configs/test_filter.ini#filt2', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'lower' def test_pipeline2(): - app = loadapp('config:sample_configs/test_filter.ini#piped2', - relative_to=here) + app = loadapp('config:sample_configs/test_filter.ini#piped2', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app assert app.method_to_call == 'upper' def test_filter_app_inverted(): - app = loadapp('config:sample_configs/test_filter.ini#inv', - relative_to=here) + app = loadapp('config:sample_configs/test_filter.ini#inv', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert app.app is fakeapp.apps.basic_app def test_filter_with_filter_with(): - app = loadapp('config:sample_configs/test_filter_with.ini', - relative_to=here) + app = loadapp('config:sample_configs/test_filter_with.ini', relative_to=here) assert isinstance(app, fakeapp.apps.CapFilter) assert isinstance(app.app, fakeapp.apps.CapFilter) assert app.app.app is fakeapp.apps.basic_app @@ -55,9 +50,8 @@ def test_filter_with_filter_with(): def test_bad_pipeline(): try: - app = loadapp('config:sample_configs/test_filter.ini#piped3', - relative_to=here) + 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' + raise AssertionError('should have raised LookupError') diff --git a/tests/test_load_package.py b/tests/test_load_package.py index 6ba1ad4..bdd6e3f 100644 --- a/tests/test_load_package.py +++ b/tests/test_load_package.py @@ -1,7 +1,8 @@ from pprint import pprint -import pkg_resources import sys +import pkg_resources + def test_load_package(): print('Path:') |