diff options
author | John Carter <john.carter@prismaticdigital.com> | 2019-01-17 12:33:33 +1300 |
---|---|---|
committer | John Carter <john@therefromhere.org> | 2019-01-18 21:31:22 +1300 |
commit | fb534f103f20d6de614189c4baa960de004a6ad7 (patch) | |
tree | 3356d8fce619b468ef1af25b442722b8b65545b3 | |
parent | 4571536f2404d1fb107f546e14e4001f427ff3aa (diff) | |
download | webtest-fb534f103f20d6de614189c4baa960de004a6ad7.tar.gz |
Support for PYTHONOPTIMIZE=2, fix tests on PYTHONOPTIMIZE=1, 2
* skip tests that rely on assert if optimize is enabled
* skip docstring test if PYTHONOPTIMIZE=2
* try/except on docstring handling in case of PYTHONOPTIMIZE=2
-rw-r--r-- | tests/test_lint.py | 9 | ||||
-rw-r--r-- | tests/test_response.py | 6 | ||||
-rw-r--r-- | tests/test_utils.py | 3 | ||||
-rw-r--r-- | webtest/utils.py | 7 |
4 files changed, 22 insertions, 3 deletions
diff --git a/tests/test_lint.py b/tests/test_lint.py index b4176f4..e0b7f31 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import sys from six import PY3 from six import StringIO from tests.compat import unittest @@ -42,6 +43,7 @@ def application(environ, start_response): return resp(environ, start_response) +@unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") class TestLatin1Assertion(unittest.TestCase): def test_valid_type(self): @@ -64,6 +66,7 @@ class TestToString(unittest.TestCase): self.assertEqual(to_string(b'foo'), 'foo') +@unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") class TestMiddleware(unittest.TestCase): def test_lint_too_few_args(self): @@ -107,6 +110,7 @@ class TestInputWrapper(unittest.TestCase): resp = app.post('/read_lines', 'hello\nt\n') self.assertEqual(resp.body, b'hello\n-t\n') + @unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") def test_close(self): input_wrapper = InputWrapper(None) self.assertRaises(AssertionError, input_wrapper.close) @@ -140,6 +144,7 @@ class TestMiddleware2(unittest.TestCase): # don't know what to assert here... a bit cheating, just covers code +@unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") class TestCheckContentType(unittest.TestCase): def test_no_content(self): status = "204 No Content" @@ -157,6 +162,7 @@ class TestCheckContentType(unittest.TestCase): self.assertRaises(AssertionError, check_content_type, status, headers) +@unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") class TestCheckHeaders(unittest.TestCase): @unittest.skipIf(PY3, 'unicode is str in Python3') @@ -286,6 +292,8 @@ class TestIteratorWrapper(unittest.TestCase): class TestWriteWrapper(unittest.TestCase): + + @unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") def test_wrong_type(self): write_wrapper = WriteWrapper(None) self.assertRaises(AssertionError, write_wrapper, 'not a binary') @@ -310,6 +318,7 @@ class TestWriteWrapper(unittest.TestCase): class TestErrorWrapper(unittest.TestCase): + @unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") def test_dont_close(self): error_wrapper = ErrorWrapper(None) self.assertRaises(AssertionError, error_wrapper.close) diff --git a/tests/test_response.py b/tests/test_response.py index f3dad7f..3885818 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -448,8 +448,9 @@ class TestFollow(unittest.TestCase): resp = resp.follow() self.assertEqual(resp.body, b'done') - # can't follow non-redirect - self.assertRaises(AssertionError, resp.follow) + if sys.flags.optimize == 0: + # can't follow non-redirect + self.assertRaises(AssertionError, resp.follow) def test_follow_relative(self): app = self.get_redirects_app(2, ['hello/foo/', 'bar']) @@ -483,6 +484,7 @@ class TestFollow(unittest.TestCase): resp = app.get('/').maybe_follow() self.assertEqual(resp.body, b'done') + @unittest.skipIf(sys.flags.optimize > 0, "skip assert tests if optimize is enabled") def test_maybe_follow_infinite(self): app = self.get_redirects_app(100000) self.assertRaises(AssertionError, app.get('/').maybe_follow) diff --git a/tests/test_utils.py b/tests/test_utils.py index b897897..9916992 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,6 +3,8 @@ from __future__ import unicode_literals import re import json +import sys + from .compat import unittest from webtest import utils @@ -111,6 +113,7 @@ class json_methodTest(unittest.TestCase): 'params': json.dumps({'a': 'b'}), 'upload_files': None})) + @unittest.skipIf(sys.flags.optimize == 2, "no docstring if PYTHONOPTIMIZE=2") def test_json_method_doc(self): self.assertIn('FOO request', self.mock.foo_json.__doc__) self.assertIn('TestApp.foo', self.mock.foo_json.__doc__) diff --git a/webtest/utils.py b/webtest/utils.py index 3eb7f90..9ae1377 100644 --- a/webtest/utils.py +++ b/webtest/utils.py @@ -36,7 +36,12 @@ def json_method(method): return self._gen_request(method, url, **kw) subst = dict(lmethod=method.lower(), method=method) - wrapper.__doc__ = json_method.__doc__ % subst + + try: + wrapper.__doc__ = json_method.__doc__ % subst + except TypeError: + pass + wrapper.__name__ = str('%(lmethod)s_json' % subst) return wrapper |