Skip to content

Commit 5d0da16

Browse files
author
Ayala Shachar
committed
Add pylint
1 parent 0a67e7f commit 5d0da16

10 files changed

Lines changed: 43 additions & 24 deletions

File tree

.pylintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[MESSAGES CONTROL]
2+
disable= R,attribute-defined-outside-init,bad-continuation,bad-option-value,bare-except,invalid-name,locally-disabled,missing-docstring,redefined-builtin,ungrouped-imports,wrong-import-order,wrong-import-position,unnecessary-pass,global-statement
3+
4+
[REPORTS]
5+
reports=no
6+
7+
[FORMAT]
8+
max-line-length=150

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
default: test
22

33
test: env
4-
.env/bin/py.test tests
4+
.env/bin/pytest tests
5+
.env/bin/pylint --rcfile .pylintrc flask_loopback tests setup.py
56

67
env: .env/.up-to-date
78

flask_loopback/_compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=import-error,unused-import
12
from contextlib import contextmanager
23
import gzip
34
import sys

flask_loopback/flask_loopback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def handle_request(self, session, url, request):
7777
return e.response
7878

7979
self._test_client.cookie_jar.clear()
80-
for cookie in request._cookies:
80+
for cookie in request._cookies: # pylint: disable=protected-access
8181
self._test_client.cookie_jar.set_cookie(cookie)
8282
resp = self._test_client.open(path, **open_kwargs)
8383
returned = requests.Response()

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ url = https://github.com/vmalloc/flask-loopback
1717
[extras]
1818
testing =
1919
pytest
20+
astroid~=1.5.3; python_version=='2.7'
21+
astroid>=2.0; python_version >= '3.4'
22+
pylint~=1.7.2; python_version=='2.7'
23+
pylint~=2.3.1; python_version >= '3.4'
2024

2125
[tool:pytest]
2226
testpaths = tests

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gzip
21
import hashlib
32

43
import pytest

tests/test_flask_loopback.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
_g_counter = 0
1616

1717
def create_sample_app():
18+
# pylint: disable=unused-variable
1819
returned = flask.Flask(__name__)
1920

2021
@returned.route("/sample/url")
@@ -36,6 +37,7 @@ def get_remote_addr():
3637
return returned, l
3738

3839
class FlaskLoopbackActivationTest(TestCase):
40+
# pylint: disable=protected-access
3941

4042
def setUp(self):
4143
super(FlaskLoopbackActivationTest, self).setUp()
@@ -45,9 +47,9 @@ def setUp(self):
4547
self.loopback.activate_address(("b.com", 1234))
4648

4749
def test_deactivate_one_by_one(self):
48-
self.assertEquals(len(dispatch._registered_addresses), 2)
50+
self.assertEqual(len(dispatch._registered_addresses), 2)
4951
self.loopback.deactivate_address(("a.com", 123))
50-
self.assertEquals(len(dispatch._registered_addresses), 1)
52+
self.assertEqual(len(dispatch._registered_addresses), 1)
5153
with self.assertRaises(LookupError):
5254
self.loopback.deactivate_address(("a.com", 123))
5355
self.loopback.deactivate_address(("b.com", 1234))
@@ -65,18 +67,18 @@ def setUp(self):
6567
self.address = ("somehost.com", 1234)
6668
self.root_url = _url(self.address)
6769
self._ctx = self.loopback.on(self.address)
68-
ctx_result = self._ctx.__enter__()
70+
ctx_result = self._ctx.__enter__() # pylint: disable=unused-variable
6971
self.addCleanup(self._ctx.__exit__, None, None, None)
7072

7173
def test_simple_request(self):
72-
self.assertEquals(requests.get(self.root_url.add_path("/sample/url")).content.decode("utf-8"), OK_RESPONSE)
74+
self.assertEqual(requests.get(self.root_url.add_path("/sample/url")).content.decode("utf-8"), OK_RESPONSE)
7375

7476
def test_response_attributes(self):
7577
url = self.root_url
7678
response = requests.get(url)
77-
self.assertEquals(response.url, url)
78-
self.assertEquals(response.request.url, url)
79-
self.assertEquals(response.request.method, "GET")
79+
self.assertEqual(response.url, url)
80+
self.assertEqual(response.request.url, url)
81+
self.assertEqual(response.request.method, "GET")
8082

8183
def test_remote_addr(self):
8284
response = requests.get(self.root_url.add_path('remote_addr'))
@@ -85,35 +87,35 @@ def test_remote_addr(self):
8587

8688
def test_not_found(self):
8789
response = requests.get(self.root_url.add_path("not_found"))
88-
self.assertEquals(response.status_code, httplib.NOT_FOUND)
89-
self.assertEquals(response.reason, "Not Found")
90+
self.assertEqual(response.status_code, httplib.NOT_FOUND)
91+
self.assertEqual(response.reason, "Not Found")
9092

9193
def test_request_context_handler(self):
9294
initial_counter = _g_counter
9395

9496
@self.loopback.register_request_context_handler
9597
@contextmanager
96-
def increase_counter(request):
98+
def increase_counter(request): # pylint: disable=unused-argument,unused-variable
9799
global _g_counter
98100
_g_counter += 1
99101
yield
100102
_g_counter += 1
101103

102104
returned = requests.get(self.root_url.add_path("increase_counter")).json()["result"]
103-
self.assertEquals(_g_counter, initial_counter + 3)
104-
self.assertEquals(returned, initial_counter + 2)
105+
self.assertEqual(_g_counter, initial_counter + 3)
106+
self.assertEqual(returned, initial_counter + 2)
105107

106108
def test_request_context_handler_custom_response(self):
107109
initial_counter = _g_counter
108110

109111
@self.loopback.register_request_context_handler
110112
@contextmanager
111-
def return_custom_code(request):
113+
def return_custom_code(request): # pylint: disable=unused-variable
112114
raise CustomHTTPResponse(request, 666)
113115

114116
response = requests.get(self.root_url.add_path("increase_counter"))
115117
assert response.status_code == 666
116-
self.assertEquals(_g_counter, initial_counter)
118+
self.assertEqual(_g_counter, initial_counter)
117119
self.assertIsNone(response.content)
118120

119121

tests/test_readme.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import os
33
import doctest
44

5+
56
class ReadMeDocTest(TestCase):
67
def test_readme_doctests(self):
78
readme_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "README.md"))
89
self.assertTrue(os.path.exists(readme_path))
910
result = doctest.testfile(readme_path, module_relative=False)
10-
self.assertEquals(result.failed, 0, "%s tests failed!" % result.failed)
11+
self.assertEqual(result.failed, 0, "%s tests failed!" % result.failed)

tests/test_request_attributes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import pytest
12
import requests
23

3-
def test_request_host(active_app, url):
4+
5+
@pytest.mark.usefixtures('active_app')
6+
def test_request_host(url):
47
assert requests.get(url.add_path('request_vars')).json()['host'] == url.netloc

tests/test_ssl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import ssl
2-
32
import requests
4-
53
import pytest
64

75

8-
def test_ssl_fails_for_non_ssl_port(active_app, hostname, ssl_port, non_ssl_port):
6+
@pytest.mark.usefixtures('active_app', 'ssl_port')
7+
def test_ssl_fails_for_non_ssl_port(hostname, non_ssl_port):
98
with pytest.raises(ssl.SSLError):
109
requests.get("https://{0}:{1}".format(hostname, non_ssl_port))
1110

12-
def test_non_ssl_fails_for_ssl_port(active_app, hostname, ssl_port, non_ssl_port):
11+
12+
@pytest.mark.usefixtures('active_app', 'non_ssl_port')
13+
def test_non_ssl_fails_for_ssl_port(hostname, ssl_port):
1314
with pytest.raises(requests.ConnectionError):
1415
requests.get("http://{0}:{1}".format(hostname, ssl_port))
15-

0 commit comments

Comments
 (0)