Code Duplication    Length = 37-39 lines in 2 locations

tests/bearlib/abstractions/LinterTest.py 2 locations

@@ 81-119 (lines=39) @@
78
        self.assertEqual(str(cm.exception),
79
                         "Invalid keyword arguments provided: 'output_regex'")
80
81
        with self.assertRaises(ValueError) as cm:
82
            linter("some-executable",
83
                   output_format="corrected",
84
                   severity_map={})
85
        self.assertEqual(str(cm.exception),
86
                         "Invalid keyword arguments provided: 'severity_map'")
87
88
        with self.assertRaises(ValueError) as cm:
89
            linter("some-executable",
90
                   prerequisite_check_fail_message="some_message")
91
        self.assertEqual(str(cm.exception),
92
                         "Invalid keyword arguments provided: "
93
                         "'prerequisite_check_fail_message'")
94
95
    def test_decorator_invalid_states(self):
96
        with self.assertRaises(ValueError) as cm:
97
            linter("some-executable", use_stdout=False, use_stderr=False)
98
        self.assertEqual(str(cm.exception),
99
                         "No output streams provided at all.")
100
101
        with self.assertRaises(ValueError) as cm:
102
            linter("some-executable", output_format="INVALID")
103
        self.assertEqual(str(cm.exception),
104
                         "Invalid `output_format` specified.")
105
106
        with self.assertRaises(ValueError) as cm:
107
            linter("some-executable", output_format="regex")
108
        self.assertEqual(
109
            str(cm.exception),
110
            "`output_regex` needed when specified output-format 'regex'.")
111
112
        with self.assertRaises(ValueError) as cm:
113
            linter("some-executable",
114
                   output_format="regex",
115
                   output_regex="",
116
                   severity_map={})
117
        self.assertEqual(
118
            str(cm.exception),
119
            "Provided `severity_map` but named group `severity` is not used "
120
            "in `output_regex`.")
121
122
        with self.assertRaises(ValueError) as cm:
@@ 42-78 (lines=37) @@
39
            return tuple()
40
41
        def get_config_dir(self):
42
            return '/'
43
44
        def process_output(self, output, *args, **kwargs):
45
            assert output == '/\n', ("The linter doesn't run the command in "
46
                                     "the right directory!")
47
48
    class ManualProcessingTestLinter:
49
50
        def process_output(self, *args, **kwargs):
51
            pass
52
53
    def setUp(self):
54
        self.section = Section("TEST_SECTION")
55
56
    def test_decorator_invalid_parameters(self):
57
        with self.assertRaises(ValueError) as cm:
58
            linter("some-executable", invalid_arg=88, ABC=2000)
59
        self.assertEqual(
60
            str(cm.exception),
61
            "Invalid keyword arguments provided: 'ABC', 'invalid_arg'")
62
63
        with self.assertRaises(ValueError) as cm:
64
            linter("some-executable", diff_severity=RESULT_SEVERITY.MAJOR)
65
        self.assertEqual(str(cm.exception),
66
                         "Invalid keyword arguments provided: 'diff_severity'")
67
68
        with self.assertRaises(ValueError) as cm:
69
            linter("some-executable", result_message="Custom message")
70
        self.assertEqual(str(cm.exception),
71
                         "Invalid keyword arguments provided: "
72
                         "'result_message'")
73
74
        with self.assertRaises(ValueError) as cm:
75
            linter("some-executable",
76
                   output_format="corrected",
77
                   output_regex=".*")
78
        self.assertEqual(str(cm.exception),
79
                         "Invalid keyword arguments provided: 'output_regex'")
80
81
        with self.assertRaises(ValueError) as cm: