1 | import tempfile |
||
2 | import unittest |
||
3 | |||
4 | from coalib import coala_delete_orig |
||
5 | from coalib.misc.ContextManagers import retrieve_stdout |
||
6 | from coalib.settings.Section import Section |
||
7 | from coalib.settings.Setting import Setting |
||
8 | |||
9 | |||
10 | class coalaDeleteOrigTest(unittest.TestCase): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
11 | |||
12 | def setUp(self): |
||
13 | self.section = Section("default") |
||
14 | self.section.append(Setting("config", '/path/to/file')) |
||
15 | |||
16 | @unittest.mock.patch('os.getcwd') |
||
17 | def test_nonexistent_coafile(self, mocked_getcwd): |
||
18 | mocked_getcwd.return_value = None |
||
19 | retval = coala_delete_orig.main() |
||
20 | self.assertEqual(retval, 255) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
21 | |||
22 | @unittest.mock.patch('coalib.parsing.Globbing.glob') |
||
23 | def test_remove_exception(self, mock_glob): |
||
24 | # Non existent file |
||
25 | mock_glob.return_value = ["non_existent_file"] |
||
26 | with retrieve_stdout() as stdout: |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
27 | retval = coala_delete_orig.main(section=self.section) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
28 | output = stdout.getvalue() |
||
29 | self.assertEqual(retval, 0) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
30 | self.assertIn("Couldn't delete", output) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
31 | |||
32 | # Directory instead of file |
||
33 | with tempfile.TemporaryDirectory() as filename, \ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
34 | retrieve_stdout() as stdout: |
||
35 | mock_glob.return_value = [filename] |
||
36 | retval = coala_delete_orig.main(section=self.section) |
||
37 | output = stdout.getvalue() |
||
38 | self.assertEqual(retval, 0) |
||
39 | self.assertIn("Couldn't delete", output) |
||
40 |