Skip to content

Commit a8d871c

Browse files
committed
Add a flake8 check to the testsuite
1 parent 5e18bc3 commit a8d871c

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = E402,E731
3+
exclude = .git,__pycache__,build,dist,.eggs

requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pytest>=3.0.7
21
Cython>=0.25.2
2+
flake8>=3.4.1
3+
pytest>=3.0.7
34
uvloop>=0.8.0
4-

tests/test__sourcecode.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2016-present the asyncpg authors and contributors
2+
# <see AUTHORS file>
3+
#
4+
# This module is part of asyncpg and is released under
5+
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
6+
7+
import os
8+
import subprocess
9+
import sys
10+
import unittest
11+
12+
13+
def find_root():
14+
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15+
16+
17+
class TestFlake8(unittest.TestCase):
18+
19+
def test_flake8(self):
20+
root_path = find_root()
21+
config_path = os.path.join(root_path, '.flake8')
22+
if not os.path.exists(config_path):
23+
raise RuntimeError('could not locate .flake8 file')
24+
25+
try:
26+
import flake8 # NoQA
27+
except ImportError:
28+
raise unittest.SkipTest('flake8 module is missing')
29+
30+
for subdir in ['asyncpg', 'tests']:
31+
try:
32+
subprocess.run(
33+
[sys.executable, '-m', 'flake8', '--config', config_path],
34+
check=True,
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.PIPE,
37+
cwd=os.path.join(root_path, subdir))
38+
except subprocess.CalledProcessError as ex:
39+
output = ex.output.decode()
40+
raise AssertionError(
41+
'flake8 validation failed:\n{}'.format(output)) from None

tests/test_codecs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import math
1212
import random
1313
import struct
14-
import unittest
1514
import uuid
1615

1716
import asyncpg

tests/test_execute.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import asyncio
99
import asyncpg
10-
import inspect
11-
import warnings
1210

1311
from asyncpg import _testbase as tb
1412

0 commit comments

Comments
 (0)