mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
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:
+12
-5
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user