summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2014-04-16 22:23:10 +0200
committerGael Pasgrimaud <gael@gawel.org>2014-04-16 22:23:10 +0200
commitd2471e042c5b33100bb742247b7ef44c1ff9ea02 (patch)
treec211d5ab50609fd18006b1b51ae8ab4e1f02a668
parent6a0435bb75ca02f3dac157f06b49b757aede04d9 (diff)
downloadwebtest-d2471e042c5b33100bb742247b7ef44c1ff9ea02.tar.gz
pep8 everywhere
-rw-r--r--tests/compat.py4
-rw-r--r--tests/test_debugapp.py9
-rw-r--r--tests/test_forms.py42
-rw-r--r--tests/test_http.py16
-rw-r--r--tests/test_lint.py17
-rw-r--r--webtest/forms.py13
-rw-r--r--webtest/lint.py30
-rw-r--r--webtest/response.py11
8 files changed, 76 insertions, 66 deletions
diff --git a/tests/compat.py b/tests/compat.py
index 2adfc2f..510db92 100644
--- a/tests/compat.py
+++ b/tests/compat.py
@@ -4,12 +4,13 @@ try:
# py < 2.7
import unittest2 as unittest
except ImportError:
- import unittest
+ import unittest # noqa
try:
unicode()
except NameError:
b = bytes
+
def u(value):
if isinstance(value, bytes):
return value.decode('utf-8')
@@ -17,6 +18,7 @@ except NameError:
else:
def b(value):
return str(value)
+
def u(value):
if isinstance(value, unicode):
return value
diff --git a/tests/test_debugapp.py b/tests/test_debugapp.py
index 5793a81..2375f8c 100644
--- a/tests/test_debugapp.py
+++ b/tests/test_debugapp.py
@@ -45,12 +45,14 @@ class TestTesting(unittest.TestCase):
self.assertEqual(res.body, to_bytes(''))
def test_post_unicode(self):
- res = self.app.post('/', params=dict(a='é'),
+ res = self.app.post(
+ '/', params=dict(a='é'),
content_type='application/x-www-form-urlencoded;charset=utf8')
res.mustcontain('a=%C3%A9')
def test_post_unicode_body(self):
- res = self.app.post('/', params='é',
+ res = self.app.post(
+ '/', params='é',
content_type='text/plain; charset=utf8')
self.assertTrue(res.body.endswith(b'\xc3\xa9'))
res.mustcontain('é')
@@ -86,7 +88,7 @@ class TestTesting(unittest.TestCase):
def test_exception(self):
self.assertRaises(Exception, self.app.get, '/?error=t')
self.assertRaises(webtest.AppError, self.app.get,
- '/?status=404%20Not%20Found')
+ '/?status=404%20Not%20Found')
def test_bad_content_type(self):
resp = self.app.get('/')
@@ -102,7 +104,6 @@ class TestTesting(unittest.TestCase):
resp = app.get('/')
self.assertEqual(resp.status_int, 200)
-
def test_errors(self):
try:
self.app.get('/?errorlog=somelogs')
diff --git a/tests/test_forms.py b/tests/test_forms.py
index 6c8a233..fffa632 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -44,19 +44,23 @@ class TestForms(unittest.TestCase):
form['select'].force_value('notavalue')
form['select'].value__set('value3')
- self.assertTrue(form['select']._forced_value is NoValue,
+ self.assertTrue(
+ form['select']._forced_value is NoValue,
"Setting a value after having forced a value should keep a forced"
" state")
- self.assertEqual(form['select'].value, 'value3',
+ self.assertEqual(
+ form['select'].value, 'value3',
"the value should the the one set by value__set")
- self.assertEqual(form['select'].selectedIndex, 2,
+ self.assertEqual(
+ form['select'].selectedIndex, 2,
"the value index should be the one set by value__set")
def test_form_select(self):
form = self.callFUT()
form.select('select', 'value1')
- self.assertEqual(form['select'].value, 'value1',
+ self.assertEqual(
+ form['select'].value, 'value1',
"when using form.select, the input selected value should be "
"changed")
@@ -262,8 +266,7 @@ def select_app(environ, start_response):
req = Request(environ)
status = b"200 OK"
if req.method == "GET":
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>form page</title></head>
<body>
@@ -294,8 +297,7 @@ def select_app(environ, start_response):
selection = req.POST.get("single")
elif select_type == "multiple":
selection = ", ".join(req.POST.getall("multiple"))
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>display page</title></head>
<body>
@@ -316,8 +318,7 @@ def select_app_without_values(environ, start_response):
req = Request(environ)
status = b"200 OK"
if req.method == "GET":
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>form page</title></head>
<body>
@@ -348,8 +349,7 @@ def select_app_without_values(environ, start_response):
selection = req.POST.get("single")
elif select_type == "multiple":
selection = ", ".join(req.POST.getall("multiple"))
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>display page</title></head>
<body>
@@ -370,8 +370,7 @@ def select_app_without_default(environ, start_response):
req = Request(environ)
status = b"200 OK"
if req.method == "GET":
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>form page</title></head>
<body>
@@ -402,8 +401,7 @@ def select_app_without_default(environ, start_response):
selection = req.POST.get("single")
elif select_type == "multiple":
selection = ", ".join(req.POST.getall("multiple"))
- body = to_bytes(
-"""
+ body = to_bytes("""
<html>
<head><title>display page</title></head>
<body>
@@ -424,8 +422,7 @@ def select_app_unicode(environ, start_response):
req = Request(environ)
status = b"200 OK"
if req.method == "GET":
- body =\
-u("""
+ body = u("""
<html>
<head><title>form page</title></head>
<body>
@@ -456,8 +453,7 @@ u("""
selection = req.POST.get("single")
elif select_type == "multiple":
selection = ", ".join(req.POST.getall("multiple"))
- body = (
-u("""
+ body = (u("""
<html>
<head><title>display page</title></head>
<body>
@@ -626,7 +622,7 @@ class TestSelect(unittest.TestCase):
self.assertEqual(multiple_form["multiple"].value, ["8", "11"],
multiple_form["multiple"].value)
self.assertRaises(ValueError, multiple_form.set,
- "multiple", ["24", "88"])
+ "multiple", ["24", "88"])
multiple_form["multiple"].force_value(["24", "88"])
self.assertEqual(multiple_form["multiple"].value, ["24", "88"],
multiple_form["multiple"].value)
@@ -845,7 +841,7 @@ class TestFileUpload(unittest.TestCase):
def test_file_upload_with_filename_and_contents(self):
uploaded_file_name = os.path.join(os.path.dirname(__file__),
- "__init__.py")
+ "__init__.py")
uploaded_file_contents = open(uploaded_file_name).read()
if PY3:
uploaded_file_contents = to_bytes(uploaded_file_contents)
@@ -865,7 +861,7 @@ class TestFileUpload(unittest.TestCase):
def test_file_upload_with_content_type(self):
uploaded_file_name = os.path.join(os.path.dirname(__file__),
- "__init__.py")
+ "__init__.py")
with open(uploaded_file_name, 'rb') as f:
uploaded_file_contents = f.read()
app = webtest.TestApp(SingleUploadFileApp())
diff --git a/tests/test_http.py b/tests/test_http.py
index dc7d6cb..f52a596 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -14,18 +14,18 @@ class TestServer(unittest.TestCase):
s = self.s
s.wait()
self.assertEqual(200,
- http.check_server(s.adj.host, s.adj.port,
- '/__application__'))
+ http.check_server(s.adj.host, s.adj.port,
+ '/__application__'))
self.assertEqual(200,
- http.check_server(s.adj.host, s.adj.port,
- '/__file__?__file__=' + __file__))
+ http.check_server(s.adj.host, s.adj.port,
+ '/__file__?__file__=' + __file__))
self.assertEqual(404,
- http.check_server(s.adj.host, s.adj.port,
- '/__file__?__file__=XXX'))
+ http.check_server(s.adj.host, s.adj.port,
+ '/__file__?__file__=XXX'))
self.assertEqual(304,
- http.check_server(s.adj.host, s.adj.port,
- '/?status=304'))
+ http.check_server(s.adj.host, s.adj.port,
+ '/?status=304'))
def test_wsgi_wrapper(self):
s = self.s
diff --git a/tests/test_lint.py b/tests/test_lint.py
index 394f1f2..60a30a5 100644
--- a/tests/test_lint.py
+++ b/tests/test_lint.py
@@ -169,7 +169,8 @@ class TestCheckEnviron(unittest.TestCase):
warnings.simplefilter("always")
check_environ(environ)
self.assertEqual(len(w), 1, "We should have only one warning")
- self.assertTrue("QUERY_STRING" in str(w[-1].message),
+ self.assertTrue(
+ "QUERY_STRING" in str(w[-1].message),
"The warning message should say something about QUERY_STRING")
def test_no_valid_request(self):
@@ -191,8 +192,10 @@ class TestCheckEnviron(unittest.TestCase):
warnings.simplefilter("always")
check_environ(environ)
self.assertEqual(len(w), 1, "We should have only one warning")
- self.assertTrue("REQUEST_METHOD" in str(w[-1].message),
- 'The warning message should say something about REQUEST_METHOD')
+ self.assertTrue(
+ "REQUEST_METHOD" in str(w[-1].message),
+ "The warning message should say something "
+ "about REQUEST_METHOD")
def test_handles_native_strings_in_variables(self):
# "native string" means unicode in py3, but bytes in py2
@@ -261,7 +264,8 @@ class TestWriteWrapper(unittest.TestCase):
mock = MockWriter()
write_wrapper = WriteWrapper(mock)
write_wrapper(data)
- self.assertEqual(mock.written, [data],
+ self.assertEqual(
+ mock.written, [data],
"WriterWrapper should call original writer when data is binary "
"type")
@@ -293,11 +297,12 @@ class TestErrorWrapper(unittest.TestCase):
data = [to_bytes('a line'), to_bytes('another line')]
error_wrapper.writelines(data)
self.assertEqual(fake_error.written, data,
- "ErrorWrapper should call original writer")
+ "ErrorWrapper should call original writer")
def test_flush(self):
fake_error = self.FakeError()
error_wrapper = ErrorWrapper(fake_error)
error_wrapper.flush()
- self.assertTrue(fake_error.flushed,
+ self.assertTrue(
+ fake_error.flushed,
"ErrorWrapper should have called original wsgi_errors's flush")
diff --git a/webtest/forms.py b/webtest/forms.py
index a6df599..c9c7ee0 100644
--- a/webtest/forms.py
+++ b/webtest/forms.py
@@ -141,8 +141,7 @@ class Select(Field):
else:
raise ValueError(
"Option %r not found (from %s)"
- % (value, ', '.join(
- [repr(o) for o, c, t in self.options])))
+ % (value, ', '.join([repr(o) for o, c, t in self.options])))
def value__get(self):
if self._forced_value is not NoValue:
@@ -476,9 +475,10 @@ class Form(object):
if tag == 'select':
for option in node('option'):
- field.options.append((option.attrs.get('value', option.text),
- 'selected' in option.attrs,
- option.text))
+ field.options.append(
+ (option.attrs.get('value', option.text),
+ 'selected' in option.attrs,
+ option.text))
self.field_order = field_order
self.fields = fields
@@ -646,7 +646,8 @@ class Form(object):
if submit_name is not None and name == submit_name:
if index is not None and current_index == index:
submit.append((name, field.value_if_submitted()))
- if submit_value is not None and field.value_if_submitted() == submit_value:
+ if submit_value is not None and \
+ field.value_if_submitted() == submit_value:
submit.append((name, field.value_if_submitted()))
current_index += 1
else:
diff --git a/webtest/lint.py b/webtest/lint.py
index 4e7c52c..6906089 100644
--- a/webtest/lint.py
+++ b/webtest/lint.py
@@ -395,23 +395,27 @@ def check_status(status):
assert type(status) in METADATA_TYPE, (
"Status must be a %s (not %r)" % (METADATA_TYPE, status))
status = to_string(status)
- assert len(status) > 5, ("The status string (%r) should be a three-digit "
+ assert len(status) > 5, (
+ "The status string (%r) should be a three-digit "
"integer followed by a single space and a status explanation"
- % status)
- assert status[:3].isdigit(), ("The status string (%r) should start with"
- "three digits" % status)
+ ) % status
+ assert status[:3].isdigit(), (
+ "The status string (%r) should start with"
+ "three digits") % status
status_int = int(status[:3])
- assert status_int >= 100, ("The status code must be greater or equal than "
- "100 (got %d)" % status_int)
- assert status[3] == ' ', ("The status string (%r) should start with three"
- "digits and a space (4th characters is not a space here)" % status)
+ assert status_int >= 100, (
+ "The status code must be greater or equal than "
+ "100 (got %d)") % status_int
+ assert status[3] == ' ', (
+ "The status string (%r) should start with three"
+ "digits and a space (4th characters is not a space here)") % status
def _assert_latin1_py3(string, message):
if PY3 and type(string) is str:
try:
- string.encode('latin1')
+ string.encode('latin1')
except UnicodeEncodeError:
raise AssertionError(message)
@@ -427,7 +431,7 @@ def check_headers(headers):
assert len(item) == 2
name, value = item
_assert_latin1_py3(
- name,
+ name,
"Headers values must be latin1 string or bytes."
"%r is not a valid latin1 string" % (value,)
)
@@ -442,7 +446,7 @@ def check_headers(headers):
assert not str_name.endswith('-') and not str_name.endswith('_'), (
"Names may not end in '-' or '_': %r" % name)
_assert_latin1_py3(
- value,
+ value,
"Headers values must be latin1 string or bytes."
"%r is not a valid latin1 string" % (value,)
)
@@ -472,7 +476,7 @@ def check_content_type(status, headers):
elif length == 0:
warnings.warn(("Content-Type header found in a %s response, "
"which not return content.") % code,
- WSGIWarning)
+ WSGIWarning)
return
else:
assert 0, (("Content-Type header found in a %s response, "
@@ -480,11 +484,13 @@ def check_content_type(status, headers):
if code not in NO_MESSAGE_BODY and length is not None and length > 0:
assert 0, "No Content-Type header found in headers (%s)" % headers
+
def check_exc_info(exc_info):
assert exc_info is None or type(exc_info) is tuple, (
"exc_info (%r) is not a tuple: %r" % (exc_info, type(exc_info)))
# More exc_info checks?
+
def check_iterator(iterator):
valid_type = PY3 and bytes or str
# Technically a bytes (str for py2.x) is legal, which is why it's a
diff --git a/webtest/response.py b/webtest/response.py
index b9f2c24..bca7c6f 100644
--- a/webtest/response.py
+++ b/webtest/response.py
@@ -107,7 +107,7 @@ class TestResponse(webob.Response):
Any keyword arguments are passed to :class:`webtest.app.TestApp.get`.
Returns another :class:`TestResponse` object.
"""
- remaining_redirects = 100 # infinite loops protection
+ remaining_redirects = 100 # infinite loops protection
response = self
while 300 <= response.status_int < 400 and remaining_redirects:
@@ -301,8 +301,7 @@ class TestResponse(webob.Response):
Return the whitespace-normalized body
"""
if getattr(self, '_normal_body', None) is None:
- self._normal_body = self._normal_body_regex.sub(
- b' ', self.body)
+ self._normal_body = self._normal_body_regex.sub(b' ', self.body)
return self._normal_body
_unicode_normal_body_regex = re.compile('[ \\n\\r\\t]+')
@@ -318,7 +317,7 @@ class TestResponse(webob.Response):
"unless charset is set"))
if getattr(self, '_unicode_normal_body', None) is None:
self._unicode_normal_body = self._unicode_normal_body_regex.sub(
- ' ', self.testbody)
+ ' ', self.testbody)
return self._unicode_normal_body
def __contains__(self, s):
@@ -468,8 +467,8 @@ class TestResponse(webob.Response):
have an earlier version of lxml then a ``lxml.HTML`` object
will be returned.
"""
- if ('html' not in self.content_type
- and 'xml' not in self.content_type):
+ if 'html' not in self.content_type and \
+ 'xml' not in self.content_type:
raise AttributeError(
"Not an XML or HTML response body (content-type: %s)"
% self.content_type)