Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:11
created

tests/results/SourcePositionTest.py (10 issues)

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
The variable unittest does not seem to be defined.
Loading history...
9
10
    def test_initialization(self):
11
        with self.assertRaises(TypeError):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable TypeError does not seem to be defined.
Loading history...
12
            SourcePosition(None, 0)
13
14
        with self.assertRaises(ValueError):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ValueError does not seem to be defined.
Loading history...
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
The variable uut does not seem to be defined.
Loading history...
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
The variable filename does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable _ does not seem to be defined.
Loading history...
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
The variable first does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable second does not seem to be defined.
Loading history...
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
The variable greater does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable lesser does not seem to be defined.
Loading history...
48
        self.assertGreaterEqual(greater, lesser)
49
        self.assertNotEqual(greater, lesser)
50
        self.assertLessEqual(lesser, greater)
51
        self.assertLess(lesser, greater)
52