class BackslashDequoteTests(unittest.TestCase): def setUp(self): reset() self.cmd = Kmd() self.cmd.preloop() def test_backslash_dequote(self): self.assertEqual(backslash_dequote(''), '') self.assertEqual(backslash_dequote(' '), ' ') self.assertEqual(backslash_dequote('\\ '), ' ') self.assertEqual(backslash_dequote('a'), 'a') self.assertEqual(backslash_dequote('\\@'), '@') def test_backslash_dequote_string(self): self.assertEqual(backslash_dequote(r'\ foo\ bar\#baz\&'), r' foo bar#baz&') def test_backslash_dequote_backslash(self): self.assertEqual(backslash_dequote(r'foo\\\\\ bar'), r'foo\\ bar') self.assertEqual(backslash_dequote(r'foo\\\\ bar'), r'foo\ bar') self.assertEqual(backslash_dequote(r'foo\\\ bar'), r'foo\ bar') self.assertEqual(backslash_dequote(r'foo\\ bar'), r'foo bar') self.assertEqual(backslash_dequote(r'foo\ bar'), r'foo bar') def test_backslash_dequote_unknown_char(self): self.assertEqual(backslash_dequote('\\€'), '\\€') # NB: not dequoted
class DequoteFilenameTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(dequote_filename) completer.filename_quoting_function = lambda x,y,z: x def test_dequote_filename(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete('Hello'), 'Hello World.txt ') self.assertEqual(self.complete('Hello\\ '), 'Hello World.txt ') self.assertEqual(self.complete("Al\\'"), "Al'Hambra.txt ") self.assertEqual(self.complete('Foo\\\\\\"'), 'Foo\\"Peng\\".txt ') self.assertEqual(self.complete('Tilde.tx\\~'), 'Tilde.tx~ ') self.assertEqual(self.complete('\\~'), '~StartsWithTilde.txt ') def test_dequote_if_single_quote_default(self): completer.quote_characters = "'\"" self.assertEqual(self.complete(''), '') self.assertEqual(self.complete('Hello'), 'Hello World.txt ') self.assertEqual(self.complete('Hello\\ '), 'Hello World.txt ') self.assertEqual(self.complete("Al\\'"), "Al'Hambra.txt ") self.assertEqual(self.complete('Foo\\\\\\"'), 'Foo\\"Peng\\".txt ') self.assertEqual(self.complete('Tilde.tx\\~'), 'Tilde.tx~ ') self.assertEqual(self.complete('\\~'), '~StartsWithTilde.txt ')
class DequoteFilenameTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(backslash_dequote_filename) completer.filename_quoting_function = lambda x,y,z: x def test_dequote_filename(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete(r'Hello'), r'Hello World.txt ') self.assertEqual(self.complete(r'Hello\ '), r'Hello World.txt ') self.assertEqual(self.complete(r"Al\'"), r"Al'Hambra.txt ") self.assertEqual(self.complete(r'Foo\\\"'), r'Foo\"Peng\".txt ') self.assertEqual(self.complete(r'Sys\$'), r'Sys$Home.txt ') self.assertEqual(self.complete(r'Tilde.tx\~'), r'Tilde.tx~ ') self.assertEqual(self.complete(r'\~'), r'~StartsWithTilde.txt ') def test_dequote_if_single_quote_default(self): completer.quote_characters = "'\"" self.assertEqual(self.complete(''), '') self.assertEqual(self.complete(r'Hello'), r'Hello World.txt ') self.assertEqual(self.complete(r'Hello\ '), r'Hello World.txt ') self.assertEqual(self.complete(r"Al\'"), r"Al'Hambra.txt ") self.assertEqual(self.complete(r'Foo\\\"'), r'Foo\"Peng\".txt ') self.assertEqual(self.complete(r'"Sys\$'), r'"Sys$Home.txt" ') self.assertEqual(self.complete(r'Tilde.tx\~'), r'Tilde.tx~ ') self.assertEqual(self.complete(r'\~'), r'~StartsWithTilde.txt ')
def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(backslash_dequote_filename) completer.filename_quoting_function = print_exc(backslash_quote_filename)
class FullyQuotedTests(unittest.TestCase): def setUp(self): reset() self.cmd = Kmd() self.cmd.preloop() def test_fully_quoted(self): self.assertEqual(is_fully_quoted('foo\\ bar\\"baz\\&'), True) self.assertEqual(is_fully_quoted('foo\\ bar\\"baz\\\\'), True) def test_not_fully_quoted(self): self.assertEqual(is_fully_quoted('foo&bar'), False) self.assertEqual(is_fully_quoted('foo\\&bar\\'), False)
class FullyQuotedTests(unittest.TestCase): def setUp(self): reset() self.cmd = Kmd() self.cmd.preloop() def test_fully_quoted(self): self.assertEqual(is_fully_quoted(r'foo\ bar\"baz\&'), True) self.assertEqual(is_fully_quoted(r'foo\ bar\"baz\\'), True) def test_not_fully_quoted(self): self.assertEqual(is_fully_quoted('foo&bar'), False) self.assertEqual(is_fully_quoted('foo\\&bar\\'), False)
def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(dequote_string) completer.filename_quoting_function = lambda x,y,z: x
def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(dequote_filename) completer.filename_quoting_function = print_exc(backslash_quote_filename)
class BackslashQuoteTests(unittest.TestCase): def setUp(self): reset() self.cmd = Kmd() self.cmd.preloop() def test_backslash_quote(self): self.assertEqual(backslash_quote(''), '') self.assertEqual(backslash_quote(' '), '\\ ') self.assertEqual(backslash_quote('a'), 'a') self.assertEqual(backslash_quote('@'), '\\@') def test_backslash_quote_string(self): self.assertEqual(backslash_quote(' foo bar#baz&'), '\\ foo\\ bar\\#baz\\&') def test_backslash_quote_unknown_char(self): self.assertEqual(backslash_quote('€'), '€')
class BackslashQuoteFilenameTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(backslash_dequote_filename) completer.filename_quoting_function = print_exc(backslash_quote_filename) def test_backslash_quote_filename(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete(r'Hello'), r'Hello\ World.txt ') self.assertEqual(self.complete(r'Hello\ '), r'Hello\ World.txt ') self.assertEqual(self.complete(r"Al\'"), r"Al\'Hambra.txt ") self.assertEqual(self.complete(r'Foo\\\"'), r'Foo\\\"Peng\\\".txt ') self.assertEqual(self.complete(r'Sys\$'), r'Sys\$Home.txt ') self.assertEqual(self.complete(r'Tilde.tx\~'), r'Tilde.tx~ ') self.assertEqual(self.complete(r'\~'), r'~StartsWithTilde.txt ') def test_user_quote_filename(self): self.assertEqual(self.complete('"'), '"') self.assertEqual(self.complete('"Hello'), '"Hello World.txt" ') self.assertEqual(self.complete('"Hello '), '"Hello World.txt" ') self.assertEqual(self.complete("\"Al'"), '''"Al'Hambra.txt" ''') self.assertEqual(self.complete(r'"Foo\\\"'), r'"Foo\\\"Peng\\\".txt" ') self.assertEqual(self.complete(r'"Sys\$'), r'"Sys\$Home.txt" ') self.assertEqual(self.complete('"Tilde.tx~'), '"Tilde.tx~" ') self.assertEqual(self.complete('"~'), '"~StartsWithTilde.txt" ') def test_backslash_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('fun'), 'funny\\ dir/') def test_user_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('"fun'), '"funny dir/') # NB: no closing quote on dir
class QuoteStringTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(backslash_dequote_string) completer.filename_quoting_function = print_exc(quote_string) def test_quote_string(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete(r'Hello'), r'"Hello World.txt" ') self.assertEqual(self.complete(r'Hello\ '), r'"Hello World.txt" ') self.assertEqual(self.complete(r"Al\'"), r'''"Al'Hambra.txt" ''') self.assertEqual(self.complete(r'Foo\\\"'), r'Foo\\\"Peng\\\".txt ') self.assertEqual(self.complete(r'Sys\$'), r'Sys\$Home.txt ') self.assertEqual(self.complete(r'Tilde.tx\~'), r'Tilde.tx~ ') self.assertEqual(self.complete(r'\~'), r'~StartsWithTilde.txt ') def test_user_quote_string(self): self.assertEqual(self.complete('"'), '"') self.assertEqual(self.complete('"Hello'), '"Hello World.txt" ') self.assertEqual(self.complete('"Hello '), '"Hello World.txt" ') self.assertEqual(self.complete("\"Al'"), '''"Al'Hambra.txt" ''') self.assertEqual(self.complete(r'"Foo\\\"'), r'"Foo\\\"Peng\\\".txt" ') self.assertEqual(self.complete(r'"Sys\$'), r'"Sys\$Home.txt" ') self.assertEqual(self.complete('"Tilde.tx~'), '"Tilde.tx~" ') self.assertEqual(self.complete('"~'), '"~StartsWithTilde.txt" ') def test_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('fun'), '"funny dir"/') # NB: slash appended by readline def test_user_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('"fun'), '"funny dir"/') # NB: slash appended by readline
class QuoteStringTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(dequote_string) completer.filename_quoting_function = print_exc(quote_string) def test_quote_string(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete('Hello'), '"Hello World.txt" ') self.assertEqual(self.complete('Hello\\ '), '"Hello World.txt" ') self.assertEqual(self.complete("Al\\'"), '''"Al'Hambra.txt" ''') self.assertEqual(self.complete('Foo\\\\\\"'), 'Foo\\\\\\"Peng\\\\\\".txt ') self.assertEqual(self.complete('Tilde.tx\\~'), 'Tilde.tx~ ') self.assertEqual(self.complete('\\~'), '~StartsWithTilde.txt ') def test_user_quote_string(self): self.assertEqual(self.complete('"'), '"') self.assertEqual(self.complete('"Hello'), '"Hello World.txt" ') self.assertEqual(self.complete('"Hello '), '"Hello World.txt" ') self.assertEqual(self.complete("\"Al'"), '''"Al'Hambra.txt" ''') self.assertEqual(self.complete('"Foo\\\\\\"'), '"Foo\\\\\\"Peng\\\\\\".txt" ') self.assertEqual(self.complete('"Tilde.tx\\~'), '"Tilde.tx~" ') self.assertEqual(self.complete('"~'), '"~StartsWithTilde.txt" ') def test_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('fun'), '"funny dir"/') # NB: slash appended by readline def test_user_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('"fun'), '"funny dir"/') # NB: slash appended by readline
class BackslashQuoteFilenameTests(FileSetup): def setUp(self): FileSetup.setUp(self) reset() self.cmd = Kmd() self.cmd.preloop() completer.completer = completefilename completer.filename_dequoting_function = print_exc(dequote_filename) completer.filename_quoting_function = print_exc(backslash_quote_filename) def test_backslash_quote_filename(self): self.assertEqual(self.complete(''), '') self.assertEqual(self.complete('Hello'), 'Hello\\ World.txt ') self.assertEqual(self.complete('Hello\\ '), 'Hello\\ World.txt ') self.assertEqual(self.complete("Al\\'"), "Al\\'Hambra.txt ") self.assertEqual(self.complete('Foo\\\\\\"'), 'Foo\\\\\\"Peng\\\\\\".txt ') self.assertEqual(self.complete('Tilde.tx\\~'), 'Tilde.tx~ ') self.assertEqual(self.complete('\\~'), '~StartsWithTilde.txt ') def test_user_quote_filename(self): self.assertEqual(self.complete('"'), '"') self.assertEqual(self.complete('"Hello'), '"Hello World.txt" ') self.assertEqual(self.complete('"Hello '), '"Hello World.txt" ') self.assertEqual(self.complete("\"Al'"), '''"Al'Hambra.txt" ''') self.assertEqual(self.complete('"Foo\\\\\\"'), '"Foo\\\\\\"Peng\\\\\\".txt" ') self.assertEqual(self.complete('"Tilde.tx\\~'), '"Tilde.tx~" ') self.assertEqual(self.complete('"~'), '"~StartsWithTilde.txt" ') def test_backslash_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('fun'), 'funny\\ dir/') def test_user_quote_directory(self): self.mkdir('funny dir') self.assertEqual(self.complete('"fun'), '"funny dir/') # NB: no closing quote on dir
def preloop(self): Kmd.preloop(self) self.completefilename = FilenameCompletion(self.quote_char)
def __init__(self, quote_char='\\'): Kmd.__init__(self) self.quote_char = quote_char
def preloop(self): Kmd.preloop(self) self.completeenviron = EnvironmentCompletion()
def test_stderr(self): shell = Kmd(stderr='X') self.assertEqual(shell.stderr, 'X')
def preloop(self): Kmd.preloop(self) self.completehostname = HostnameCompletion(self.hostsfile)
def __init__(self, hostsfile=None): Kmd.__init__(self) self.hostsfile = hostsfile
def test_completekey(self): shell = Kmd(completekey='X') self.assertEqual(shell.completekey, 'X')
def setUp(self): reset() self.cmd = Kmd() self.cmd.preloop()
def test_stdin(self): shell = Kmd(stdin='X') self.assertEqual(shell.stdin, 'X')
def test_stdout(self): shell = Kmd(stdout='X') self.assertEqual(shell.stdout, 'X')
def test_all(self): shell = Kmd('X', 'Y', 'Z', 'A') self.assertEqual(shell.completekey, 'X') self.assertEqual(shell.stdin, 'Y') self.assertEqual(shell.stdout, 'Z') self.assertEqual(shell.stderr, 'A')
def preloop(self): Kmd.preloop(self) self.completeuser = UsernameCompletion()