MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_statement_as_dict

Function test_statement_as_dict

tests/test_parsing.py:895–912  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

893
894
895def test_statement_as_dict(parser) -> None:
896 # Make sure to_dict() results can be restored to identical Statement
897 statement = parser.parse("!ls > out.txt")
898 assert statement == Statement.from_dict(statement.to_dict())
899
900 statement = parser.parse("!ls | grep text")
901 assert statement == Statement.from_dict(statement.to_dict())
902
903 statement = parser.parse("multiline arg; suffix")
904 assert statement == Statement.from_dict(statement.to_dict())
905
906 # from_dict() should raise KeyError if required field is missing
907 statement = parser.parse("command")
908 statement_dict = statement.to_dict()
909 del statement_dict["args"]
910
911 with pytest.raises(KeyError):
912 Statement.from_dict(statement_dict)
913
914
915def test_is_valid_command_invalid(mocker, parser) -> None:

Callers

nothing calls this directly

Calls 3

parseMethod · 0.80
from_dictMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…