Rework cmdparse.Script API

The API now requires a command argument from signature. Parsing errors
(no command from input) is thrown as a custom exception, and caught by
the outmost possible invocation to emit a message from click.
This commit is contained in:
Tzu-ping Chung
2018-04-06 17:34:14 +08:00
committed by Dan Ryan
parent d1eeeced45
commit 483bf175cf
4 changed files with 38 additions and 29 deletions
+12 -5
View File
@@ -1,8 +1,7 @@
import textwrap
from pipenv.cmdparse import Script
import pytest
from pipenv.cmdparse import Script, ScriptEmptyError
@pytest.mark.run
@pytest.mark.script
@@ -12,9 +11,17 @@ def test_parse():
assert script.args == ['-c', "print('hello')"], script
@pytest.mark.run
@pytest.mark.script
def test_parse_error():
with pytest.raises(ScriptEmptyError) as e:
Script.parse('')
assert str(e.value) == "[]"
@pytest.mark.run
def test_extend():
script = Script.parse(['python', '-c', "print('hello')"])
script = Script('python', ['-c', "print('hello')"])
script.extend(['--verbose'])
assert script.command == 'python'
assert script.args == ['-c', "print('hello')", "--verbose"], script
@@ -23,7 +30,7 @@ def test_extend():
@pytest.mark.run
@pytest.mark.script
def test_cmdify():
script = Script.parse(['python', '-c', "print('hello')"])
script = Script('python', ['-c', "print('hello')"])
cmd = script.cmdify()
assert cmd == '"python" "-c" "print(\'hello\')"', script