1 | import unittest |
||
2 | from os.path import relpath |
||
3 | |||
4 | from coalib.results.SourcePosition import SourcePosition |
||
5 | from coalib.misc.ContextManagers import prepare_file |
||
6 | |||
7 | |||
8 | class SourcePositionTest(unittest.TestCase): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
9 | |||
10 | def test_initialization(self): |
||
11 | with self.assertRaises(TypeError): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
12 | SourcePosition(None, 0) |
||
13 | |||
14 | with self.assertRaises(ValueError): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
15 | SourcePosition("file", None, 1) |
||
16 | |||
17 | # However these should work: |
||
18 | SourcePosition("file", None, None) |
||
19 | SourcePosition("file", 4, None) |
||
20 | SourcePosition("file", 4, 5) |
||
21 | |||
22 | def test_string_conversion(self): |
||
23 | uut = SourcePosition("filename", 1) |
||
24 | self.assertRegex( |
||
25 | repr(uut), |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
26 | "<SourcePosition object\\(file='.*filename', line=1, " |
||
27 | "column=None\\) at 0x[0-9a-fA-F]+>") |
||
28 | |||
29 | uut = SourcePosition("None", None) |
||
30 | self.assertRegex( |
||
31 | repr(uut), |
||
32 | "<SourcePosition object\\(file='.*None', line=None, column=None\\) " |
||
33 | "at 0x[0-9a-fA-F]+>") |
||
34 | |||
35 | def test_json(self): |
||
36 | with prepare_file([""], None) as (_, filename): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
37 | uut = SourcePosition(filename, 1) |
||
38 | self.assertEqual(uut.__json__(use_relpath=True) |
||
39 | ['file'], relpath(filename)) |
||
40 | |||
41 | def assert_equal(self, first, second): |
||
42 | self.assertGreaterEqual(first, second) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
43 | self.assertEqual(first, second) |
||
44 | self.assertLessEqual(first, second) |
||
45 | |||
46 | def assert_ordering(self, greater, lesser): |
||
47 | self.assertGreater(greater, lesser) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
48 | self.assertGreaterEqual(greater, lesser) |
||
49 | self.assertNotEqual(greater, lesser) |
||
50 | self.assertLessEqual(lesser, greater) |
||
51 | self.assertLess(lesser, greater) |
||
52 |