-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_regex.py
81 lines (71 loc) · 2.46 KB
/
test_regex.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
import unittest
import re
from regex import regex
class TestRegex(unittest.TestCase):
def match_regex_dict(self, str, dict):
redict = re.compile(regex, re.X).match(str).groupdict()
self.assertEqual(redict, dict)
def test_output_with_rule_prepended(self):
str = '177:24 colors warning hexidecimal color should be a variable'
dict = {
'filename': None,
'line': '177',
'col': '24',
'rule': 'colors',
'warning': 'warning',
'error': None,
'message': 'hexidecimal color should be a variable'
}
self.match_regex_dict(str, dict)
def test_output_with_rule_appended(self):
str = '177:24 warning hexidecimal color should be a variable colors'
dict = {
'filename': None,
'line': '177',
'col': '24',
'rule': None,
'warning': 'warning',
'error': None,
'message': 'hexidecimal color should be a variable colors'
}
self.match_regex_dict(str, dict)
def test_output_with_no_col(self):
str = '177 warning hexidecimal color should be a variable'
dict = {
'filename': None,
'line': '177',
'col': None,
'rule': None,
'warning': 'warning',
'error': None,
'message': 'hexidecimal color should be a variable'
}
self.match_regex_dict(str, dict)
def test_multiline_output(self):
str = '/path/to/file/example.styl\n\n' \
'31:10 colons error missing colon between property and value'
dict = {
'filename': None,
'line': '31',
'col': '10',
'rule': 'colons',
'warning': None,
'error': 'error',
'message': 'missing colon between property and value'
}
self.match_regex_dict(str, dict)
def test_prepended_filename(self):
str = '/path/to/file/example.styl ' \
'31:10 colons error missing colon between property and value'
dict = {
'filename': '/path/to/file/example.styl',
'line': '31',
'col': '10',
'rule': 'colons',
'warning': None,
'error': 'error',
'message': 'missing colon between property and value'
}
self.match_regex_dict(str, dict)
if __name__ == '__main__':
unittest.main()