def __init__(self, *args, **kwargs): super(BaseShell, self).__init__(*args, **kwargs) # characters preceding the cursor when prompting for command entry self.prompt = '> ' # text to be displayed upon launch of the shell, before displaying # the interactive prompt self.banner_text = None # Flag indicating whether this shell should be closed after the current # command finishes processing self._done = False # Command parser API for parsing tokens from command lines self._parser = default_line_parser() # input redirection to use instead of the default stdin self._input_stream = None # parent Friendly Shell this shell runs under # only used for nested sub-shells self._parent = None # default comment delimiter self.comment_delimiter = "#" # error code / return value produced by this shell self._return_code = 0
def test_no_params(): parser = default_line_parser() res = parser.parseString('MyCommand') assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 0
def test_params_with_nested_double_quotes(): parser = default_line_parser() res = parser.parseString("MyCommand 'param with \"double quotes\"'") assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 1 assert res.params[0] == '\'param with "double quotes"\''
def test_params_with_nested_quotes(): parser = default_line_parser() res = parser.parseString('MyCommand "param with \'quotes\'"') assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 1 assert res.params[0] == "\"param with 'quotes'\""
def test_params_with_spaces(): parser = default_line_parser() res = parser.parseString("MyCommand 'param with spaces'") assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 1 assert res.params[0] == "'param with spaces'"
def test_single_quoted_param(): parser = default_line_parser() res = parser.parseString("MyCommand 'param1'") assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 1 assert res.params[0] == "'param1'"
def test_quoted_param(): parser = default_line_parser() res = parser.parseString('MyCommand "param1"') assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 1 assert res.params[0] == '"param1"'
def test_incomplete_single_quotes(): parser = default_line_parser() res = parser.parseString("MyCommand first_param '") assert res is not None assert res.command == "MyCommand" assert len(res.params) == 2 assert res.params[0] == "first_param" assert res.params[1] == "'"
def test_partial_completion_double_quotes(): parser = default_line_parser() res = parser.parseString("MyCommand first_param \"partial") assert res is not None assert res.command == "MyCommand" assert len(res.params) == 2 assert res.params[0] == "first_param" assert res.params[1] == "\"partial"
def test_params_whitespace(): parser = default_line_parser() res = parser.parseString(' MyCommand param1 param2') assert res is not None assert res.command == 'MyCommand' assert len(res.params) == 2 assert res.params[0] == 'param1' assert res.params[1] == 'param2'
def test_nested_quoted_param(): parser = default_line_parser() res = parser.parseString( "MyCommand first_param \"second param\" third_param") assert res is not None assert res.command == "MyCommand" assert len(res.params) == 3 assert res.params[0] == "first_param" assert res.params[1] == "\"second param\"" assert res.params[2] == "third_param"
def test_mixed_param_quotes(): parser = default_line_parser() res = parser.parseString( "MyCommand first_param \"second param\" 'third param' fourth_param") assert res is not None assert res.command == "MyCommand" assert len(res.params) == 4 assert res.params[0] == "first_param" assert res.params[1] == "\"second param\"" assert res.params[2] == "'third param'" assert res.params[3] == "fourth_param"