MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_is_valid_command_invalid

Function test_is_valid_command_invalid

tests/test_parsing.py:915–959  ·  view source on GitHub ↗
(mocker, parser)

Source from the content-addressed store, hash-verified

913
914
915def test_is_valid_command_invalid(mocker, parser) -> None:
916 # Non-string command
917 valid, errmsg = parser.is_valid_command(5)
918 assert not valid
919 assert "must be a string" in errmsg
920
921 mock = mocker.MagicMock()
922 valid, errmsg = parser.is_valid_command(mock)
923 assert not valid
924 assert "must be a string" in errmsg
925
926 # Empty command
927 valid, errmsg = parser.is_valid_command("")
928 assert not valid
929 assert "cannot be an empty string" in errmsg
930
931 # Start with the comment character
932 valid, errmsg = parser.is_valid_command(constants.COMMENT_CHAR)
933 assert not valid
934 assert "cannot start with the comment character" in errmsg
935
936 # Starts with shortcut
937 valid, errmsg = parser.is_valid_command("!ls")
938 assert not valid
939 assert "cannot start with a shortcut" in errmsg
940
941 # Contains whitespace
942 valid, errmsg = parser.is_valid_command("shell ls")
943 assert not valid
944 assert "cannot contain: whitespace, quotes," in errmsg
945
946 # Contains a quote
947 valid, errmsg = parser.is_valid_command('"shell"')
948 assert not valid
949 assert "cannot contain: whitespace, quotes," in errmsg
950
951 # Contains a redirector
952 valid, errmsg = parser.is_valid_command(">shell")
953 assert not valid
954 assert "cannot contain: whitespace, quotes," in errmsg
955
956 # Contains a terminator
957 valid, errmsg = parser.is_valid_command(";shell")
958 assert not valid
959 assert "cannot contain: whitespace, quotes," in errmsg
960
961
962def test_is_valid_command_valid(parser) -> None:

Callers

nothing calls this directly

Calls 1

is_valid_commandMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…