Example #1
0
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
Example #2
0
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 ')
Example #3
0
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 ')
Example #4
0
 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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
 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
Example #8
0
 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)
Example #9
0
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('€'), '€')
Example #10
0
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
Example #11
0
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
Example #12
0
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
Example #13
0
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
Example #14
0
 def preloop(self):
     Kmd.preloop(self)
     self.completefilename = FilenameCompletion(self.quote_char)
Example #15
0
 def __init__(self, quote_char='\\'):
     Kmd.__init__(self)
     self.quote_char = quote_char
Example #16
0
 def preloop(self):
     Kmd.preloop(self)
     self.completeenviron = EnvironmentCompletion()
Example #17
0
 def preloop(self):
     Kmd.preloop(self)
     self.completefilename = FilenameCompletion(self.quote_char)
Example #18
0
 def __init__(self, quote_char='\\'):
     Kmd.__init__(self)
     self.quote_char = quote_char
Example #19
0
 def test_stderr(self):
     shell = Kmd(stderr='X')
     self.assertEqual(shell.stderr, 'X')
Example #20
0
 def preloop(self):
     Kmd.preloop(self)
     self.completehostname = HostnameCompletion(self.hostsfile)
Example #21
0
 def __init__(self, hostsfile=None):
     Kmd.__init__(self)
     self.hostsfile = hostsfile
Example #22
0
 def test_completekey(self):
     shell = Kmd(completekey='X')
     self.assertEqual(shell.completekey, 'X')
Example #23
0
 def setUp(self):
     reset()
     self.cmd = Kmd()
     self.cmd.preloop()
Example #24
0
 def test_stdin(self):
     shell = Kmd(stdin='X')
     self.assertEqual(shell.stdin, 'X')
Example #25
0
 def __init__(self, hostsfile=None):
     Kmd.__init__(self)
     self.hostsfile = hostsfile
Example #26
0
 def test_stdout(self):
     shell = Kmd(stdout='X')
     self.assertEqual(shell.stdout, 'X')
Example #27
0
 def preloop(self):
     Kmd.preloop(self)
     self.completehostname = HostnameCompletion(self.hostsfile)
Example #28
0
 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')
Example #29
0
 def preloop(self):
     Kmd.preloop(self)
     self.completeuser = UsernameCompletion()
Example #30
0
 def preloop(self):
     Kmd.preloop(self)
     self.completeenviron = EnvironmentCompletion()
Example #31
0
 def setUp(self):
     reset()
     self.cmd = Kmd()
     self.cmd.preloop()