File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed
Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,11 @@ def open_editor(placeholder="") -> str:
3333 with open (temp .name , "w" ) as writer :
3434 writer .write (placeholder )
3535
36- stdout = open (_get_tty_filename (), "wb" )
37- proc = subprocess .Popen (
38- [binpath , temp .name ], close_fds = True , stdout = stdout
39- )
40- proc .communicate ()
36+ with open (_get_tty_filename (), "wb" ) as stdout :
37+ proc = subprocess .Popen (
38+ [binpath , temp .name ], close_fds = True , stdout = stdout
39+ )
40+ proc .communicate ()
4141
4242 with open (temp .name , mode = "r" ) as reader :
4343 return reader .read ()
Original file line number Diff line number Diff line change 1+ import pytest
12import shutil
3+ import subprocess
24
35import git_draft .editor as sut
46
@@ -40,3 +42,30 @@ def which(_editor):
4042 monkeypatch .setenv ("EDITOR" , "" )
4143
4244 assert sut ._guess_editor_binpath () == ""
45+
46+
47+ class TestOpenEditor :
48+ def test_no_binpath (self , monkeypatch ) -> None :
49+ def which (_editor ):
50+ return ""
51+
52+ monkeypatch .setattr (shutil , "which" , which )
53+
54+ with pytest .raises (ValueError ):
55+ sut .open_editor ()
56+
57+ def test_ok (self , monkeypatch ) -> None :
58+ def which (editor ):
59+ return f"/bin/{ editor } "
60+
61+ class Popen :
62+ def __init__ (self , * _args , ** _kwargs ):
63+ pass
64+
65+ def communicate (self ):
66+ pass
67+
68+ monkeypatch .setattr (shutil , "which" , which )
69+ monkeypatch .setattr (subprocess , "Popen" , Popen )
70+
71+ assert sut .open_editor (placeholder = "hello" ) == "hello"
You can’t perform that action at this time.
0 commit comments