diff options
Diffstat (limited to 'tests/test_parsing.py')
-rwxr-xr-x | tests/test_parsing.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 9776dace..59b8905b 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -13,6 +13,7 @@ from cmd2 import ( utils, ) from cmd2.parsing import ( + Statement, StatementParser, shlex_split, ) @@ -944,6 +945,26 @@ def test_statement_is_immutable(): statement.raw = 'baz' +def test_statement_as_dict(parser): + # Make sure to_dict() results can be restored to identical Statement + statement = parser.parse("!ls > out.txt") + assert statement == Statement.from_dict(statement.to_dict()) + + statement = parser.parse("!ls | grep text") + assert statement == Statement.from_dict(statement.to_dict()) + + statement = parser.parse("multiline arg; suffix") + assert statement == Statement.from_dict(statement.to_dict()) + + # from_dict() should raise KeyError if required field is missing + statement = parser.parse("command") + statement_dict = statement.to_dict() + del statement_dict[Statement._args_field] + + with pytest.raises(KeyError): + Statement.from_dict(statement_dict) + + def test_is_valid_command_invalid(mocker, parser): # Non-string command # noinspection PyTypeChecker |