summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pecan/core.py20
-rw-r--r--pecan/tests/test_no_thread_locals.py45
-rw-r--r--tox.ini12
3 files changed, 59 insertions, 18 deletions
diff --git a/pecan/core.py b/pecan/core.py
index a52dae2..9174c50 100644
--- a/pecan/core.py
+++ b/pecan/core.py
@@ -684,15 +684,23 @@ class ExplicitPecan(PecanBase):
# When comparing the argspec of the method to GET/POST params,
# ignore the implicit (req, resp) at the beginning of the function
# signature
- signature_error = TypeError(
- 'When `use_context_locals` is `False`, pecan passes an explicit '
- 'reference to the request and response as the first two arguments '
- 'to the controller.\nChange the `%s.%s.%s` signature to accept '
- 'exactly 2 initial arguments (req, resp)' % (
+ if hasattr(state.controller, '__self__'):
+ _repr = '.'.join((
state.controller.__self__.__class__.__module__,
state.controller.__self__.__class__.__name__,
state.controller.__name__
- )
+ ))
+ else:
+ _repr = '.'.join((
+ state.controller.__module__,
+ state.controller.__name__
+ ))
+
+ signature_error = TypeError(
+ 'When `use_context_locals` is `False`, pecan passes an explicit '
+ 'reference to the request and response as the first two arguments '
+ 'to the controller.\nChange the `%s` signature to accept exactly '
+ '2 initial arguments (req, resp)' % _repr
)
try:
positional = argspec.args[:]
diff --git a/pecan/tests/test_no_thread_locals.py b/pecan/tests/test_no_thread_locals.py
index e9fcf75..a114840 100644
--- a/pecan/tests/test_no_thread_locals.py
+++ b/pecan/tests/test_no_thread_locals.py
@@ -24,6 +24,21 @@ class TestThreadingLocalUsage(PecanTestCase):
assert isinstance(resp, webob.Response)
return 'Hello, World!'
+ @expose()
+ def warning(self):
+ return ("This should be unroutable because (req, resp) are not"
+ " arguments. It should raise a TypeError.")
+
+ @expose(generic=True)
+ def generic(self):
+ return ("This should be unroutable because (req, resp) are not"
+ " arguments. It should raise a TypeError.")
+
+ @generic.when(method='PUT')
+ def generic_put(self, _id):
+ return ("This should be unroutable because (req, resp) are not"
+ " arguments. It should raise a TypeError.")
+
return RootController
def test_locals_are_not_used(self):
@@ -36,6 +51,36 @@ class TestThreadingLocalUsage(PecanTestCase):
self.assertRaises(AssertionError, Pecan, self.root)
+ def test_threadlocal_argument_warning(self):
+ with mock.patch('threading.local', side_effect=AssertionError()):
+
+ app = TestApp(Pecan(self.root(), use_context_locals=False))
+ self.assertRaises(
+ TypeError,
+ app.get,
+ '/warning/'
+ )
+
+ def test_threadlocal_argument_warning_on_generic(self):
+ with mock.patch('threading.local', side_effect=AssertionError()):
+
+ app = TestApp(Pecan(self.root(), use_context_locals=False))
+ self.assertRaises(
+ TypeError,
+ app.get,
+ '/generic/'
+ )
+
+ def test_threadlocal_argument_warning_on_generic_delegate(self):
+ with mock.patch('threading.local', side_effect=AssertionError()):
+
+ app = TestApp(Pecan(self.root(), use_context_locals=False))
+ self.assertRaises(
+ TypeError,
+ app.put,
+ '/generic/'
+ )
+
class TestIndexRouting(PecanTestCase):
diff --git a/tox.ini b/tox.ini
index 66deedd..468021f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -56,8 +56,6 @@ basepython = python3.2
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123
@@ -68,8 +66,6 @@ basepython = python3.2
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123 rest-api
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123
@@ -80,8 +76,6 @@ basepython = python3.3
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123
@@ -92,8 +86,6 @@ basepython = python3.3
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123 rest-api
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123
@@ -104,8 +96,6 @@ basepython = python3.4
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123
@@ -116,8 +106,6 @@ basepython = python3.4
deps = {[testenv:scaffolds-base]deps}
changedir={[testenv:scaffolds-26]changedir}
commands=pecan create testing123 rest-api
- curl "http://python-distribute.org/distribute_setup.py" -O
- {envpython} distribute_setup.py
{envpython} testing123/setup.py install
{envpython} testing123/setup.py test -q
pep8 --repeat --show-source testing123/setup.py testing123/testing123