Failed Conditions
Pull Request — master (#1099)
by Mischa
02:17
created

coalib.tests.parsing.StringProcessing.UnescapedStripTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %
Metric Value
dl 0
loc 51
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_basic() 0 16 2
A test_no_whitespaced_strings() 0 6 2
A test_rstrip() 0 16 2
1
import sys
2
import unittest
3
4
sys.path.insert(0, ".")
5
from coalib.tests.parsing.StringProcessing.StringProcessingTestBase import (
6
    StringProcessingTestBase)
7
from coalib.parsing.StringProcessing import unescaped_rstrip, unescaped_strip
8
9
10
class UnescapedStripTest(StringProcessingTestBase):
11
    test_strings2 = ("hello\\",
12
                     "te\\st\\\\",
13
                     "A\\ ",
14
                     "A\\       ",
15
                     "   A \\ \\  ",
16
                     "    \\ A \\    ",
17
                     "  \\\\ A",
18
                     " \\\\\\\\\\  ",
19
                     " \\\\\\\\  ")
20
21
    def test_rstrip(self):
22
        expected_results = ("hello\\",
23
                            "te\\st\\\\",
24
                            "A\\ ",
25
                            "A\\ ",
26
                            "   A \\ \\ ",
27
                            "    \\ A \\ ",
28
                            "  \\\\ A",
29
                            " \\\\\\\\\\ ",
30
                            " \\\\\\\\")
31
32
        self.assertResultsEqual(
33
            unescaped_rstrip,
34
            {(test_string,): result
35
             for test_string, result in zip(self.test_strings2,
36
                                            expected_results)})
37
38
    def test_basic(self):
39
        expected_results = ("hello\\",
40
                            "te\\st\\\\",
41
                            "A\\ ",
42
                            "A\\ ",
43
                            "A \\ \\ ",
44
                            "\\ A \\ ",
45
                            "\\\\ A",
46
                            "\\\\\\\\\\ ",
47
                            "\\\\\\\\")
48
49
        self.assertResultsEqual(
50
            unescaped_strip,
51
            {(test_string,): result
52
             for test_string, result in zip(self.test_strings2,
53
                                            expected_results)})
54
55
    def test_no_whitespaced_strings(self):
56
        # When no leading or trailing whitespaces exist, nothing should happen.
57
        self.assertResultsEqual(
58
            unescaped_strip,
59
            {(test_string,): test_string
60
             for test_string in self.test_strings})
61
62
63
if __name__ == '__main__':
64
    unittest.main(verbosity=2)
65