forked from klen/pylama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
152 lines (113 loc) · 4.23 KB
/
tests.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import unittest
from pylama.config import parse_options
from pylama.core import run
from pylama.tasks import check_path, async_check_files
class LamaCoreTest(unittest.TestCase):
def test_filters(self):
from pylama.core import filter_errors
self.assertTrue(filter_errors(
dict(text='E'), select=['E'], ignore=['E101']
))
self.assertFalse(filter_errors(
dict(text='W'), select=['W100'], ignore=['W']
))
def test_parse_modeline(self):
from pylama.core import parse_modeline
code = """
bla bla bla
# lint_ignore=W12,E14:lint_select=R
"""
params = parse_modeline(code)
self.assertEqual(params, dict(
lint_ignore='W12,E14', lint_select='R'
))
def test_prepare_params(self):
from pylama.core import prepare_params
p1 = dict(lint_ignore='W', select='R01', lint=1)
p2 = dict(lint=0, lint_ignore='E34,R45', select='E')
params = prepare_params(p1, p2)
self.assertEqual(
params,
{
'ignore': set(['R45', 'E34', 'W']),
'select': set(['R01', 'E']),
'lint': 0,
}
)
class LamaTest(unittest.TestCase):
def test_lama(self):
errors = run(
'dummy.py', ignore=set(['M234', 'C']), config=dict(lint=1))
self.assertEqual(len(errors), 3)
def test_mccabe(self):
from pylama.lint.extensions import LINTERS
mccabe = LINTERS.get('mccabe')
errors = mccabe.run('dummy.py', '')
self.assertEqual(errors, [])
def test_pyflakes(self):
errors = run('dummy.py', linters=['pyflakes'])
self.assertFalse(errors)
def test_pep257(self):
errors = run('dummy.py', linters=['pep257'])
self.assertTrue(errors)
def test_ignore_select(self):
errors = run('dummy.py', ignore=['E301', 'C0110'])
self.assertEqual(len(errors), 2)
errors = run('dummy.py', ignore=['E3', 'C'])
self.assertEqual(len(errors), 2)
errors = run(
'dummy.py', ignore=['E3', 'C'], select=['E301'])
self.assertEqual(len(errors), 3)
self.assertTrue(errors[0]['col'])
def test_checkpath(self):
options = parse_options(linters=['pep8'])
errors = check_path('dummy.py', options)
self.assertTrue(errors)
self.assertEqual(errors[0]['rel'], 'dummy.py')
def test_async(self):
options = parse_options(async=True, linters=['pep8'])
errors = async_check_files(['dummy.py'], options)
self.assertTrue(errors)
def test_shell(self):
from pylama.main import shell, check_files
errors = shell('-o dummy dummy.py'.split(), error=False)
self.assertTrue(errors)
options = parse_options()
errors = check_files(['dummy.py'], options=options, error=False)
self.assertTrue(errors)
errors = shell(['unknown.py'], error=False)
self.assertFalse(errors)
@staticmethod
def test_git_hook():
from pylama.hook import git_hook
try:
git_hook()
raise AssertionError('Test failed.')
except SystemExit:
pass
@staticmethod
def test_hg_hook():
from pylama.hook import hg_hook
try:
hg_hook(None, dict())
raise AssertionError('Test failed.')
except SystemExit:
pass
def test_config(self):
from pylama.config import get_parser, get_config
parser = get_parser()
self.assertTrue(parser)
config = get_config()
self.assertTrue(config)
options = parse_options()
self.assertTrue(options)
self.assertTrue(options.skip)
self.assertEqual(options.path, 'pylama')
options = parse_options(['-l', 'pep257,pep8', '-i', 'E'])
linters, _ = zip(*options.linters)
self.assertEqual(set(linters), set(['pep257', 'pep8']))
self.assertEqual(options.ignore, ['E'])
options = parse_options('-o dummy dummy.py'.split())
linters, _ = zip(*options.linters)
self.assertEqual(set(linters), set(['pep8', 'mccabe', 'pyflakes']))
self.assertEqual(options.skip, [])