1 | import os |
||
2 | import re |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
3 | import sys |
||
0 ignored issues
–
show
|
|||
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 |