@@ -76,13 +76,15 @@ def tearDown(self):
76
76
self .remove ()
77
77
super ().tearDown ()
78
78
79
- def verify_install (self , script = manage_script ):
79
+ def verify_install (self , script = None ):
80
80
pass
81
81
82
- def verify_remove (self , script = manage_script ):
82
+ def verify_remove (self , script = None ):
83
83
pass
84
84
85
- def install (self , script = manage_script ):
85
+ def install (self , script = None ):
86
+ if not script :
87
+ script = self .manage_script
86
88
kwargs = {}
87
89
if self .shell :
88
90
kwargs ["shell" ] = self .shell
@@ -91,7 +93,9 @@ def install(self, script=manage_script):
91
93
self .command .install (** kwargs )
92
94
self .verify_install (script = script )
93
95
94
- def remove (self , script = manage_script ):
96
+ def remove (self , script = None ):
97
+ if not script :
98
+ script = self .manage_script
95
99
kwargs = {}
96
100
if self .shell :
97
101
kwargs ["shell" ] = self .shell
@@ -185,20 +189,49 @@ def test_shell_complete(self):
185
189
self .install ()
186
190
187
191
192
+ class _InstalledScriptTestCase (_DefaultCompleteTestCase ):
193
+ """
194
+ These shell completes use an installed script available on the path
195
+ instead of a script directly invoked by path. The difference may
196
+ seem trivial - but it is not given how most shells determine if completion
197
+ logic should be invoked for a given command.
198
+ """
199
+
200
+ MANAGE_SCRIPT_TMPL = Path (__file__ ).parent / "django_manage.py"
201
+ manage_script = "django_manage"
202
+ launch_script = "django_manage"
203
+
204
+ def setUp (self ):
205
+ lines = []
206
+ with open (self .MANAGE_SCRIPT_TMPL , "r" ) as f :
207
+ for line in f .readlines ():
208
+ if line .startswith ("#!{{shebang}}" ):
209
+ line = f"#!{ sys .executable } \n "
210
+ lines .append (line )
211
+ exe = Path (sys .executable ).parent / self .manage_script
212
+ with open (exe , "w" ) as f :
213
+ for line in lines :
214
+ f .write (line )
215
+
216
+ # make the script executable
217
+ os .chmod (exe , os .stat (exe ).st_mode | 0o111 )
218
+ super ().setUp ()
219
+
220
+
188
221
@pytest .mark .skipif (shutil .which ("zsh" ) is None , reason = "Z-Shell not available" )
189
222
class ZshShellTests (_DefaultCompleteTestCase , TestCase ):
190
223
191
224
shell = "zsh"
192
225
directory = Path ("~/.zfunc" ).expanduser ()
193
226
194
- def verify_install (self , script = _DefaultCompleteTestCase . manage_script ):
227
+ def verify_install (self , script = None ):
195
228
if not script :
196
- script = self .command . manage_script_name
229
+ script = self .manage_script
197
230
self .assertTrue ((self .directory / f"_{ script } " ).exists ())
198
231
199
- def verify_remove (self , script = _DefaultCompleteTestCase . manage_script ):
232
+ def verify_remove (self , script = None ):
200
233
if not script :
201
- script = self .command . manage_script_name
234
+ script = self .manage_script
202
235
self .assertFalse ((self .directory / f"_{ script } " ).exists ())
203
236
204
237
@@ -218,17 +251,22 @@ def set_environment(self, fd):
218
251
os .write (fd , f"source ~/.bashrc\n " .encode ())
219
252
os .write (fd , f"source .venv/bin/activate\n " .encode ())
220
253
221
- def verify_install (self , script = _DefaultCompleteTestCase . manage_script ):
254
+ def verify_install (self , script = None ):
222
255
if not script :
223
- script = self .command . manage_script_name
256
+ script = self .manage_script
224
257
self .assertTrue ((self .directory / f"{ script } .sh" ).exists ())
225
258
226
- def verify_remove (self , script = _DefaultCompleteTestCase . manage_script ):
259
+ def verify_remove (self , script = None ):
227
260
if not script :
228
- script = self .command . manage_script_name
261
+ script = self .manage_script
229
262
self .assertFalse ((self .directory / f"{ script } .sh" ).exists ())
230
263
231
264
265
+ @pytest .mark .skipif (shutil .which ("bash" ) is None , reason = "Bash not available" )
266
+ class BashExeShellTests (_InstalledScriptTestCase , TestCase ):
267
+ pass
268
+
269
+
232
270
@pytest .mark .skipif (shutil .which ("pwsh" ) is None , reason = "Powershell not available" )
233
271
class PowerShellTests (_DefaultCompleteTestCase , TestCase ):
234
272
@@ -257,18 +295,18 @@ def test_shell_complete(self):
257
295
self .install ()
258
296
self .remove ()
259
297
260
- def verify_install (self , script = _DefaultCompleteTestCase . manage_script ):
298
+ def verify_install (self , script = None ):
261
299
if not script :
262
- script = self .command . manage_script_name
300
+ script = self .manage_script
263
301
self .assertTrue ((self .directory / f"Microsoft.PowerShell_profile.ps1" ).exists ())
264
302
self .assertTrue (
265
303
f"Register-ArgumentCompleter -Native -CommandName { script } -ScriptBlock $scriptblock"
266
304
in (self .directory / f"Microsoft.PowerShell_profile.ps1" ).read_text ()
267
305
)
268
306
269
- def verify_remove (self , script = _DefaultCompleteTestCase . manage_script ):
307
+ def verify_remove (self , script = None ):
270
308
if not script :
271
- script = self .command . manage_script_name
309
+ script = self .manage_script
272
310
if (self .directory / f"Microsoft.PowerShell_profile.ps1" ).exists ():
273
311
contents = (
274
312
self .directory / f"Microsoft.PowerShell_profile.ps1"
0 commit comments