Codebase list python-procrunner / 107e74d
add resolution tests Markus Gerstel 5 years ago
2 changed file(s) with 51 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 =======
11 History
22 =======
3
4 0.6.1 (2018-05-02)
5 ------------------
6
7 * Maintenance release to add some tests for executable resolution.
38
49 0.6.0 (2018-05-02)
510 ------------------
0 from __future__ import absolute_import, division, print_function
1
2 import os
3 import sys
4
5 import procrunner
6 import pytest
7
8 @pytest.mark.skipif(sys.platform != 'win32', reason="windows specific test only")
9 def test_name_resolution_for_simple_exe():
10 command = ['cmd.exe', '/c', 'echo', 'hello']
11
12 resolved = procrunner._windows_resolve(command)
13
14 # command should be replaced with full path to cmd.exe
15 assert resolved[0].lower().endswith('\\cmd.exe')
16 assert os.path.exists(resolved[0])
17
18 # parameters are unchanged
19 assert resolved[1:] == command[1:]
20
21 @pytest.mark.skipif(sys.platform != 'win32', reason="windows specific test only")
22 def test_name_resolution_for_complex_cases(tmpdir):
23 tmpdir.chdir()
24
25 bat = 'simple_bat_extension'
26 cmd = 'simple_cmd_extension'
27 exe = 'simple_exe_extension'
28 dotshort = 'more_complex_filename_with_a.dot'
29 dotlong = 'more_complex_filename.withadot'
30
31 (tmpdir / bat + '.bat').ensure()
32 (tmpdir / cmd + '.cmd').ensure()
33 (tmpdir / exe + '.exe').ensure()
34 (tmpdir / dotshort + '.bat').ensure()
35 (tmpdir / dotlong + '.cmd').ensure()
36
37 def is_valid(command):
38 assert len(command) == 1
39 assert os.path.exists(command[0])
40
41 is_valid(procrunner._windows_resolve([bat]))
42 is_valid(procrunner._windows_resolve([cmd]))
43 is_valid(procrunner._windows_resolve([exe]))
44 is_valid(procrunner._windows_resolve([dotshort]))
45 is_valid(procrunner._windows_resolve([dotlong]))