Example #1
0
    def test_executablescript ( self ):
        """make sure the script is executable """

        text=( "~# date >/dev/null \n"
               "coucou\nbonjour\n"
               "~# ls >/dev/null \n"
               "passwd:" )
        import os
        self.assertEqual( os.system(session(text).toscript()), 0)
Example #2
0
    def test_output (self):

        outputs = (
            ("hello world\n~$ ", "hello world" ),
            ("hello world\n~good by\n~$ ", "hello world\n~good by" ),
            ( "~$ ", ""),
            ( "~# ", ""),
            ( "", "") )

        for text, expected in outputs:
            self.assertEqual( session(text)._takewhile(is_output=True), expected)
Example #3
0
    def test_next ( self ):
        
        text=( "~$ ls\n"
               "coucou\n"
               "~$ tr\n"
               "passwd:" )

        self.assertEqual(
            list(session(text)),
            [ ("ls", "coucou"), ("tr", "passwd:") ]
            )
Example #4
0
    def test_command (self):

        commands = (
            ("date\nls\nid\n", "date" ),
            ("date # comment\n", "date # comment" ),
            ("ls # ~$ promptlike\n", "ls # ~$ promptlike" ),
            ( "hello () {\n echo hello\n} \n some more stuff",
              "hello () {\n echo hello\n}" ),
            ( "( cd \ntmp )\n", "( cd \ntmp )"),
            ( "ls", "ls"),
            ( "", "") )

        for text, expected in commands:
            self.assertEqual( session(text)._takewhile(), expected ) 
Example #5
0
    def test_toscript ( self ):
        
        text= ( "~# ls\n"
               "coucou\nbonjour\n"
               "~# tr\n"
               "passwd:" )

        self.assertEqual(
            session(text).toscript(),
            ( "#!/bin/sh\nset -e  # -x\n\n"
              "ls\n"
              "# coucou\n"
              "# bonjour\n\n"
              "tr\n"
              "# passwd:\n\n" )
            )