Failed Conditions
Pull Request — master (#1511)
by Abdeali
01:34
created

coalib.tests.coalaDeleteOrigTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %
Metric Value
dl 0
loc 28
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_nonexistent_coafile() 0 8 3
A test_remove_exception() 0 13 3
A setUp() 0 3 1
1
import os
2
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
3
import sys
0 ignored issues
show
Unused Code introduced by
The import sys seems to be unused.
Loading history...
4
import unittest
5
6
from coalib import coala_delete_orig
7
from coalib.misc.ContextManagers import retrieve_stdout
8
from coalib.parsing import Globbing
9
from coalib.settings.Section import Section
10
from coalib.settings.Setting import Setting
11
12
13
def raise_assertion_error(*args, **kwargs):
14
    raise AssertionError
15
16
17
class coalaDeleteOrigTest(unittest.TestCase):
18
19
    def setUp(self):
20
        self.section = Section("default")
21
        self.section.append(Setting("config", '/path/to/file'))
22
23
    def test_nonexistent_coafile(self):
24
        old_getcwd = os.getcwd
25
        os.getcwd = lambda *args: None
26
        with retrieve_stdout() as stdout:
27
            retval = coala_delete_orig.main()
28
            self.assertIn("Can only delete .orig files if ", stdout.getvalue())
29
            self.assertEqual(retval, 255)
30
        os.getcwd = old_getcwd
31
32
    def test_remove_exception(self):
33
        old_remove = os.remove
34
        old_glob = Globbing.glob
35
        Globbing.glob = lambda *args: ["file1", "file2"]
36
        os.remove = raise_assertion_error
37
        with retrieve_stdout() as stdout:
38
            retval = coala_delete_orig.main(section=self.section)
39
            output = stdout.getvalue()
40
            self.assertEqual(retval, 0)
41
            self.assertIn("Couldn't delete... file1", output)
42
            self.assertIn("Couldn't delete... file2", output)
43
        os.remove = old_remove
44
        Globbing.glob = old_glob
45