virtual_fs: Make sample_conversation() a list of tuples.

It's nice to see the requests and replies as separate strings
when you're reading the code.
This commit is contained in:
Steve Howell 2018-01-10 12:27:47 -05:00 committed by showell
parent f8d51fc9d1
commit 5be72288db

View file

@ -61,53 +61,53 @@ Use commands like `@mention-bot help write` for more details on specific
commands. commands.
''' '''
def sample_conversation() -> List[str]: def sample_conversation() -> List[Tuple[str, str]]:
return [ return [
('cd /\nCurrent path: /\n\n'), ('cd /', 'Current path: /'),
('cd /home\nERROR: invalid path\n\n'), ('cd /home', 'ERROR: invalid path'),
('cd .\nERROR: invalid path\n\n'), ('cd .', 'ERROR: invalid path'),
('mkdir home\ndirectory created\n\n'), ('mkdir home', 'directory created'),
('cd home\nCurrent path: /home/\n\n'), ('cd home', 'Current path: /home/'),
('cd /home/\nCurrent path: /home/\n\n'), ('cd /home/', 'Current path: /home/'),
('mkdir stuff/\nERROR: stuff/ is not a valid name\n\n'), ('mkdir stuff/', 'ERROR: stuff/ is not a valid name'),
('mkdir stuff\ndirectory created\n\n'), ('mkdir stuff', 'directory created'),
('write stuff/file1 something\nfile written\n\n'), ('write stuff/file1 something', 'file written'),
('read stuff/file1\nsomething\n\n'), ('read stuff/file1', 'something'),
('read /home/stuff/file1\nsomething\n\n'), ('read /home/stuff/file1', 'something'),
('read home/stuff/file1\nERROR: file does not exist\n\n'), ('read home/stuff/file1', 'ERROR: file does not exist'),
('pwd \n/home/\n\n'), ('pwd ', '/home/'),
('pwd bla\nERROR: syntax: pwd\n\n'), ('pwd bla', 'ERROR: syntax: pwd'),
('ls bla foo\nERROR: syntax: ls <optional_path>\n\n'), ('ls bla foo', 'ERROR: syntax: ls <optional_path>'),
('cd /\nCurrent path: /\n\n'), ('cd /', 'Current path: /'),
('rm home\nERROR: /home/ is a directory, file required\n\n'), ('rm home', 'ERROR: /home/ is a directory, file required'),
('rmdir home\nremoved\n\n'), ('rmdir home', 'removed'),
('ls \nWARNING: directory is empty\n\n'), ('ls ', 'WARNING: directory is empty'),
('cd home\nERROR: invalid path\n\n'), ('cd home', 'ERROR: invalid path'),
('read /home/stuff/file1\nERROR: file does not exist\n\n'), ('read /home/stuff/file1', 'ERROR: file does not exist'),
('cd /\nCurrent path: /\n\n'), ('cd /', 'Current path: /'),
('write /foo contents of /foo\nfile written\n\n'), ('write /foo contents of /foo', 'file written'),
('read /foo\ncontents of /foo\n\n'), ('read /foo', 'contents of /foo'),
('write /bar Contents: bar bar\nfile written\n\n'), ('write /bar Contents: bar bar', 'file written'),
('read /bar\nContents: bar bar\n\n'), ('read /bar', 'Contents: bar bar'),
('write /bar invalid\nERROR: file already exists\n\n'), ('write /bar invalid', 'ERROR: file already exists'),
('rm /bar\nremoved\n\n'), ('rm /bar', 'removed'),
('rm /bar\nERROR: file does not exist\n\n'), ('rm /bar', 'ERROR: file does not exist'),
('write /bar new bar\nfile written\n\n'), ('write /bar new bar', 'file written'),
('read /bar\nnew bar\n\n'), ('read /bar', 'new bar'),
('write /yo/invalid whatever\nERROR: /yo is not a directory\n\n'), ('write /yo/invalid whatever', 'ERROR: /yo is not a directory'),
('mkdir /yo\ndirectory created\n\n'), ('mkdir /yo', 'directory created'),
('read /yo\nERROR: /yo/ is a directory, file required\n\n'), ('read /yo', 'ERROR: /yo/ is a directory, file required'),
('ls /yo\nWARNING: directory is empty\n\n'), ('ls /yo', 'WARNING: directory is empty'),
('read /yo/nada\nERROR: file does not exist\n\n'), ('read /yo/nada', 'ERROR: file does not exist'),
('write /yo whatever\nERROR: file already exists\n\n'), ('write /yo whatever', 'ERROR: file already exists'),
('write /yo/apple red\nfile written\n\n'), ('write /yo/apple red', 'file written'),
('read /yo/apple\nred\n\n'), ('read /yo/apple', 'red'),
('mkdir /yo/apple\nERROR: file already exists\n\n'), ('mkdir /yo/apple', 'ERROR: file already exists'),
('ls /invalid\nERROR: file does not exist\n\n'), ('ls /invalid', 'ERROR: file does not exist'),
('ls /foo\nERROR: /foo is not a directory\n\n'), ('ls /foo', 'ERROR: /foo is not a directory'),
('ls /\n* /*bar*\n* /*foo*\n* /yo/\n\n'), ('ls /', '* /*bar*\n* /*foo*\n* /yo/'),
('invalid command\nERROR: unrecognized command\n\n'), ('invalid command', 'ERROR: unrecognized command'),
('write\nERROR: syntax: write <path> <some_text>\n\n'), ('write', 'ERROR: syntax: write <path> <some_text>'),
] ]
REGEXES = dict( REGEXES = dict(
@ -135,7 +135,12 @@ def fs_command(fs: str, user: str, cmd: str) -> Tuple[str, Any]:
if cmd == 'help': if cmd == 'help':
return fs, get_help() return fs, get_help()
if cmd == 'sample_conversation': if cmd == 'sample_conversation':
return fs, (''.join(sample_conversation())) sample = '\n\n'.join(
'\n'.join(tup)
for tup
in sample_conversation()
)
return fs, sample
cmd_name = cmd.split()[0] cmd_name = cmd.split()[0]
cmd_args = cmd[len(cmd_name):].strip() cmd_args = cmd[len(cmd_name):].strip()
commands = get_commands() commands = get_commands()