forked from OpenJUB/jay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_pep8.py
37 lines (26 loc) · 993 Bytes
/
check_pep8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import unittest
import pep8
ignore_patterns = (
'env', '.git', '__pycache__', 'filters/migrations', 'settings/migrations',
'users/migrations', 'votes/migrations')
def _ignore(directory: str) -> bool:
"""Should the directory be ignored?"""
for pattern in ignore_patterns:
if pattern in directory:
return True
return False
class SanityTest(unittest.TestCase):
"""Run PEP8 on all files in this directory and subdirectories."""
def test_pep8_compliance(self):
style = pep8.StyleGuide(quiet=False)
errors = 0
for root, _, files in os.walk('.'):
if _ignore(root):
continue
python_files = [os.path.join(root, f) for f in files if
f.endswith('.py')]
errors += style.check_files(python_files).total_errors
self.assertEqual(errors, 0, 'PEP8 style errors: {}'.format(errors))
if __name__ == '__main__':
unittest.main()