Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit baad744

Browse files
committed
Update tests
Update tests to not use the regex directly but test what `find_errors` returns. - `find_errors` adjustes line/col to be 0-based - switch to `error_type` as we support "notes" now
1 parent 05c4128 commit baad744

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

tests/test_regex.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,48 @@
33
import re
44
import importlib
55

6+
import sublime
7+
68
LinterModule = importlib.import_module('SublimeLinter-mypy.linter')
79
Linter = LinterModule.Mypy
8-
regex = Linter.regex
910

1011

1112
class TestRegex(unittest.TestCase):
12-
1313
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)
1719

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)
2024

2125
def test_no_matches(self):
22-
self.assertMatchIsNone('')
23-
self.assertMatchIsNone('foo')
26+
self.assertNoMatch('')
27+
self.assertNoMatch('foo')
2428

2529
def test_matches(self):
2630
self.assertMatch(
2731
'/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,
3235
'message': 'No return value expected'})
3336

3437
self.assertMatch(
3538
'/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,
3841
'col': None,
39-
'warning': None,
4042
'message': '"dict" is not subscriptable, use "typing.Dict" instead'})
4143

4244
def test_tmp_files_that_have_no_file_extension(self):
4345
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,
4950
'message': 'Cannot find module named \'PackageName.lib\''})

0 commit comments

Comments
 (0)