|
3 | 3 | import re |
4 | 4 | import importlib |
5 | 5 |
|
| 6 | +import sublime |
| 7 | + |
6 | 8 | LinterModule = importlib.import_module('SublimeLinter-mypy.linter') |
7 | 9 | Linter = LinterModule.Mypy |
8 | | -regex = Linter.regex |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class TestRegex(unittest.TestCase): |
12 | | - |
13 | 13 | def assertMatch(self, string, expected): |
14 | | - match = re.match(regex, string) |
15 | | - self.assertIsNotNone(match) |
16 | | - self.assertEqual(match.groupdict(), expected) |
| 14 | + linter = Linter(sublime.View(0), {}) |
| 15 | + actual = list(linter.find_errors(string))[0] |
| 16 | + # `find_errors` fills out more information we don't want to write down |
| 17 | + # in the examples |
| 18 | + self.assertEqual({k: actual[k] for k in expected.keys()}, expected) |
17 | 19 |
|
18 | | - def assertMatchIsNone(self, string): |
19 | | - self.assertIsNone(re.match(regex, string)) |
| 20 | + def assertNoMatch(self, string): |
| 21 | + linter = Linter(sublime.View(0), {}) |
| 22 | + actual = list(linter.find_errors(string)) |
| 23 | + self.assertFalse(actual) |
20 | 24 |
|
21 | 25 | def test_no_matches(self): |
22 | | - self.assertMatchIsNone('') |
23 | | - self.assertMatchIsNone('foo') |
| 26 | + self.assertNoMatch('') |
| 27 | + self.assertNoMatch('foo') |
24 | 28 |
|
25 | 29 | def test_matches(self): |
26 | 30 | self.assertMatch( |
27 | 31 | '/path/to/package/module.py:18:4: error: No return value expected', { |
28 | | - 'error': 'error', |
29 | | - 'line': '18', |
30 | | - 'col': '4', |
31 | | - 'warning': None, |
| 32 | + 'error_type': 'error', |
| 33 | + 'line': 17, |
| 34 | + 'col': 3, |
32 | 35 | 'message': 'No return value expected'}) |
33 | 36 |
|
34 | 37 | self.assertMatch( |
35 | 38 | '/path/to/package/module.py:40: error: "dict" is not subscriptable, use "typing.Dict" instead', { |
36 | | - 'error': 'error', |
37 | | - 'line': '40', |
| 39 | + 'error_type': 'error', |
| 40 | + 'line': 39, |
38 | 41 | 'col': None, |
39 | | - 'warning': None, |
40 | 42 | 'message': '"dict" is not subscriptable, use "typing.Dict" instead'}) |
41 | 43 |
|
42 | 44 | def test_tmp_files_that_have_no_file_extension(self): |
43 | 45 | self.assertMatch( |
44 | | - '/tmp/yoeai32h2:6:0: error: Cannot find module named \'PackageName.lib\'', { |
45 | | - 'error': 'error', |
46 | | - 'line': '6', |
47 | | - 'col': '0', |
48 | | - 'warning': None, |
| 46 | + '/tmp/yoeai32h2:6:1: error: Cannot find module named \'PackageName.lib\'', { |
| 47 | + 'error_type': 'error', |
| 48 | + 'line': 5, |
| 49 | + 'col': 0, |
49 | 50 | 'message': 'Cannot find module named \'PackageName.lib\''}) |
0 commit comments