summaryrefslogtreecommitdiff
path: root/tests/test_scripts
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-10-15 01:55:54 -0500
committerMichael Merickel <michael@merickel.org>2018-10-15 09:24:07 -0500
commit0c29cf2df41600d3906d521c72991c7686018b71 (patch)
treeff907f90ec9467e12874c9b2c961549d0e7caf74 /tests/test_scripts
parent851c368e3c158e264358de10446f5b5de240e534 (diff)
downloadpyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.gz
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.bz2
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.zip
format source using black
Diffstat (limited to 'tests/test_scripts')
-rw-r--r--tests/test_scripts/dummy.py44
-rw-r--r--tests/test_scripts/test_common.py3
-rw-r--r--tests/test_scripts/test_pcreate.py212
-rw-r--r--tests/test_scripts/test_pdistreport.py63
-rw-r--r--tests/test_scripts/test_prequest.py134
-rw-r--r--tests/test_scripts/test_proutes.py265
-rw-r--r--tests/test_scripts/test_pserve.py70
-rw-r--r--tests/test_scripts/test_pshell.py269
-rw-r--r--tests/test_scripts/test_ptweens.py16
-rw-r--r--tests/test_scripts/test_pviews.py272
10 files changed, 858 insertions, 490 deletions
diff --git a/tests/test_scripts/dummy.py b/tests/test_scripts/dummy.py
index f1ef403f8..69e69a280 100644
--- a/tests/test_scripts/dummy.py
+++ b/tests/test_scripts/dummy.py
@@ -3,21 +3,28 @@ class DummyTweens(object):
self._implicit = implicit
self.explicit = explicit
self.name_to_alias = {}
+
def implicit(self):
return self._implicit
+
class Dummy:
pass
+
dummy_root = Dummy()
+
class DummyRegistry(object):
settings = {}
+
def queryUtility(self, iface, default=None, name=''):
return default
+
dummy_registry = DummyRegistry()
+
class DummyShell(object):
env = {}
help = ''
@@ -30,15 +37,18 @@ class DummyShell(object):
self.called = True
self.env['request'].dummy_attr = self.dummy_attr
+
class DummyInteractor:
def __call__(self, banner, local):
self.banner = banner
self.local = local
+
class DummyApp:
def __init__(self):
self.registry = dummy_registry
+
class DummyMapper(object):
def __init__(self, *routes):
self.routes = routes
@@ -46,9 +56,11 @@ class DummyMapper(object):
def get_routes(self, include_static=False):
return self.routes
+
class DummyRoute(object):
- def __init__(self, name, pattern, factory=None,
- matchdict=None, predicate=None):
+ def __init__(
+ self, name, pattern, factory=None, matchdict=None, predicate=None
+ ):
self.name = name
self.path = pattern
self.pattern = pattern
@@ -61,35 +73,50 @@ class DummyRoute(object):
def match(self, route):
return self.matchdict
+
class DummyRequest:
application_url = 'http://example.com:5432'
script_name = ''
+
def __init__(self, environ):
self.environ = environ
self.matchdict = {}
+
class DummyView(object):
def __init__(self, **attrs):
self.__request_attrs__ = attrs
- def view(context, request): pass
+ def view(context, request):
+ pass
+
from zope.interface import implementer
from pyramid.interfaces import IMultiView
+
+
@implementer(IMultiView)
class DummyMultiView(object):
-
def __init__(self, *views, **attrs):
self.views = [(None, view, None) for view in views]
self.__request_attrs__ = attrs
+
class DummyCloser(object):
def __call__(self):
self.called = True
+
class DummyBootstrap(object):
- def __init__(self, app=None, registry=None, request=None, root=None,
- root_factory=None, closer=None):
+ def __init__(
+ self,
+ app=None,
+ registry=None,
+ request=None,
+ root=None,
+ root_factory=None,
+ closer=None,
+ ):
self.app = app or DummyApp()
if registry is None:
registry = DummyRegistry()
@@ -150,7 +177,9 @@ class dummy_setup_logging(object):
class DummyLoader(object):
- def __init__(self, settings=None, app_settings=None, app=None, server=None):
+ def __init__(
+ self, settings=None, app_settings=None, app=None, server=None
+ ):
if not settings:
settings = {}
if not app_settings:
@@ -163,6 +192,7 @@ class DummyLoader(object):
def __call__(self, uri):
import plaster
+
self.uri = plaster.parse_uri(uri)
return self
diff --git a/tests/test_scripts/test_common.py b/tests/test_scripts/test_common.py
index 60741db92..e286d3c3e 100644
--- a/tests/test_scripts/test_common.py
+++ b/tests/test_scripts/test_common.py
@@ -1,13 +1,16 @@
import unittest
+
class TestParseVars(unittest.TestCase):
def test_parse_vars_good(self):
from pyramid.scripts.common import parse_vars
+
vars = ['a=1', 'b=2']
result = parse_vars(vars)
self.assertEqual(result, {'a': '1', 'b': '2'})
def test_parse_vars_bad(self):
from pyramid.scripts.common import parse_vars
+
vars = ['a']
self.assertRaises(ValueError, parse_vars, vars)
diff --git a/tests/test_scripts/test_pcreate.py b/tests/test_scripts/test_pcreate.py
index 0286614ce..6ac082b41 100644
--- a/tests/test_scripts/test_pcreate.py
+++ b/tests/test_scripts/test_pcreate.py
@@ -4,6 +4,7 @@ import unittest
class TestPCreateCommand(unittest.TestCase):
def setUp(self):
from pyramid.compat import NativeIO
+
self.out_ = NativeIO()
def out(self, msg):
@@ -11,6 +12,7 @@ class TestPCreateCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.pcreate import PCreateCommand
+
return PCreateCommand
def _makeOne(self, *args, **kw):
@@ -46,8 +48,9 @@ class TestPCreateCommand(unittest.TestCase):
result = cmd.run()
self.assertEqual(result, 2)
out = self.out_.getvalue()
- self.assertTrue(out.count(
- 'You must provide at least one scaffold name'))
+ self.assertTrue(
+ out.count('You must provide at least one scaffold name')
+ )
def test_no_project_name(self):
cmd = self._makeOne('-s', 'dummy')
@@ -65,6 +68,7 @@ class TestPCreateCommand(unittest.TestCase):
def test_known_scaffold_single_rendered(self):
import os
+
cmd = self._makeOne('-s', 'dummy', 'Distro')
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
@@ -73,17 +77,25 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro')),
+ )
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_scaffold_with_package_name(self):
import os
- cmd = self._makeOne('-s', 'dummy', '--package-name', 'dummy_package',
- 'Distro')
+
+ cmd = self._makeOne(
+ '-s', 'dummy', '--package-name', 'dummy_package', 'Distro'
+ )
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
cmd.pyramid_dist = DummyDist("0.1")
@@ -92,17 +104,22 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro')),
+ )
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'dummy_package',
- 'package': 'dummy_package', 'pyramid_version': '0.1',
- 'pyramid_docs_branch':'0.1-branch'})
-
+ {
+ 'project': 'Distro',
+ 'egg': 'dummy_package',
+ 'package': 'dummy_package',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_scaffold_with_hyphen_in_project_name(self):
import os
+
cmd = self._makeOne('-s', 'dummy', 'Distro-')
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
@@ -111,15 +128,22 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro-'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro-')),
+ )
self.assertEqual(
scaffold.vars,
- {'project': 'Distro-', 'egg': 'Distro_', 'package': 'distro_',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
+ {
+ 'project': 'Distro-',
+ 'egg': 'Distro_',
+ 'package': 'distro_',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_known_scaffold_absolute_path(self):
import os
+
path = os.path.abspath('Distro')
cmd = self._makeOne('-s', 'dummy', path)
cmd.pyramid_dist = DummyDist("0.1")
@@ -130,15 +154,22 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro')),
+ )
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_known_scaffold_multiple_rendered(self):
import os
+
cmd = self._makeOne('-s', 'dummy1', '-s', 'dummy2', 'Distro')
scaffold1 = DummyScaffold('dummy1')
scaffold2 = DummyScaffold('dummy2')
@@ -148,23 +179,36 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold1.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro')),
+ )
self.assertEqual(
scaffold1.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
self.assertEqual(
scaffold2.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), 'Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), 'Distro')),
+ )
self.assertEqual(
scaffold2.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_known_scaffold_with_path_as_project_target_rendered(self):
import os
+
cmd = self._makeOne('-s', 'dummy', '/tmp/foo/Distro/')
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
@@ -173,13 +217,18 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.output_dir,
- os.path.normpath(os.path.join(os.getcwd(), '/tmp/foo/Distro'))
- )
+ os.path.normpath(os.path.join(os.getcwd(), '/tmp/foo/Distro')),
+ )
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.1', 'pyramid_docs_branch':'0.1-branch'})
-
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.1',
+ 'pyramid_docs_branch': '0.1-branch',
+ },
+ )
def test_scaffold_with_prod_pyramid_version(self):
cmd = self._makeOne('-s', 'dummy', 'Distro')
@@ -190,8 +239,14 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.2', 'pyramid_docs_branch':'0.2-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.2',
+ 'pyramid_docs_branch': '0.2-branch',
+ },
+ )
def test_scaffold_with_prod_pyramid_long_version(self):
cmd = self._makeOne('-s', 'dummy', 'Distro')
@@ -202,8 +257,14 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.2.1', 'pyramid_docs_branch':'0.2-branch'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.2.1',
+ 'pyramid_docs_branch': '0.2-branch',
+ },
+ )
def test_scaffold_with_prod_pyramid_unparsable_version(self):
cmd = self._makeOne('-s', 'dummy', 'Distro')
@@ -214,8 +275,14 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': 'abc', 'pyramid_docs_branch':'latest'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': 'abc',
+ 'pyramid_docs_branch': 'latest',
+ },
+ )
def test_scaffold_with_dev_pyramid_version(self):
cmd = self._makeOne('-s', 'dummy', 'Distro')
@@ -226,9 +293,14 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.12dev',
- 'pyramid_docs_branch': 'master'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.12dev',
+ 'pyramid_docs_branch': 'master',
+ },
+ )
def test_scaffold_with_dev_pyramid_long_version(self):
cmd = self._makeOne('-s', 'dummy', 'Distro')
@@ -239,16 +311,25 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Distro', 'egg': 'Distro', 'package': 'distro',
- 'pyramid_version': '0.10.1dev',
- 'pyramid_docs_branch': 'master'})
+ {
+ 'project': 'Distro',
+ 'egg': 'Distro',
+ 'package': 'distro',
+ 'pyramid_version': '0.10.1dev',
+ 'pyramid_docs_branch': 'master',
+ },
+ )
def test_confirm_override_conflicting_name(self):
from pyramid.scripts.pcreate import PCreateCommand
+
class YahInputPCreateCommand(PCreateCommand):
def confirm_bad_name(self, pkg_name):
return True
- cmd = self._makeOne('-s', 'dummy', 'Unittest', target_class=YahInputPCreateCommand)
+
+ cmd = self._makeOne(
+ '-s', 'dummy', 'Unittest', target_class=YahInputPCreateCommand
+ )
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
cmd.pyramid_dist = DummyDist("0.10.1dev")
@@ -256,12 +337,19 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Unittest', 'egg': 'Unittest', 'package': 'unittest',
- 'pyramid_version': '0.10.1dev',
- 'pyramid_docs_branch': 'master'})
+ {
+ 'project': 'Unittest',
+ 'egg': 'Unittest',
+ 'package': 'unittest',
+ 'pyramid_version': '0.10.1dev',
+ 'pyramid_docs_branch': 'master',
+ },
+ )
def test_force_override_conflicting_name(self):
- cmd = self._makeOne('-s', 'dummy', 'Unittest', '--ignore-conflicting-name')
+ cmd = self._makeOne(
+ '-s', 'dummy', 'Unittest', '--ignore-conflicting-name'
+ )
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
cmd.pyramid_dist = DummyDist("0.10.1dev")
@@ -269,16 +357,25 @@ class TestPCreateCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(
scaffold.vars,
- {'project': 'Unittest', 'egg': 'Unittest', 'package': 'unittest',
- 'pyramid_version': '0.10.1dev',
- 'pyramid_docs_branch': 'master'})
+ {
+ 'project': 'Unittest',
+ 'egg': 'Unittest',
+ 'package': 'unittest',
+ 'pyramid_version': '0.10.1dev',
+ 'pyramid_docs_branch': 'master',
+ },
+ )
def test_force_override_site_name(self):
from pyramid.scripts.pcreate import PCreateCommand
+
class NayInputPCreateCommand(PCreateCommand):
def confirm_bad_name(self, pkg_name):
return False
- cmd = self._makeOne('-s', 'dummy', 'Site', target_class=NayInputPCreateCommand)
+
+ cmd = self._makeOne(
+ '-s', 'dummy', 'Site', target_class=NayInputPCreateCommand
+ )
scaffold = DummyScaffold('dummy')
cmd.scaffolds = [scaffold]
cmd.pyramid_dist = DummyDist("0.10.1dev")
@@ -289,12 +386,14 @@ class TestPCreateCommand(unittest.TestCase):
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pcreate import main
+
return main(argv, quiet=True)
def test_it(self):
result = self._callFUT(['pcreate'])
self.assertEqual(result, 2)
+
class DummyScaffold(object):
def __init__(self, name):
self.name = name
@@ -304,6 +403,7 @@ class DummyScaffold(object):
self.output_dir = output_dir
self.vars = vars
+
class DummyDist(object):
def __init__(self, version):
self.version = version
diff --git a/tests/test_scripts/test_pdistreport.py b/tests/test_scripts/test_pdistreport.py
index e229667c5..031a6ff2b 100644
--- a/tests/test_scripts/test_pdistreport.py
+++ b/tests/test_scripts/test_pdistreport.py
@@ -1,57 +1,68 @@
import unittest
+
class TestPDistReportCommand(unittest.TestCase):
def _callFUT(self, **kw):
argv = []
from pyramid.scripts.pdistreport import main
+
return main(argv, **kw)
def test_no_dists(self):
def platform():
return 'myplatform'
+
pkg_resources = DummyPkgResources()
L = []
+
def out(*args):
L.extend(args)
- result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
- out=out)
+
+ result = self._callFUT(
+ pkg_resources=pkg_resources, platform=platform, out=out
+ )
self.assertEqual(result, None)
self.assertEqual(
L,
- ['Pyramid version:', '1',
- 'Platform:', 'myplatform',
- 'Packages:']
- )
+ ['Pyramid version:', '1', 'Platform:', 'myplatform', 'Packages:'],
+ )
def test_with_dists(self):
def platform():
return 'myplatform'
+
working_set = (DummyDistribution('abc'), DummyDistribution('def'))
pkg_resources = DummyPkgResources(working_set)
L = []
+
def out(*args):
L.extend(args)
- result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
- out=out)
+
+ result = self._callFUT(
+ pkg_resources=pkg_resources, platform=platform, out=out
+ )
self.assertEqual(result, None)
self.assertEqual(
L,
- ['Pyramid version:',
- '1',
- 'Platform:',
- 'myplatform',
- 'Packages:',
- ' ',
- 'abc',
- '1',
- ' ',
- '/projects/abc',
- ' ',
- 'def',
- '1',
- ' ',
- '/projects/def']
- )
+ [
+ 'Pyramid version:',
+ '1',
+ 'Platform:',
+ 'myplatform',
+ 'Packages:',
+ ' ',
+ 'abc',
+ '1',
+ ' ',
+ '/projects/abc',
+ ' ',
+ 'def',
+ '1',
+ ' ',
+ '/projects/def',
+ ],
+ )
+
class DummyPkgResources(object):
def __init__(self, working_set=()):
@@ -60,14 +71,14 @@ class DummyPkgResources(object):
def get_distribution(self, name):
return Version('1')
+
class Version(object):
def __init__(self, version):
self.version = version
+
class DummyDistribution(object):
def __init__(self, name):
self.project_name = name
self.version = '1'
self.location = '/projects/%s' % name
-
-
diff --git a/tests/test_scripts/test_prequest.py b/tests/test_scripts/test_prequest.py
index f7e656995..1521172bc 100644
--- a/tests/test_scripts/test_prequest.py
+++ b/tests/test_scripts/test_prequest.py
@@ -1,9 +1,11 @@
import unittest
from . import dummy
+
class TestPRequestCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.prequest import PRequestCommand
+
return PRequestCommand
def _makeOne(self, argv, headers=None):
@@ -14,6 +16,7 @@ class TestPRequestCommand(unittest.TestCase):
self._path_info = environ['PATH_INFO']
start_request('200 OK', headers or [])
return [b'abc']
+
self.loader = dummy.DummyLoader(app=helloworld)
self._out = []
cmd._get_config_loader = self.loader
@@ -26,11 +29,15 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_not_enough_args(self):
command = self._makeOne([])
command.run()
- self.assertEqual(self._out, ['You must provide at least two arguments'])
+ self.assertEqual(
+ self._out, ['You must provide at least two arguments']
+ )
def test_command_two_args(self):
- command = self._makeOne(['', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ command = self._makeOne(
+ ['', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._path_info, '/')
self.assertEqual(self.loader.uri.path, 'development.ini')
@@ -40,26 +47,31 @@ class TestPRequestCommand(unittest.TestCase):
self.assertEqual(self._out, ['abc'])
def test_command_path_doesnt_start_with_slash(self):
- command = self._makeOne(['', 'development.ini', 'abc'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ command = self._makeOne(
+ ['', 'development.ini', 'abc'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._path_info, '/abc')
self.assertEqual(self.loader.uri.path, 'development.ini')
self.assertEqual(self._out, ['abc'])
def test_command_has_bad_config_header(self):
- command = self._makeOne(
- ['', '--header=name','development.ini', '/'])
+ command = self._makeOne(['', '--header=name', 'development.ini', '/'])
command.run()
self.assertEqual(
self._out[0],
- ("Bad --header=name option, value must be in the form "
- "'name:value'"))
+ (
+ "Bad --header=name option, value must be in the form "
+ "'name:value'"
+ ),
+ )
def test_command_has_good_header_var(self):
command = self._makeOne(
- ['', '--header=name:value','development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ ['', '--header=name:value', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['HTTP_NAME'], 'value')
self.assertEqual(self._path_info, '/')
@@ -67,20 +79,28 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_w_basic_auth(self):
command = self._makeOne(
- ['', '--login=user:password',
- '--header=name:value','development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ [
+ '',
+ '--login=user:password',
+ '--header=name:value',
+ 'development.ini',
+ '/',
+ ],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['HTTP_NAME'], 'value')
- self.assertEqual(self._environ['HTTP_AUTHORIZATION'],
- 'Basic dXNlcjpwYXNzd29yZA==')
+ self.assertEqual(
+ self._environ['HTTP_AUTHORIZATION'], 'Basic dXNlcjpwYXNzd29yZA=='
+ )
self.assertEqual(self._path_info, '/')
self.assertEqual(self._out, ['abc'])
def test_command_has_content_type_header_var(self):
command = self._makeOne(
- ['', '--header=content-type:app/foo','development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ ['', '--header=content-type:app/foo', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['CONTENT_TYPE'], 'app/foo')
self.assertEqual(self._path_info, '/')
@@ -88,13 +108,15 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_has_multiple_header_vars(self):
command = self._makeOne(
- ['',
- '--header=name:value',
- '--header=name2:value2',
- 'development.ini',
- '/'],
- [('Content-Type', 'text/html; charset=UTF-8')]
- )
+ [
+ '',
+ '--header=name:value',
+ '--header=name2:value2',
+ 'development.ini',
+ '/',
+ ],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['HTTP_NAME'], 'value')
self.assertEqual(self._environ['HTTP_NAME2'], 'value2')
@@ -102,8 +124,10 @@ class TestPRequestCommand(unittest.TestCase):
self.assertEqual(self._out, ['abc'])
def test_command_method_get(self):
- command = self._makeOne(['', '--method=GET', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ command = self._makeOne(
+ ['', '--method=GET', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['REQUEST_METHOD'], 'GET')
self.assertEqual(self._path_info, '/')
@@ -111,8 +135,11 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_method_post(self):
from pyramid.compat import NativeIO
- command = self._makeOne(['', '--method=POST', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+
+ command = self._makeOne(
+ ['', '--method=POST', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
stdin = NativeIO()
command.stdin = stdin
command.run()
@@ -124,8 +151,11 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_method_put(self):
from pyramid.compat import NativeIO
- command = self._makeOne(['', '--method=PUT', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+
+ command = self._makeOne(
+ ['', '--method=PUT', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
stdin = NativeIO()
command.stdin = stdin
command.run()
@@ -137,8 +167,11 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_method_patch(self):
from pyramid.compat import NativeIO
- command = self._makeOne(['', '--method=PATCH', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+
+ command = self._makeOne(
+ ['', '--method=PATCH', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
stdin = NativeIO()
command.stdin = stdin
command.run()
@@ -150,9 +183,11 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_method_propfind(self):
from pyramid.compat import NativeIO
- command = self._makeOne(['', '--method=PROPFIND', 'development.ini',
- '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+
+ command = self._makeOne(
+ ['', '--method=PROPFIND', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
stdin = NativeIO()
command.stdin = stdin
command.run()
@@ -162,9 +197,11 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_method_options(self):
from pyramid.compat import NativeIO
- command = self._makeOne(['', '--method=OPTIONS', 'development.ini',
- '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+
+ command = self._makeOne(
+ ['', '--method=OPTIONS', 'development.ini', '/'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
stdin = NativeIO()
command.stdin = stdin
command.run()
@@ -173,8 +210,10 @@ class TestPRequestCommand(unittest.TestCase):
self.assertEqual(self._out, ['abc'])
def test_command_with_query_string(self):
- command = self._makeOne(['', 'development.ini', '/abc?a=1&b=2&c'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ command = self._makeOne(
+ ['', 'development.ini', '/abc?a=1&b=2&c'],
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._environ['QUERY_STRING'], 'a=1&b=2&c')
self.assertEqual(self._path_info, '/abc')
@@ -183,16 +222,20 @@ class TestPRequestCommand(unittest.TestCase):
def test_command_display_headers(self):
command = self._makeOne(
['', '--display-headers', 'development.ini', '/'],
- [('Content-Type', 'text/html; charset=UTF-8')])
+ [('Content-Type', 'text/html; charset=UTF-8')],
+ )
command.run()
self.assertEqual(self._path_info, '/')
self.assertEqual(
self._out,
- ['200 OK', 'Content-Type: text/html; charset=UTF-8', 'abc'])
+ ['200 OK', 'Content-Type: text/html; charset=UTF-8', 'abc'],
+ )
def test_command_response_has_no_charset(self):
- command = self._makeOne(['', '--method=GET', 'development.ini', '/'],
- headers=[('Content-Type', 'image/jpeg')])
+ command = self._makeOne(
+ ['', '--method=GET', 'development.ini', '/'],
+ headers=[('Content-Type', 'image/jpeg')],
+ )
command.run()
self.assertEqual(self._path_info, '/')
@@ -207,6 +250,7 @@ class TestPRequestCommand(unittest.TestCase):
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.prequest import main
+
return main(argv, True)
def test_it(self):
diff --git a/tests/test_scripts/test_proutes.py b/tests/test_scripts/test_proutes.py
index 0de331c94..5bbfa9f25 100644
--- a/tests/test_scripts/test_proutes.py
+++ b/tests/test_scripts/test_proutes.py
@@ -15,6 +15,7 @@ class DummyIntrospector(object):
class TestPRoutesCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.proutes import PRoutesCommand
+
return PRoutesCommand
def _makeOne(self):
@@ -27,12 +28,14 @@ class TestPRoutesCommand(unittest.TestCase):
def _makeRegistry(self):
from pyramid.registry import Registry
+
registry = Registry()
registry.introspector = DummyIntrospector()
return registry
def _makeConfig(self, *arg, **kw):
from pyramid.config import Configurator
+
config = Configurator(*arg, **kw)
return config
@@ -76,7 +79,7 @@ class TestPRoutesCommand(unittest.TestCase):
def test_no_mapper(self):
command = self._makeOne()
- command._get_mapper = lambda *arg:None
+ command._get_mapper = lambda *arg: None
L = []
command.out = L.append
result = command.run()
@@ -115,11 +118,15 @@ class TestPRoutesCommand(unittest.TestCase):
def test_single_route_no_views_registered(self):
from zope.interface import Interface
from pyramid.interfaces import IRouteRequest
+
registry = self._makeRegistry()
- def view():pass
+ def view():
+ pass
+
class IMyRoute(Interface):
pass
+
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
route = dummy.DummyRoute('a', '/a')
@@ -138,14 +145,18 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
+
registry = self._makeRegistry()
- def view():pass
+ def view():
+ pass
+
class IMyRoute(Interface):
pass
- registry.registerAdapter(view,
- (IViewClassifier, IMyRoute, Interface),
- IView, '')
+
+ registry.registerAdapter(
+ view, (IViewClassifier, IMyRoute, Interface), IView, ''
+ )
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
route = dummy.DummyRoute('a', '/a')
@@ -159,8 +170,7 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()[:3]
self.assertEqual(
- compare_to,
- ['a', '/a', 'tests.test_scripts.test_proutes.view']
+ compare_to, ['a', '/a', 'tests.test_scripts.test_proutes.view']
)
def test_one_route_with_long_name_one_view_registered(self):
@@ -168,26 +178,26 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
+
registry = self._makeRegistry()
- def view():pass
+ def view():
+ pass
class IMyRoute(Interface):
pass
registry.registerAdapter(
- view,
- (IViewClassifier, IMyRoute, Interface),
- IView, ''
+ view, (IViewClassifier, IMyRoute, Interface), IView, ''
)
- registry.registerUtility(IMyRoute, IRouteRequest,
- name='very_long_name_123')
+ registry.registerUtility(
+ IMyRoute, IRouteRequest, name='very_long_name_123'
+ )
command = self._makeOne()
route = dummy.DummyRoute(
- 'very_long_name_123',
- '/and_very_long_pattern_as_well'
+ 'very_long_name_123', '/and_very_long_pattern_as_well'
)
mapper = dummy.DummyMapper(route)
command._get_mapper = lambda *arg: mapper
@@ -200,9 +210,11 @@ class TestPRoutesCommand(unittest.TestCase):
compare_to = L[-1].split()[:3]
self.assertEqual(
compare_to,
- ['very_long_name_123',
- '/and_very_long_pattern_as_well',
- 'tests.test_scripts.test_proutes.view']
+ [
+ 'very_long_name_123',
+ '/and_very_long_pattern_as_well',
+ 'tests.test_scripts.test_proutes.view',
+ ],
)
def test_class_view(self):
@@ -215,7 +227,7 @@ class TestPRoutesCommand(unittest.TestCase):
view=dummy.DummyView,
attr='view',
renderer=nr,
- request_method='POST'
+ request_method='POST',
)
command = self._makeOne()
@@ -227,8 +239,10 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
- 'tests.test_scripts.dummy.DummyView.view', 'POST'
+ 'foo',
+ '/a/b',
+ 'tests.test_scripts.dummy.DummyView.view',
+ 'POST',
]
self.assertEqual(compare_to, expected)
@@ -237,19 +251,27 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
+
registry = self._makeRegistry()
- def view():pass
+ def view():
+ pass
+
class IMyRoot(Interface):
pass
+
class IMyRoute(Interface):
pass
- registry.registerAdapter(view,
- (IViewClassifier, IMyRoute, IMyRoot),
- IView, '')
+
+ registry.registerAdapter(
+ view, (IViewClassifier, IMyRoute, IMyRoot), IView, ''
+ )
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
- def factory(request): pass
+
+ def factory(request):
+ pass
+
route = dummy.DummyRoute('a', '/a', factory=factory)
mapper = dummy.DummyMapper(route)
command._get_mapper = lambda *arg: mapper
@@ -269,20 +291,18 @@ class TestPRoutesCommand(unittest.TestCase):
registry = self._makeRegistry()
- def view(): pass
+ def view():
+ pass
class IMyRoute(Interface):
pass
multiview1 = dummy.DummyMultiView(
- view, context='context',
- view_name='a1'
+ view, context='context', view_name='a1'
)
registry.registerAdapter(
- multiview1,
- (IViewClassifier, IMyRoute, Interface),
- IMultiView, ''
+ multiview1, (IViewClassifier, IMyRoute, Interface), IMultiView, ''
)
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
@@ -300,13 +320,11 @@ class TestPRoutesCommand(unittest.TestCase):
view_str = '<tests.test_scripts.dummy.DummyMultiView'
final = '%s.%s' % (view_module, view_str)
- self.assertEqual(
- compare_to,
- ['a', '/a', final]
- )
+ self.assertEqual(compare_to, ['a', '/a', final])
def test__get_mapper(self):
from pyramid.urldispatch import RoutesMapper
+
command = self._makeOne()
registry = self._makeRegistry()
@@ -316,15 +334,13 @@ class TestPRoutesCommand(unittest.TestCase):
def test_one_route_all_methods_view_only_post(self):
from pyramid.renderers import null_renderer as nr
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
config.add_view(
- route_name='foo',
- view=view1,
- renderer=nr,
- request_method='POST'
+ route_name='foo', view=view1, renderer=nr, request_method='POST'
)
command = self._makeOne()
@@ -336,23 +352,22 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
- 'tests.test_scripts.test_proutes.view1', 'POST'
+ 'foo',
+ '/a/b',
+ 'tests.test_scripts.test_proutes.view1',
+ 'POST',
]
self.assertEqual(compare_to, expected)
def test_one_route_only_post_view_all_methods(self):
from pyramid.renderers import null_renderer as nr
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b', request_method='POST')
- config.add_view(
- route_name='foo',
- view=view1,
- renderer=nr,
- )
+ config.add_view(route_name='foo', view=view1, renderer=nr)
command = self._makeOne()
L = []
@@ -363,15 +378,18 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
- 'tests.test_scripts.test_proutes.view1', 'POST'
+ 'foo',
+ '/a/b',
+ 'tests.test_scripts.test_proutes.view1',
+ 'POST',
]
self.assertEqual(compare_to, expected)
def test_one_route_only_post_view_post_and_get(self):
from pyramid.renderers import null_renderer as nr
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b', request_method='POST')
@@ -379,7 +397,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=('POST', 'GET')
+ request_method=('POST', 'GET'),
)
command = self._makeOne()
@@ -391,23 +409,23 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
- 'tests.test_scripts.test_proutes.view1', 'POST'
+ 'foo',
+ '/a/b',
+ 'tests.test_scripts.test_proutes.view1',
+ 'POST',
]
self.assertEqual(compare_to, expected)
def test_route_request_method_mismatch(self):
from pyramid.renderers import null_renderer as nr
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b', request_method='POST')
config.add_view(
- route_name='foo',
- view=view1,
- renderer=nr,
- request_method='GET'
+ route_name='foo', view=view1, renderer=nr, request_method='GET'
)
command = self._makeOne()
@@ -419,21 +437,24 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
+ 'foo',
+ '/a/b',
'tests.test_scripts.test_proutes.view1',
- '<route', 'mismatch>'
+ '<route',
+ 'mismatch>',
]
self.assertEqual(compare_to, expected)
def test_route_static_views(self):
from pyramid.renderers import null_renderer as nr
+
config = self._makeConfig(autocommit=True)
config.add_static_view('static', 'static', cache_max_age=3600)
path2 = os.path.normpath('/var/www/static')
config.add_static_view(name='static2', path=path2)
config.add_static_view(
name='pyramid_scaffold',
- path='pyramid:scaffolds/starter/+package+/static'
+ path='pyramid:scaffolds/starter/+package+/static',
)
command = self._makeOne()
@@ -445,11 +466,19 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 5)
expected = [
- ['__static/', '/static/*subpath',
- 'tests.test_scripts:static/', '*'],
+ [
+ '__static/',
+ '/static/*subpath',
+ 'tests.test_scripts:static/',
+ '*',
+ ],
['__static2/', '/static2/*subpath', path2 + os.sep, '*'],
- ['__pyramid_scaffold/', '/pyramid_scaffold/*subpath',
- 'pyramid:scaffolds/starter/+package+/static/', '*'],
+ [
+ '__pyramid_scaffold/',
+ '/pyramid_scaffold/*subpath',
+ 'pyramid:scaffolds/starter/+package+/static/',
+ '*',
+ ],
]
for index, line in enumerate(L[2:]):
@@ -458,6 +487,7 @@ class TestPRoutesCommand(unittest.TestCase):
def test_route_no_view(self):
from pyramid.renderers import null_renderer as nr
+
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b', request_method='POST')
@@ -469,27 +499,23 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
- expected = [
- 'foo', '/a/b',
- '<unknown>',
- 'POST',
- ]
+ expected = ['foo', '/a/b', '<unknown>', 'POST']
self.assertEqual(compare_to, expected)
def test_route_as_wsgiapp(self):
from pyramid.wsgi import wsgiapp2
config1 = self._makeConfig(autocommit=True)
- def view1(context, request): return 'view1'
+
+ def view1(context, request):
+ return 'view1'
+
config1.add_route('foo', '/a/b', request_method='POST')
config1.add_view(view=view1, route_name='foo')
config2 = self._makeConfig(autocommit=True)
config2.add_route('foo', '/a/b', request_method='POST')
- config2.add_view(
- wsgiapp2(config1.make_wsgi_app()),
- route_name='foo',
- )
+ config2.add_view(wsgiapp2(config1.make_wsgi_app()), route_name='foo')
command = self._makeOne()
L = []
@@ -499,18 +525,15 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
- expected = [
- 'foo', '/a/b',
- '<wsgiapp>',
- 'POST',
- ]
+ expected = ['foo', '/a/b', '<wsgiapp>', 'POST']
self.assertEqual(compare_to, expected)
def test_route_is_get_view_request_method_not_post(self):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b', request_method='GET')
@@ -518,7 +541,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -530,9 +553,10 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
+ 'foo',
+ '/a/b',
'tests.test_scripts.test_proutes.view1',
- 'GET'
+ 'GET',
]
self.assertEqual(compare_to, expected)
@@ -540,7 +564,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -548,7 +573,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -560,9 +585,10 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
+ 'foo',
+ '/a/b',
'tests.test_scripts.test_proutes.view1',
- '!POST,*'
+ '!POST,*',
]
self.assertEqual(compare_to, expected)
@@ -570,8 +596,11 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
- def view2(context, request): return 'view2'
+ def view1(context, request):
+ return 'view1'
+
+ def view2(context, request):
+ return 'view2'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -579,7 +608,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
config.add_route('bar', '/b/a')
@@ -587,7 +616,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='bar',
view=view2,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -601,9 +630,10 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
expected = [
- 'foo', '/a/b',
+ 'foo',
+ '/a/b',
'tests.test_scripts.test_proutes.view1',
- '!POST,*'
+ '!POST,*',
]
self.assertEqual(compare_to, expected)
@@ -611,7 +641,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -619,7 +650,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -641,7 +672,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -649,7 +681,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -670,7 +702,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -678,7 +711,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -687,7 +720,8 @@ class TestPRoutesCommand(unittest.TestCase):
command.out = L.append
command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
command.get_config_loader = dummy.DummyLoader(
- {'proutes': {'format': 'method\nname'}})
+ {'proutes': {'format': 'method\nname'}}
+ )
result = command.run()
self.assertEqual(result, 0)
@@ -702,7 +736,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -710,7 +745,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -719,7 +754,8 @@ class TestPRoutesCommand(unittest.TestCase):
command.out = L.append
command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
command.get_config_loader = dummy.DummyLoader(
- {'proutes': {'format': 'method name'}})
+ {'proutes': {'format': 'method name'}}
+ )
result = command.run()
self.assertEqual(result, 0)
@@ -734,7 +770,8 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.renderers import null_renderer as nr
from pyramid.config import not_
- def view1(context, request): return 'view1'
+ def view1(context, request):
+ return 'view1'
config = self._makeConfig(autocommit=True)
config.add_route('foo', '/a/b')
@@ -742,7 +779,7 @@ class TestPRoutesCommand(unittest.TestCase):
route_name='foo',
view=view1,
renderer=nr,
- request_method=not_('POST')
+ request_method=not_('POST'),
)
command = self._makeOne()
@@ -751,7 +788,8 @@ class TestPRoutesCommand(unittest.TestCase):
command.out = L.append
command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
command.get_config_loader = dummy.DummyLoader(
- {'proutes': {'format': 'method,name'}})
+ {'proutes': {'format': 'method,name'}}
+ )
result = command.run()
self.assertEqual(result, 0)
@@ -776,15 +814,14 @@ class TestPRoutesCommand(unittest.TestCase):
self.assertEqual(result, 0)
self.assertEqual(len(L), 3)
compare_to = L[-1].split()
- expected = [
- 'foo', 'http://example.com/bar.aspx',
- '<unknown>', '*',
- ]
+ expected = ['foo', 'http://example.com/bar.aspx', '<unknown>', '*']
self.assertEqual(compare_to, expected)
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.proutes import main
+
return main(argv, quiet=True)
def test_it(self):
diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py
index 0c46b5348..b85f4ddb7 100644
--- a/tests/test_scripts/test_pserve.py
+++ b/tests/test_scripts/test_pserve.py
@@ -9,6 +9,7 @@ here = os.path.abspath(os.path.dirname(__file__))
class TestPServeCommand(unittest.TestCase):
def setUp(self):
from pyramid.compat import NativeIO
+
self.out_ = NativeIO()
def out(self, msg):
@@ -16,6 +17,7 @@ class TestPServeCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.pserve import PServeCommand
+
return PServeCommand
def _makeOne(self, *args):
@@ -41,6 +43,7 @@ class TestPServeCommand(unittest.TestCase):
app.name = name
app.global_conf = global_conf
return app
+
self.loader.get_wsgi_app = get_app
self.loader.server = lambda x: x
@@ -54,41 +57,36 @@ class TestPServeCommand(unittest.TestCase):
def test_config_file_finds_watch_files(self):
inst = self._makeOne('development.ini')
loader = self.loader('/base/path.ini')
- loader.settings = {'pserve': {
- 'watch_files': 'foo\n/baz\ntests.test_scripts:*.py',
- }}
+ loader.settings = {
+ 'pserve': {'watch_files': 'foo\n/baz\ntests.test_scripts:*.py'}
+ }
inst.pserve_file_config(loader, global_conf={'a': '1'})
- self.assertEqual(loader.calls[0]['defaults'], {
- 'a': '1',
- })
- self.assertEqual(inst.watch_files, set([
- os.path.abspath('/base/foo'),
- os.path.abspath('/baz'),
- os.path.abspath(os.path.join(here, '*.py')),
- ]))
+ self.assertEqual(loader.calls[0]['defaults'], {'a': '1'})
+ self.assertEqual(
+ inst.watch_files,
+ set(
+ [
+ os.path.abspath('/base/foo'),
+ os.path.abspath('/baz'),
+ os.path.abspath(os.path.join(here, '*.py')),
+ ]
+ ),
+ )
def test_config_file_finds_open_url(self):
inst = self._makeOne('development.ini')
loader = self.loader('/base/path.ini')
- loader.settings = {'pserve': {
- 'open_url': 'http://127.0.0.1:8080/',
- }}
+ loader.settings = {'pserve': {'open_url': 'http://127.0.0.1:8080/'}}
inst.pserve_file_config(loader, global_conf={'a': '1'})
- self.assertEqual(loader.calls[0]['defaults'], {
- 'a': '1',
- })
+ self.assertEqual(loader.calls[0]['defaults'], {'a': '1'})
self.assertEqual(inst.open_url, 'http://127.0.0.1:8080/')
def test_guess_server_url(self):
inst = self._makeOne('development.ini')
loader = self.loader('/base/path.ini')
- loader.settings = {'server:foo': {
- 'port': '8080',
- }}
+ loader.settings = {'server:foo': {'port': '8080'}}
url = inst.guess_server_url(loader, 'foo', global_conf={'a': '1'})
- self.assertEqual(loader.calls[0]['defaults'], {
- 'a': '1',
- })
+ self.assertEqual(loader.calls[0]['defaults'], {'a': '1'})
self.assertEqual(url, 'http://127.0.0.1:8080')
def test_reload_call_hupper_with_correct_args(self):
@@ -105,25 +103,35 @@ class TestPServeCommand(unittest.TestCase):
orig_hupper = pserve.hupper
try:
- pserve.hupper = AttrDict(is_active=lambda: False,
- start_reloader=dummy_start_reloader)
+ pserve.hupper = AttrDict(
+ is_active=lambda: False, start_reloader=dummy_start_reloader
+ )
inst = self._makeOne('--reload', 'development.ini')
inst.run()
finally:
pserve.hupper = orig_hupper
- self.assertEquals(dummy_start_reloader.args, ('pyramid.scripts.pserve.main',))
- self.assertEquals(dummy_start_reloader.kwargs, {
- 'reload_interval': 1,
- 'verbose': 1,
- 'worker_kwargs': {'argv': ['pserve', '--reload', 'development.ini'],
- 'quiet': False}})
+ self.assertEquals(
+ dummy_start_reloader.args, ('pyramid.scripts.pserve.main',)
+ )
+ self.assertEquals(
+ dummy_start_reloader.kwargs,
+ {
+ 'reload_interval': 1,
+ 'verbose': 1,
+ 'worker_kwargs': {
+ 'argv': ['pserve', '--reload', 'development.ini'],
+ 'quiet': False,
+ },
+ },
+ )
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pserve import main
+
return main(argv, quiet=True)
def test_it(self):
diff --git a/tests/test_scripts/test_pshell.py b/tests/test_scripts/test_pshell.py
index 291714340..6beaacda6 100644
--- a/tests/test_scripts/test_pshell.py
+++ b/tests/test_scripts/test_pshell.py
@@ -6,10 +6,16 @@ from . import dummy
class TestPShellCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.pshell import PShellCommand
+
return PShellCommand
- def _makeOne(self, patch_bootstrap=True, patch_loader=True,
- patch_args=True, patch_options=True):
+ def _makeOne(
+ self,
+ patch_bootstrap=True,
+ patch_loader=True,
+ patch_args=True,
+ patch_options=True,
+ ):
cmd = self._getTargetClass()([])
if patch_bootstrap:
@@ -19,12 +25,18 @@ class TestPShellCommand(unittest.TestCase):
self.loader = dummy.DummyLoader()
cmd.get_config_loader = self.loader
if patch_args:
- class Args(object): pass
+
+ class Args(object):
+ pass
+
self.args = Args()
self.args.config_uri = '/foo/bar/myapp.ini#myapp'
cmd.args.config_uri = self.args.config_uri
if patch_options:
- class Options(object): pass
+
+ class Options(object):
+ pass
+
self.options = Options()
self.options.python_shell = ''
self.options.setup = None
@@ -47,12 +59,16 @@ class TestPShellCommand(unittest.TestCase):
command.default_runner = shell
command.run()
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': self.bootstrap.root,
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
@@ -84,23 +100,23 @@ class TestPShellCommand(unittest.TestCase):
shell = dummy.DummyShell()
bad_shell = dummy.DummyShell()
self._makeEntryPoints(
- command,
- {
- 'ipython': shell,
- 'bpython': bad_shell,
- }
+ command, {'ipython': shell, 'bpython': bad_shell}
)
command.args.python_shell = 'ipython'
command.run()
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': self.bootstrap.root,
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
@@ -108,13 +124,7 @@ class TestPShellCommand(unittest.TestCase):
command = self._makeOne()
dshell = dummy.DummyShell()
- self._makeEntryPoints(
- command,
- {
- 'ipython': dshell,
- 'bpython': dshell,
- }
- )
+ self._makeEntryPoints(command, {'ipython': dshell, 'bpython': dshell})
command.default_runner = None
shell = command.make_shell()
@@ -137,12 +147,7 @@ class TestPShellCommand(unittest.TestCase):
self.assertRaises(ValueError, command.make_shell)
self._makeEntryPoints(
- command,
- {
- 'ipython': ipshell,
- 'bpython': bpshell,
- 'python': dshell,
- }
+ command, {'ipython': ipshell, 'bpython': bpshell, 'python': dshell}
)
command.args.python_shell = 'ipython'
@@ -164,12 +169,7 @@ class TestPShellCommand(unittest.TestCase):
dshell = dummy.DummyShell()
self._makeEntryPoints(
- command,
- {
- 'ipython': ipshell,
- 'bpython': bpshell,
- 'python': dshell,
- }
+ command, {'ipython': ipshell, 'bpython': bpshell, 'python': dshell}
)
command.default_runner = dshell
@@ -194,41 +194,52 @@ class TestPShellCommand(unittest.TestCase):
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'm':model,
- 'User': user,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': self.bootstrap.root,
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'm': model,
+ 'User': user,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
def test_command_setup(self):
command = self._makeOne()
+
def setup(env):
env['a'] = 1
env['root'] = 'root override'
env['none'] = None
+
self.loader.settings = {'pshell': {'setup': setup}}
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':'root override',
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'a':1,
- 'none': None,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': 'root override',
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'a': 1,
+ 'none': None,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
def test_command_setup_generator(self):
command = self._makeOne()
did_resume_after_yield = {}
+
def setup(env):
env['a'] = 1
env['root'] = 'root override'
@@ -237,18 +248,23 @@ class TestPShellCommand(unittest.TestCase):
yield
did_resume_after_yield['result'] = True
self.assertEqual(request.dummy_attr, 1)
+
self.loader.settings = {'pshell': {'setup': setup}}
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':'root override',
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'a':1,
- 'none': None,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': 'root override',
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'a': 1,
+ 'none': None,
+ },
+ )
self.assertTrue(did_resume_after_yield['result'])
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
@@ -257,15 +273,10 @@ class TestPShellCommand(unittest.TestCase):
command = self._makeOne()
ipshell = dummy.DummyShell()
dshell = dummy.DummyShell()
- self._makeEntryPoints(
- command,
- {
- 'ipython': ipshell,
- 'python': dshell,
- }
- )
- self.loader.settings = {'pshell': {
- 'default_shell': 'bpython python\nipython'}}
+ self._makeEntryPoints(command, {'ipython': ipshell, 'python': dshell})
+ self.loader.settings = {
+ 'pshell': {'default_shell': 'bpython python\nipython'}
+ }
command.run()
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
self.assertTrue(dshell.called)
@@ -273,78 +284,105 @@ class TestPShellCommand(unittest.TestCase):
def test_command_loads_check_variable_override_order(self):
command = self._makeOne()
model = dummy.Dummy()
+
def setup(env):
env['a'] = 1
env['m'] = 'model override'
env['root'] = 'root override'
+
self.loader.settings = {'pshell': {'setup': setup, 'm': model}}
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':'root override',
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'a':1, 'm':'model override',
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': 'root override',
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'a': 1,
+ 'm': 'model override',
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
def test_command_loads_setup_from_options(self):
command = self._makeOne()
+
def setup(env):
env['a'] = 1
env['root'] = 'root override'
+
model = dummy.Dummy()
self.loader.settings = {'pshell': {'setup': 'abc', 'm': model}}
command.args.setup = setup
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':'root override',
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'a':1, 'm':model,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': 'root override',
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'a': 1,
+ 'm': model,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
def test_command_custom_section_override(self):
command = self._makeOne()
dummy_ = dummy.Dummy()
- self.loader.settings = {'pshell': {
- 'app': dummy_, 'root': dummy_, 'registry': dummy_,
- 'request': dummy_}}
+ self.loader.settings = {
+ 'pshell': {
+ 'app': dummy_,
+ 'root': dummy_,
+ 'registry': dummy_,
+ 'request': dummy_,
+ }
+ }
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':dummy_, 'root':dummy_, 'registry':dummy_, 'request':dummy_,
- 'root_factory':self.bootstrap.root_factory,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': dummy_,
+ 'root': dummy_,
+ 'registry': dummy_,
+ 'request': dummy_,
+ 'root_factory': self.bootstrap.root_factory,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
def test_command_loads_pythonstartup(self):
command = self._makeOne()
- command.pystartup = (
- os.path.abspath(
- os.path.join(
- os.path.dirname(__file__),
- 'pystartup.txt')))
+ command.pystartup = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), 'pystartup.txt')
+ )
shell = dummy.DummyShell()
command.run(shell)
self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'foo':1,
- })
+ self.assertEqual(
+ shell.env,
+ {
+ 'app': self.bootstrap.app,
+ 'root': self.bootstrap.root,
+ 'registry': self.bootstrap.registry,
+ 'request': self.bootstrap.request,
+ 'root_factory': self.bootstrap.root_factory,
+ 'foo': 1,
+ },
+ )
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
@@ -359,27 +397,20 @@ class TestPShellCommand(unittest.TestCase):
command.out = out
- self._makeEntryPoints(
- command,
- {
- 'ipython': dshell,
- 'python': dshell,
- }
- )
+ self._makeEntryPoints(command, {'ipython': dshell, 'python': dshell})
command.args.list = True
result = command.run()
self.assertEqual(result, 0)
- self.assertEqual(out_calls, [
- 'Available shells:',
- ' ipython',
- ' python',
- ])
+ self.assertEqual(
+ out_calls, ['Available shells:', ' ipython', ' python']
+ )
class Test_python_shell_runner(unittest.TestCase):
def _callFUT(self, env, help, interact):
from pyramid.scripts.pshell import python_shell_runner
+
return python_shell_runner(env, help, interact=interact)
def test_it(self):
@@ -388,9 +419,11 @@ class Test_python_shell_runner(unittest.TestCase):
self.assertEqual(interact.local, {'foo': 'bar'})
self.assertTrue('a help message' in interact.banner)
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pshell import main
+
return main(argv, quiet=True)
def test_it(self):
diff --git a/tests/test_scripts/test_ptweens.py b/tests/test_scripts/test_ptweens.py
index 4ad015249..a7fe6f651 100644
--- a/tests/test_scripts/test_ptweens.py
+++ b/tests/test_scripts/test_ptweens.py
@@ -1,9 +1,11 @@
import unittest
from . import dummy
+
class TestPTweensCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.ptweens import PTweensCommand
+
return PTweensCommand
def _makeOne(self):
@@ -31,9 +33,10 @@ class TestPTweensCommand(unittest.TestCase):
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(
- L[0],
- '"pyramid.tweens" config value NOT set (implicitly ordered tweens '
- 'used)')
+ L[0],
+ '"pyramid.tweens" config value NOT set (implicitly ordered tweens '
+ 'used)',
+ )
def test_command_implicit_and_explicit_tweens(self):
command = self._makeOne()
@@ -44,17 +47,20 @@ class TestPTweensCommand(unittest.TestCase):
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(
- L[0],
- '"pyramid.tweens" config value set (explicitly ordered tweens used)')
+ L[0],
+ '"pyramid.tweens" config value set (explicitly ordered tweens used)',
+ )
def test__get_tweens(self):
command = self._makeOne()
registry = dummy.DummyRegistry()
self.assertEqual(command._get_tweens(registry), None)
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.ptweens import main
+
return main(argv, quiet=True)
def test_it(self):
diff --git a/tests/test_scripts/test_pviews.py b/tests/test_scripts/test_pviews.py
index 999028f28..cdb3c1c33 100644
--- a/tests/test_scripts/test_pviews.py
+++ b/tests/test_scripts/test_pviews.py
@@ -1,9 +1,11 @@
import unittest
from . import dummy
+
class TestPViewsCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.scripts.pviews import PViewsCommand
+
return PViewsCommand
def _makeOne(self, registry=None):
@@ -15,17 +17,20 @@ class TestPViewsCommand(unittest.TestCase):
def _makeRequest(self, url, registry):
from pyramid.request import Request
+
request = Request.blank('/a')
request.registry = registry
return request
def _register_mapper(self, registry, routes):
from pyramid.interfaces import IRoutesMapper
+
mapper = dummy.DummyMapper(*routes)
registry.registerUtility(mapper, IRoutesMapper)
def test__find_view_no_match(self):
from pyramid.registry import Registry
+
registry = Registry()
self._register_mapper(registry, [])
command = self._makeOne(registry)
@@ -41,16 +46,19 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IMultiView
from pyramid.traversal import DefaultRootFactory
from pyramid.registry import Registry
+
registry = Registry()
+
@implementer(IMultiView)
class View1(object):
pass
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
root = DefaultRootFactory(request)
root_iface = providedBy(root)
- registry.registerAdapter(View1(),
- (IViewClassifier, IRequest, root_iface),
- IMultiView)
+ registry.registerAdapter(
+ View1(), (IViewClassifier, IRequest, root_iface), IMultiView
+ )
self._register_mapper(registry, [])
command = self._makeOne(registry=registry)
request = self._makeRequest('/x', registry)
@@ -64,14 +72,18 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IView
from pyramid.traversal import DefaultRootFactory
from pyramid.registry import Registry
+
registry = Registry()
- def view1(): pass
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+
+ def view1():
+ pass
+
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
root = DefaultRootFactory(request)
root_iface = providedBy(root)
- registry.registerAdapter(view1,
- (IViewClassifier, IRequest, root_iface),
- IView, name='a')
+ registry.registerAdapter(
+ view1, (IViewClassifier, IRequest, root_iface), IView, name='a'
+ )
self._register_mapper(registry, [])
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
@@ -86,17 +98,20 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IMultiView
from pyramid.traversal import DefaultRootFactory
from pyramid.registry import Registry
+
registry = Registry()
+
@implementer(IMultiView)
class View1(object):
pass
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
root = DefaultRootFactory(request)
root_iface = providedBy(root)
view = View1()
- registry.registerAdapter(view,
- (IViewClassifier, IRequest, root_iface),
- IMultiView, name='a')
+ registry.registerAdapter(
+ view, (IViewClassifier, IRequest, root_iface), IMultiView, name='a'
+ )
self._register_mapper(registry, [])
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
@@ -110,22 +125,32 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
from pyramid.registry import Registry
+
registry = Registry()
- def view():pass
+
+ def view():
+ pass
+
class IMyRoot(Interface):
pass
+
class IMyRoute(Interface):
pass
- registry.registerAdapter(view,
- (IViewClassifier, IMyRoute, IMyRoot),
- IView, '')
+
+ registry.registerAdapter(
+ view, (IViewClassifier, IMyRoute, IMyRoot), IView, ''
+ )
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
+
@implementer(IMyRoot)
class Factory(object):
def __init__(self, request):
pass
- routes = [dummy.DummyRoute('a', '/a', factory=Factory, matchdict={}),
- dummy.DummyRoute('b', '/b', factory=Factory)]
+
+ routes = [
+ dummy.DummyRoute('a', '/a', factory=Factory, matchdict={}),
+ dummy.DummyRoute('b', '/b', factory=Factory),
+ ]
self._register_mapper(registry, routes)
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
@@ -139,24 +164,37 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IMultiView
from pyramid.interfaces import IRootFactory
from pyramid.registry import Registry
+
registry = Registry()
- def view1():pass
- def view2():pass
+
+ def view1():
+ pass
+
+ def view2():
+ pass
+
class IMyRoot(Interface):
pass
+
class IMyRoute1(Interface):
pass
+
class IMyRoute2(Interface):
pass
+
registry.registerUtility(IMyRoute1, IRouteRequest, name='a')
registry.registerUtility(IMyRoute2, IRouteRequest, name='b')
+
@implementer(IMyRoot)
class Factory(object):
def __init__(self, request):
pass
+
registry.registerUtility(Factory, IRootFactory)
- routes = [dummy.DummyRoute('a', '/a', matchdict={}),
- dummy.DummyRoute('b', '/a', matchdict={})]
+ routes = [
+ dummy.DummyRoute('a', '/a', matchdict={}),
+ dummy.DummyRoute('b', '/a', matchdict={}),
+ ]
self._register_mapper(registry, routes)
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
@@ -172,30 +210,43 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.interfaces import IMultiView
from pyramid.interfaces import IRootFactory
from pyramid.registry import Registry
+
registry = Registry()
- def view1():pass
- def view2():pass
+
+ def view1():
+ pass
+
+ def view2():
+ pass
+
class IMyRoot(Interface):
pass
+
class IMyRoute1(Interface):
pass
+
class IMyRoute2(Interface):
pass
- registry.registerAdapter(view1,
- (IViewClassifier, IMyRoute1, IMyRoot),
- IView, '')
- registry.registerAdapter(view2,
- (IViewClassifier, IMyRoute2, IMyRoot),
- IView, '')
+
+ registry.registerAdapter(
+ view1, (IViewClassifier, IMyRoute1, IMyRoot), IView, ''
+ )
+ registry.registerAdapter(
+ view2, (IViewClassifier, IMyRoute2, IMyRoot), IView, ''
+ )
registry.registerUtility(IMyRoute1, IRouteRequest, name='a')
registry.registerUtility(IMyRoute2, IRouteRequest, name='b')
+
@implementer(IMyRoot)
class Factory(object):
def __init__(self, request):
pass
+
registry.registerUtility(Factory, IRootFactory)
- routes = [dummy.DummyRoute('a', '/a', matchdict={}),
- dummy.DummyRoute('b', '/a', matchdict={})]
+ routes = [
+ dummy.DummyRoute('a', '/a', matchdict={}),
+ dummy.DummyRoute('b', '/a', matchdict={}),
+ ]
self._register_mapper(registry, routes)
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
@@ -207,37 +258,58 @@ class TestPViewsCommand(unittest.TestCase):
def test__find_multi_routes_all_match(self):
command = self._makeOne()
- def factory(request): pass
- routes = [dummy.DummyRoute('a', '/a', factory=factory, matchdict={}),
- dummy.DummyRoute('b', '/a', factory=factory, matchdict={})]
+
+ def factory(request):
+ pass
+
+ routes = [
+ dummy.DummyRoute('a', '/a', factory=factory, matchdict={}),
+ dummy.DummyRoute('b', '/a', factory=factory, matchdict={}),
+ ]
mapper = dummy.DummyMapper(*routes)
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
result = command._find_multi_routes(mapper, request)
- self.assertEqual(result, [{'match':{}, 'route':routes[0]},
- {'match':{}, 'route':routes[1]}])
-
+ self.assertEqual(
+ result,
+ [
+ {'match': {}, 'route': routes[0]},
+ {'match': {}, 'route': routes[1]},
+ ],
+ )
+
def test__find_multi_routes_some_match(self):
command = self._makeOne()
- def factory(request): pass
- routes = [dummy.DummyRoute('a', '/a', factory=factory),
- dummy.DummyRoute('b', '/a', factory=factory, matchdict={})]
+
+ def factory(request):
+ pass
+
+ routes = [
+ dummy.DummyRoute('a', '/a', factory=factory),
+ dummy.DummyRoute('b', '/a', factory=factory, matchdict={}),
+ ]
mapper = dummy.DummyMapper(*routes)
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
result = command._find_multi_routes(mapper, request)
- self.assertEqual(result, [{'match':{}, 'route':routes[1]}])
-
+ self.assertEqual(result, [{'match': {}, 'route': routes[1]}])
+
def test__find_multi_routes_none_match(self):
command = self._makeOne()
- def factory(request): pass
- routes = [dummy.DummyRoute('a', '/a', factory=factory),
- dummy.DummyRoute('b', '/a', factory=factory)]
+
+ def factory(request):
+ pass
+
+ routes = [
+ dummy.DummyRoute('a', '/a', factory=factory),
+ dummy.DummyRoute('b', '/a', factory=factory),
+ ]
mapper = dummy.DummyMapper(*routes)
- request = dummy.DummyRequest({'PATH_INFO':'/a'})
+ request = dummy.DummyRequest({'PATH_INFO': '/a'})
result = command._find_multi_routes(mapper, request)
self.assertEqual(result, [])
-
+
def test_views_command_not_found(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -252,6 +324,7 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_not_found_url_starts_without_slash(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -266,6 +339,7 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_traversal(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -279,16 +353,19 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.DummyView')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.DummyView')
def test_views_command_single_view_function_traversal(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
command.out = L.append
- def view(): pass
+
+ def view():
+ pass
+
view.__request_attrs__ = {'context': 'context', 'view_name': 'a'}
command._find_view = lambda arg1: view
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
@@ -298,11 +375,11 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.test_pviews.view')
+ self.assertEqual(L[8], ' tests.test_scripts.test_pviews.view')
def test_views_command_single_view_traversal_with_permission(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -317,17 +394,20 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.DummyView')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.DummyView')
self.assertEqual(L[9], ' required permission = test')
def test_views_command_single_view_traversal_with_predicates(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
command.out = L.append
- def predicate(): pass
+
+ def predicate():
+ pass
+
predicate.text = lambda *arg: "predicate = x"
view = dummy.DummyView(context='context', view_name='a')
view.__predicates__ = [predicate]
@@ -339,19 +419,20 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.DummyView')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.DummyView')
self.assertEqual(L[9], ' view predicates (predicate = x)')
def test_views_command_single_view_route(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
command.out = L.append
route = dummy.DummyRoute('a', '/a', matchdict={})
- view = dummy.DummyView(context='context', view_name='a',
- matched_route=route, subpath='')
+ view = dummy.DummyView(
+ context='context', view_name='a', matched_route=route, subpath=''
+ )
command._find_view = lambda arg1: view
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -365,11 +446,11 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[9], ' route pattern: /a')
self.assertEqual(L[10], ' route path: /a')
self.assertEqual(L[11], ' subpath: ')
- self.assertEqual(L[15],
- ' tests.test_scripts.dummy.DummyView')
+ self.assertEqual(L[15], ' tests.test_scripts.dummy.DummyView')
def test_views_command_multi_view_nested(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -377,10 +458,12 @@ class TestPViewsCommand(unittest.TestCase):
view1 = dummy.DummyView(context='context', view_name='a1')
view1.__name__ = 'view1'
view1.__view_attr__ = 'call'
- multiview1 = dummy.DummyMultiView(view1, context='context',
- view_name='a1')
- multiview2 = dummy.DummyMultiView(multiview1, context='context',
- view_name='a')
+ multiview1 = dummy.DummyMultiView(
+ view1, context='context', view_name='a1'
+ )
+ multiview2 = dummy.DummyMultiView(
+ multiview1, context='context', view_name='a'
+ )
command._find_view = lambda arg1: multiview2
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -389,22 +472,25 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.DummyMultiView')
- self.assertEqual(L[12],
- ' tests.test_scripts.dummy.view1.call')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.DummyMultiView')
+ self.assertEqual(L[12], ' tests.test_scripts.dummy.view1.call')
def test_views_command_single_view_route_with_route_predicates(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
command.out = L.append
- def predicate(): pass
+
+ def predicate():
+ pass
+
predicate.text = lambda *arg: "predicate = x"
route = dummy.DummyRoute('a', '/a', matchdict={}, predicate=predicate)
- view = dummy.DummyView(context='context', view_name='a',
- matched_route=route, subpath='')
+ view = dummy.DummyView(
+ context='context', view_name='a', matched_route=route, subpath=''
+ )
command._find_view = lambda arg1: view
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -419,11 +505,11 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[10], ' route path: /a')
self.assertEqual(L[11], ' subpath: ')
self.assertEqual(L[12], ' route predicates (predicate = x)')
- self.assertEqual(L[16],
- ' tests.test_scripts.dummy.DummyView')
+ self.assertEqual(L[16], ' tests.test_scripts.dummy.DummyView')
def test_views_command_multiview(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -431,7 +517,9 @@ class TestPViewsCommand(unittest.TestCase):
view = dummy.DummyView(context='context')
view.__name__ = 'view'
view.__view_attr__ = 'call'
- multiview = dummy.DummyMultiView(view, context='context', view_name='a')
+ multiview = dummy.DummyMultiView(
+ view, context='context', view_name='a'
+ )
command._find_view = lambda arg1: multiview
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -440,11 +528,11 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.view.call')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.view.call')
def test_views_command_multiview_with_permission(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
@@ -453,7 +541,9 @@ class TestPViewsCommand(unittest.TestCase):
view.__name__ = 'view'
view.__view_attr__ = 'call'
view.__permission__ = 'test'
- multiview = dummy.DummyMultiView(view, context='context', view_name='a')
+ multiview = dummy.DummyMultiView(
+ view, context='context', view_name='a'
+ )
command._find_view = lambda arg1: multiview
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -462,23 +552,28 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.view.call')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.view.call')
self.assertEqual(L[9], ' required permission = test')
def test_views_command_multiview_with_predicates(self):
from pyramid.registry import Registry
+
registry = Registry()
command = self._makeOne(registry=registry)
L = []
command.out = L.append
- def predicate(): pass
+
+ def predicate():
+ pass
+
predicate.text = lambda *arg: "predicate = x"
view = dummy.DummyView(context='context')
view.__name__ = 'view'
view.__view_attr__ = 'call'
view.__predicates__ = [predicate]
- multiview = dummy.DummyMultiView(view, context='context', view_name='a')
+ multiview = dummy.DummyMultiView(
+ view, context='context', view_name='a'
+ )
command._find_view = lambda arg1: multiview
command.args.config_uri = '/foo/bar/myapp.ini#myapp'
command.args.url = '/a'
@@ -487,13 +582,14 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[1], 'URL = /a')
self.assertEqual(L[3], ' context: context')
self.assertEqual(L[4], ' view name: a')
- self.assertEqual(L[8],
- ' tests.test_scripts.dummy.view.call')
+ self.assertEqual(L[8], ' tests.test_scripts.dummy.view.call')
self.assertEqual(L[9], ' view predicates (predicate = x)')
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pviews import main
+
return main(argv, quiet=True)
def test_it(self):