1010
1111import pytest
1212from pkgcore .ebuild .atom import atom as atom_cls
13- from snakeoil .contexts import os_environ
1413
1514from pkgdev .scripts import run
1615
@@ -122,9 +121,10 @@ def profile(self):
122121 def test_empty_repo (self ):
123122 assert self .profile .masks == frozenset ()
124123
125- def test_nonexistent_editor (self , capsys ):
124+ def test_nonexistent_editor (self , capsys , monkeypatch ):
125+ monkeypatch .delenv ("VISUAL" , raising = False )
126+ monkeypatch .setenv ("EDITOR" , "12345" )
126127 with (
127- os_environ ("VISUAL" , EDITOR = "12345" ),
128128 patch ("sys.argv" , self .args + ["cat/pkg" ]),
129129 pytest .raises (SystemExit ),
130130 chdir (pjoin (self .repo .path )),
@@ -133,9 +133,10 @@ def test_nonexistent_editor(self, capsys):
133133 _out , err = capsys .readouterr ()
134134 assert err .strip () == "pkgdev mask: error: nonexistent editor: '12345'"
135135
136- def test_nonexistent_visual (self , capsys ):
136+ def test_nonexistent_visual (self , capsys , monkeypatch ):
137+ monkeypatch .delenv ("EDITOR" , raising = False )
138+ monkeypatch .setenv ("VISUAL" , "12345" )
137139 with (
138- os_environ ("EDITOR" , VISUAL = "12345" ),
139140 patch ("sys.argv" , self .args + ["cat/pkg" ]),
140141 pytest .raises (SystemExit ),
141142 chdir (pjoin (self .repo .path )),
@@ -144,9 +145,10 @@ def test_nonexistent_visual(self, capsys):
144145 _out , err = capsys .readouterr ()
145146 assert err .strip () == "pkgdev mask: error: nonexistent editor: '12345'"
146147
147- def test_failed_editor (self , capsys ):
148+ def test_failed_editor (self , capsys , monkeypatch ):
149+ monkeypatch .delenv ("VISUAL" , raising = False )
150+ monkeypatch .setenv ("EDITOR" , "sed -i 's///'" )
148151 with (
149- os_environ ("VISUAL" , EDITOR = "sed -i 's///'" ),
150152 patch ("sys.argv" , self .args + ["cat/pkg" ]),
151153 pytest .raises (SystemExit ),
152154 chdir (pjoin (self .repo .path )),
@@ -155,9 +157,10 @@ def test_failed_editor(self, capsys):
155157 _out , err = capsys .readouterr ()
156158 assert err .strip () == "pkgdev mask: error: failed writing mask comment"
157159
158- def test_empty_mask_comment (self , capsys ):
160+ def test_empty_mask_comment (self , capsys , monkeypatch ):
161+ monkeypatch .delenv ("VISUAL" , raising = False )
162+ monkeypatch .setenv ("EDITOR" , "sed -i 's/#/#/'" )
159163 with (
160- os_environ ("VISUAL" , EDITOR = "sed -i 's/#/#/'" ),
161164 patch ("sys.argv" , self .args + ["cat/pkg" ]),
162165 pytest .raises (SystemExit ),
163166 chdir (pjoin (self .repo .path )),
@@ -166,37 +169,40 @@ def test_empty_mask_comment(self, capsys):
166169 _out , err = capsys .readouterr ()
167170 assert err .strip () == "pkgdev mask: error: empty mask comment"
168171
169- def test_mask_cwd (self ):
172+ def test_mask_cwd (self , monkeypatch ):
173+ monkeypatch .delenv ("VISUAL" , raising = False )
174+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
170175 with (
171- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
172176 patch ("sys.argv" , self .args ),
173177 pytest .raises (SystemExit ),
174178 chdir (pjoin (self .repo .path , "cat/pkg" )),
175179 ):
176180 self .script ()
177181 assert self .profile .masks == frozenset ([atom_cls ("cat/pkg" )])
178182
179- def test_mask_target (self ):
183+ def test_mask_target (self , monkeypatch ):
184+ monkeypatch .delenv ("VISUAL" , raising = False )
185+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
180186 with (
181- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
182187 patch ("sys.argv" , self .args + ["cat/pkg" ]),
183188 pytest .raises (SystemExit ),
184189 chdir (pjoin (self .repo .path )),
185190 ):
186191 self .script ()
187192 assert self .profile .masks == frozenset ([atom_cls ("cat/pkg" )])
188193
189- def test_mask_ebuild_path (self ):
194+ def test_mask_ebuild_path (self , monkeypatch ):
195+ monkeypatch .delenv ("VISUAL" , raising = False )
196+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
190197 with (
191- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
192198 patch ("sys.argv" , self .args + ["cat/pkg/pkg-0.ebuild" ]),
193199 pytest .raises (SystemExit ),
194200 chdir (pjoin (self .repo .path )),
195201 ):
196202 self .script ()
197203 assert self .profile .masks == frozenset ([atom_cls ("=cat/pkg-0" )])
198204
199- def test_existing_masks (self ):
205+ def test_existing_masks (self , monkeypatch ):
200206 self .masks_path .write_text (
201207 textwrap .dedent (
202208 """\
@@ -207,16 +213,17 @@ def test_existing_masks(self):
207213 )
208214 )
209215
216+ monkeypatch .delenv ("VISUAL" , raising = False )
217+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
210218 with (
211- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
212219 patch ("sys.argv" , self .args + ["=cat/pkg-0" ]),
213220 pytest .raises (SystemExit ),
214221 chdir (pjoin (self .repo .path )),
215222 ):
216223 self .script ()
217224 assert self .profile .masks == frozenset ([atom_cls ("cat/masked" ), atom_cls ("=cat/pkg-0" )])
218225
219- def test_invalid_header (self , capsys ):
226+ def test_invalid_header (self , capsys , monkeypatch ):
220227 self .masks_path .write_text (
221228 textwrap .dedent (
222229 """\
@@ -235,8 +242,9 @@ def test_invalid_header(self, capsys):
235242 )
236243 )
237244
245+ monkeypatch .delenv ("VISUAL" , raising = False )
246+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
238247 with (
239- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
240248 patch ("sys.argv" , self .args + ["=cat/pkg-0" ]),
241249 pytest .raises (SystemExit ),
242250 chdir (pjoin (self .repo .path )),
@@ -245,7 +253,9 @@ def test_invalid_header(self, capsys):
245253 _ , err = capsys .readouterr ()
246254 assert "invalid mask entry header, lineno 9" in err
247255
248- def test_invalid_author (self , capsys ):
256+ def test_invalid_author (self , capsys , monkeypatch ):
257+ monkeypatch .delenv ("VISUAL" , raising = False )
258+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
249259 for line in (
250260 "# Random Dev <random.dev@email.com>" ,
251261 "# Random Dev <random.dev@email.com) (2021-03-24)" ,
@@ -268,7 +278,6 @@ def test_invalid_author(self, capsys):
268278 )
269279
270280 with (
271- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
272281 patch ("sys.argv" , self .args + ["=cat/pkg-0" ]),
273282 pytest .raises (SystemExit ),
274283 chdir (pjoin (self .repo .path )),
@@ -277,11 +286,12 @@ def test_invalid_author(self, capsys):
277286 _ , err = capsys .readouterr ()
278287 assert "pkgdev mask: error: invalid author, lineno 5" in err
279288
280- def test_last_rites (self ):
289+ def test_last_rites (self , monkeypatch ):
290+ monkeypatch .delenv ("VISUAL" , raising = False )
291+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
281292 for rflag in ("-r" , "--rites" ):
282293 for args in ([rflag ], [rflag , "14" ]):
283294 with (
284- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
285295 patch ("sys.argv" , self .args + ["cat/pkg" ] + args ),
286296 pytest .raises (SystemExit ),
287297 chdir (pjoin (self .repo .path )),
@@ -303,13 +313,13 @@ def test_last_rites(self):
303313 self .masks_path .write_text ("" ) # Reset the contents of package.mask
304314
305315 @pytest .mark .skipif (sys .platform == "darwin" , reason = "no xdg-email on mac os" )
306- def test_last_rites_with_email (self , tmp_path ):
316+ def test_last_rites_with_email (self , tmp_path , monkeypatch ):
307317 output_file = tmp_path / "mail.txt"
318+ monkeypatch .delenv ("VISUAL" , raising = False )
319+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
320+ monkeypatch .setenv ("MAILER" , f"> { output_file } echo" )
308321 for rflag in ("-r" , "--rites" ):
309322 with (
310- os_environ (
311- "VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" , MAILER = f"> { output_file } echo"
312- ),
313323 patch ("sys.argv" , self .args + ["cat/pkg" , rflag , "--email" ]),
314324 pytest .raises (SystemExit ),
315325 chdir (pjoin (self .repo .path )),
@@ -321,10 +331,12 @@ def test_last_rites_with_email(self, tmp_path):
321331 self .masks_path .write_text ("" ) # Reset the contents of package.mask
322332
323333 @pytest .mark .skipif (sys .platform == "darwin" , reason = "no xdg-email on mac os" )
324- def test_last_email_bad_mailer (self , capsys ):
334+ def test_last_email_bad_mailer (self , capsys , monkeypatch ):
335+ monkeypatch .delenv ("VISUAL" , raising = False )
336+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
337+ monkeypatch .setenv ("MAILER" , "false" )
325338 for rflag in ("-r" , "--rites" ):
326339 with (
327- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" , MAILER = "false" ),
328340 patch ("sys.argv" , self .args + ["cat/pkg" , rflag , "--email" ]),
329341 pytest .raises (SystemExit ),
330342 chdir (pjoin (self .repo .path )),
@@ -333,8 +345,10 @@ def test_last_email_bad_mailer(self, capsys):
333345 _ , err = capsys .readouterr ()
334346 assert err .strip () == "pkgdev mask: error: failed opening email composer"
335347
336- def test_mask_bugs (self ):
348+ def test_mask_bugs (self , monkeypatch ):
337349 today = self .today .strftime ("%Y-%m-%d" )
350+ monkeypatch .delenv ("VISUAL" , raising = False )
351+ monkeypatch .setenv ("EDITOR" , "sed -i '1s/$/mask comment/'" )
338352 for bflag in ("-b" , "--bug" ):
339353 for bug_nums , expected in [
340354 (["42" ], "Bug #42." ),
@@ -345,7 +359,6 @@ def test_mask_bugs(self):
345359 for bug_num in bug_nums :
346360 args += [bflag , bug_num ]
347361 with (
348- os_environ ("VISUAL" , EDITOR = "sed -i '1s/$/mask comment/'" ),
349362 patch ("sys.argv" , self .args + ["cat/pkg" ] + args ),
350363 pytest .raises (SystemExit ),
351364 chdir (pjoin (self .repo .path )),
0 commit comments