Files
pipenv/tests/test_cmdparse.py
T
Tzu-ping Chung 15c7308ca9 Proper script argument escaping
I chose to make Script.parse to always operate in POSIX mode so it is much
easier to write commands compatible on all platforms.

Script.cmdify is the important part on Windows. It ensures the argument
line is always escaped and joined properly on Windows, not just for the
subset that works both under POSIX and Windows (as is the case of
shlex.escape).
2018-04-06 23:22:30 -04:00

28 lines
797 B
Python

import textwrap
from pipenv.cmdparse import Script
def test_parse():
script = Script.parse(['python', '-c', "print('hello')"])
assert script.command == 'python'
assert script.args == ['-c', "print('hello')"], script
def test_cmdify():
script = Script.parse(['python', '-c', "print('hello')"])
cmd = script.cmdify(['--verbose'])
assert cmd == '"python" "-c" "print(\'hello\')" "--verbose"', script
def test_cmdify_complex():
script = Script.parse(' '.join([
'"C:\\Program Files\\Python36\\python.exe" -c',
""" "print(\'Double quote: \\\"\')" """.strip(),
]))
assert script.cmdify([]) == ' '.join([
'"C:\\Program Files\\Python36\\python.exe"',
'"-c"',
""" "print(\'Double quote: \\\"\')" """.strip(),
]), script