-
Notifications
You must be signed in to change notification settings - Fork 752
/
Copy pathtest_all.py
75 lines (59 loc) · 2.42 KB
/
test_all.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os.path
import sys
import unittest
import pycodestyle
from testsuite.support import init_tests, selftest, ROOT_DIR
# Note: please only use a subset of unittest methods which were present
# in Python 2.5: assert(True|False|Equal|NotEqual|Raises)
class PycodestyleTestCase(unittest.TestCase):
"""Test the standard errors and warnings (E and W)."""
def setUp(self):
self._style = pycodestyle.StyleGuide(
paths=[os.path.join(ROOT_DIR, 'testsuite')],
select='E,W', quiet=True)
def test_doctest(self):
import doctest
fail_d, done_d = doctest.testmod(
pycodestyle, verbose=False, report=False
)
self.assertTrue(done_d, msg='tests not found')
self.assertFalse(fail_d, msg='%s failure(s)' % fail_d)
def test_selftest(self):
fail_s, done_s = selftest(self._style.options)
self.assertTrue(done_s, msg='tests not found')
self.assertFalse(fail_s, msg='%s failure(s)' % fail_s)
def test_checkers_testsuite(self):
init_tests(self._style)
report = self._style.check_files()
self.assertFalse(report.total_errors,
msg='%s failure(s)' % report.total_errors)
def test_own_dog_food(self):
files = [pycodestyle.__file__.rstrip('oc'), __file__.rstrip('oc'),
os.path.join(ROOT_DIR, 'setup.py')]
report = self._style.init_report(pycodestyle.StandardReport)
report = self._style.check_files(files)
self.assertEqual(report.messages[0][2], 'W504',
msg='Failures: %s' % report.messages)
def suite():
from testsuite import (
test_api,
test_blank_lines,
test_parser,
test_shell,
test_util,
)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(PycodestyleTestCase))
suite.addTest(unittest.makeSuite(test_api.APITestCase))
suite.addTest(unittest.makeSuite(test_blank_lines.TestBlankLinesDefault))
suite.addTest(unittest.makeSuite(test_blank_lines.TestBlankLinesTwisted))
suite.addTest(unittest.makeSuite(test_parser.ParserTestCase))
suite.addTest(unittest.makeSuite(test_shell.ShellTestCase))
suite.addTest(unittest.makeSuite(test_util.UtilTestCase))
return suite
def _main():
return unittest.TextTestRunner(verbosity=2).run(suite())
if __name__ == '__main__':
sys.exit(not _main())