Skip to content

Commit

Permalink
Teach editor to be monkeypatchable (see #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Jan 6, 2024
1 parent 4592ddb commit 22d2c98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
EDITORS = {'Windows': 'notepad'}


@xmod.xmod
@xmod.xmod(mutable=True)
def editor(
text: t.Optional[str] = None,
filename: t.Union[None, Path, str] = None,
Expand Down
13 changes: 13 additions & 0 deletions test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

FILENAME = 'a_file.txt'
EDITOR = editor.default_editor()
TEST_CONTENT = 'roses are red,\nwater is blue.\n'


@mock.patch('editor.runs.call', autospec=True)
Expand Down Expand Up @@ -46,3 +47,15 @@ def test_temp2(self, call):
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

0 comments on commit 22d2c98

Please sign in to comment.