Failed Conditions
Pull Request — master (#1099)
by Mischa
01:56
created

coalib.tests.parsing.StringProcessing.UnescapedStripTest   A

Complexity

Total Complexity 6

Size/Duplication

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_rstrip() 0 16 2
A test_strip() 0 16 2
A test_no_whitespaced_strings() 0 7 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
                     r"A\ ",
14
                     r"A\       ",
15
                     r"   A \ \  ",
16
                     r"    \ A \    ",
17
                     r"  \\ A",
18
                     r" \\\\\  ",
19
                     r" \\\\  ")
20
21
    def test_rstrip(self):
22
        expected_results = ("hello\\",
23
                            "te\\st\\\\",
24
                            r"A\ ",
25
                            r"A\ ",
26
                            r"   A \ \ ",
27
                            r"    \ A \ ",
28
                            r"  \\ A",
29
                            r" \\\\\ ",
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_strip(self):
39
        expected_results = ("hello\\",
40
                            "te\\st\\\\",
41
                            r"A\ ",
42
                            r"A\ ",
43
                            r"A \ \ ",
44
                            r"\ A \ ",
45
                            r"\\ A",
46
                            r"\\\\\ ",
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
        # By the way: self.test_strings comes from the base class.
58
        self.assertResultsEqual(
59
            unescaped_strip,
60
            {(test_string,): test_string
61
             for test_string in self.test_strings})
62
63
64
if __name__ == '__main__':
65
    unittest.main(verbosity=2)
66