forked from coala/coala
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcoalaDeleteOrigTest.py
51 lines (43 loc) · 1.86 KB
/
coalaDeleteOrigTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import tempfile
import unittest
import os
import re
from coalib import coala_delete_orig
from coalib.misc.ContextManagers import retrieve_stderr
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
class coalaDeleteOrigTest(unittest.TestCase):
def setUp(self):
self.section = Section("default")
self.section.append(Setting("config", '/path/to/file'))
@unittest.mock.patch('os.getcwd')
def test_nonexistent_coafile(self, mocked_getcwd):
mocked_getcwd.return_value = None
retval = coala_delete_orig.main()
self.assertEqual(retval, 255)
@unittest.mock.patch('coalib.parsing.Globbing.glob')
def test_remove_exception(self, mock_glob):
# Non existent file
mock_glob.return_value = ["non_existent_file"]
with retrieve_stderr() as stderr:
retval = coala_delete_orig.main(section=self.section)
output = stderr.getvalue()
self.assertEqual(retval, 0)
self.assertIn("Couldn't delete", output)
# Directory instead of file
with tempfile.TemporaryDirectory() as filename, \
retrieve_stderr() as stderr:
mock_glob.return_value = [filename]
retval = coala_delete_orig.main(section=self.section)
output = stderr.getvalue()
self.assertEqual(retval, 0)
self.assertIn("Couldn't delete", output)
def test_normal_running(self):
with tempfile.TemporaryDirectory() as directory:
temporary = tempfile.mkstemp(suffix=".orig", dir=directory)
os.close(temporary[0])
section = Section("")
section.append(Setting("project_dir", re.escape(directory)))
retval = coala_delete_orig.main(section=section)
self.assertEqual(retval, 0)
self.assertFalse(os.path.isfile(temporary[1]))