-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_editor.py
61 lines (44 loc) · 1.5 KB
/
test_editor.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
52
53
54
55
56
57
58
59
60
61
import unittest
from pathlib import Path
from unittest import mock
import tdir
import editor
FILENAME = 'a_file.txt'
EDITOR = editor.default_editor()
TEST_CONTENT = 'roses are red,\nwater is blue.\n'
@mock.patch('editor.runs.call', autospec=True)
class TestEditor(unittest.TestCase):
@tdir(FILENAME)
def test_existing(self, call):
actual = editor(filename=FILENAME)
expected = FILENAME + '\n'
assert actual == expected
filename = Path(FILENAME).resolve()
call.assert_called_once_with('{} "{}"'.format(EDITOR, filename))
actual = editor('X', filename=filename)
expected = 'X'
assert actual == expected
@tdir
def test_new(self, call):
actual = editor('X', filename=FILENAME, shell=True)
expected = 'X'
assert actual == expected
filename = Path(FILENAME).resolve()
expected = '{} "{}"'.format(EDITOR, filename)
call.assert_called_once_with(expected, shell=True)
def test_temp(self, call):
actual = editor()
expected = ''
assert actual == expected
call.assert_called_once()
def test_temp2(self, call):
actual = editor('some contents')
expected = 'some contents'
assert actual == expected
call.assert_called_once()
def main():
print(editor.editor())
def test_main(monkeypatch, capsys):
monkeypatch.setattr('editor.editor', lambda: TEST_CONTENT)
main()
assert TEST_CONTENT + '\n' == capsys.readouterr().out