|
1 | 1 | import unittest
|
| 2 | +import enum |
2 | 3 | from test.asserting.policy import PolicyAssertion, get_fixture_path
|
3 |
| - |
4 | 4 | from vint.linting.level import Level
|
5 | 5 | from vint.linting.policy.prohibit_unused_variable import ProhibitUnusedVariable
|
6 | 6 |
|
7 |
| -PATH_VALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_valid.vim') |
8 |
| -PATH_INVALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_invalid.vim') |
| 7 | +class Fixtures(enum.Enum): |
| 8 | + VALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_valid.vim') |
| 9 | + INVALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_invalid.vim') |
| 10 | + ISSUE_274 = get_fixture_path('prohibit_unused_variable_issue_274.vim') |
| 11 | + IGNORED_PATTERNS = get_fixture_path('prohibit_unused_variable_ignored_patterns.vim') |
| 12 | + README = get_fixture_path('prohibit_unused_variable_readme.vim') |
9 | 13 |
|
10 | 14 |
|
11 | 15 | class TestProhibitUnusedVariable(PolicyAssertion, unittest.TestCase):
|
12 | 16 | def test_get_violation_if_found_when_file_is_valid(self):
|
13 |
| - self.assertFoundNoViolations(PATH_VALID_VIM_SCRIPT, |
| 17 | + self.assertFoundNoViolations(Fixtures.VALID_VIM_SCRIPT.value, |
14 | 18 | ProhibitUnusedVariable)
|
15 | 19 |
|
16 | 20 |
|
17 |
| - def create_violation(self, line, column): |
| 21 | + def create_violation(self, line, column, path): |
18 | 22 | return {
|
19 | 23 | 'name': 'ProhibitUnusedVariable',
|
20 | 24 | 'level': Level.WARNING,
|
21 | 25 | 'position': {
|
22 | 26 | 'line': line,
|
23 | 27 | 'column': column,
|
24 |
| - 'path': PATH_INVALID_VIM_SCRIPT |
| 28 | + 'path': path |
25 | 29 | }
|
26 | 30 | }
|
27 | 31 |
|
28 | 32 |
|
29 | 33 | def test_get_violation_if_found_when_file_is_invalid(self):
|
30 | 34 | expected_violations = [
|
31 |
| - self.create_violation(2, 5), |
32 |
| - self.create_violation(4, 11), |
33 |
| - self.create_violation(7, 25), |
34 |
| - self.create_violation(7, 36), |
35 |
| - self.create_violation(11, 9), |
36 |
| - self.create_violation(12, 9), |
| 35 | + self.create_violation(2, 5, Fixtures.INVALID_VIM_SCRIPT.value), |
| 36 | + self.create_violation(4, 11, Fixtures.INVALID_VIM_SCRIPT.value), |
| 37 | + self.create_violation(7, 25, Fixtures.INVALID_VIM_SCRIPT.value), |
| 38 | + self.create_violation(7, 36, Fixtures.INVALID_VIM_SCRIPT.value), |
| 39 | + self.create_violation(11, 9, Fixtures.INVALID_VIM_SCRIPT.value), |
| 40 | + self.create_violation(12, 9, Fixtures.INVALID_VIM_SCRIPT.value), |
| 41 | + self.create_violation(15, 8, Fixtures.INVALID_VIM_SCRIPT.value), |
37 | 42 | ]
|
38 | 43 |
|
39 |
| - self.assertFoundViolationsEqual(PATH_INVALID_VIM_SCRIPT, |
| 44 | + self.assertFoundViolationsEqual(Fixtures.INVALID_VIM_SCRIPT.value, |
40 | 45 | ProhibitUnusedVariable,
|
41 | 46 | expected_violations)
|
42 | 47 |
|
| 48 | + def test_issue_274(self): |
| 49 | + self.assertFoundNoViolations(Fixtures.ISSUE_274.value, ProhibitUnusedVariable) |
| 50 | + |
| 51 | + |
| 52 | + def test_ignored_patterns(self): |
| 53 | + expected_violations = [ |
| 54 | + self.create_violation(1, 5, Fixtures.IGNORED_PATTERNS.value), |
| 55 | + ] |
| 56 | + |
| 57 | + self.assertFoundViolationsEqual(Fixtures.IGNORED_PATTERNS.value, |
| 58 | + ProhibitUnusedVariable, |
| 59 | + expected_violations, |
| 60 | + policy_options={'ignored_patterns': ['_ignored$']}) |
| 61 | + |
| 62 | + |
| 63 | + def test_readme(self): |
| 64 | + self.assertFoundNoViolations(Fixtures.README.value, |
| 65 | + ProhibitUnusedVariable) |
| 66 | + |
| 67 | + |
43 | 68 | if __name__ == '__main__':
|
44 | 69 | unittest.main()
|
0 commit comments