Example #1
0
    def test_help_newpy(self):
        '''
        Run "pytool help newpy". Verify that the output is correct.
        '''
        prepare_tests()
        S = pexpect.spawn('../pytool help newpy')
        which = S.expect([r'Are you sure\? >',
                          'Error:',
                          pexpect.EOF])
        if which == 0:
            S.sendline('no')
            S.expect(pexpect.EOF)
            self.fail('should not have asked about overwriting')
        elif which == 1:
            print S.before + S.after
            self.fail('unexpected exception')

        got = S.before.split('\r\n')
        expected = ['newpy - Create a new python program',
                    '',
                    '    usage: pytool newpy <program-name>',
                    '',
                    '    Creates executable file <program-name>.py'
                       + ' with skeletal',
                    '    contents. Run "<program-name>.py -L" to create'
                       + ' link <program-name>.',
                    '    ',
                    '']
        testhelp.expectVSgot(expected, got)
Example #2
0
    def test_help_newtool(self):
        '''
        Run "pytool help newtool". Verify that the output is correct.
        '''
        prepare_tests()
        S = pexpect.spawn('../pytool help newtool')
        which = S.expect([r'Are you sure\? >',
                          'Error:',
                          pexpect.EOF])
        if which == 0:
            S.sendline('no')
            S.expect(pexpect.EOF)
            self.fail('should not have asked about overwriting')
        elif which == 1:
            print S.before + S.after
            self.fail('unexpected exception')

        got = S.before.split('\r\n')
        expected = ['newtool - Create a new tool-style program',
                    '',
                    '    usage: pytool newtool <program-name> <prefix>',
                    '',
                    '    Creates executable file <program-name>.py'
                        + ' with skeletal',
                    '    contents. The structure of the program is such'
                        + ' that it is easy',
                    '    to add and describe new subfunctions.',
                    '    ',
                    '']
        testhelp.expectVSgot(expected, got)
Example #3
0
    def test_newtool(self):
        '''
        Run "pytool newtool testtool tt". Verify that testtool.py
        is created and has the right contents.
        '''
        prepare_tests()
        safe_unlink(['testtool', 'testtool.py'])
        S = pexpect.spawn('../pytool newtool testtool tt')
        S.logfile = sys.stdout
        which = S.expect([r'Are you sure\? >',
                          'Error:',
                          pexpect.EOF])
        if which == 0:
            S.sendline('no')
            S.expect(pexpect.EOF)
            self.fail('should not have asked about overwriting')
        elif which == 1:
            print S.before + S.after
            self.fail('unexpected exception')
            
        assert(not os.path.exists('testtool'))

        expected = expected_testtool_py()
        got = contents('testtool.py')
        testhelp.expectVSgot(expected, got)
Example #4
0
 def test_newpy_overwriting_yes(self):
     '''
     Run "pytool newpy xyzzy" when xyzzy, xyzzy.py already exist.
     Verify that confirmation is requested. Answer "yes" and verify
     that the existing file IS overwritten.
     '''
     prepare_tests()
     safe_unlink(['xyzzy', 'xyzzy.py'])
     writefile('xyzzy.py', ['original xyzzy\n'])
     S = pexpect.spawn('../pytool newpy xyzzy')
     which = S.expect([r'Are you sure\? >',
                       'Error:',
                       pexpect.EOF])
     if which == 0:
         S.sendline('yes')
         S.expect(pexpect.EOF)
     elif which == 1:
         print S.before + S.after
         self.fail('unexpected exception')
     else:
         self.fail('should have asked about overwriting xyzzy')
         
     assert(not os.path.exists('xyzzy'))
     
     expected = expected_xyzzy_py()
     got = contents('xyzzy.py')
     testhelp.expectVSgot(expected, got)
Example #5
0
    def test_diff(self):
        """
        Test diff
        """
        tpbtools.writefile('mrpm1', ['this is a test file\n'])
        tpbtools.writefile('mrpm2', ['this is another test file\n'])
        tpbtools.writefile('mrpm1.2009-10-01', ['copy of test file\n'])
        tpbtools.writefile('old/mrpm2.2009-08-31',
                           ['copy of another test file\n'])

        expected = ['diff ./mrpm1.2009-10-01 mrpm1\n',
                    '1c1\n',
                    '< copy of test file\n',
                    '---\n',
                    '> this is a test file\n']
        f = os.popen('../fl diff mrpm1')
        got = f.readlines()
        f.close()
        testhelp.expectVSgot(expected, got)

        expected = ['diff ./old/mrpm2.2009-08-31 mrpm2\n',
                    '1c1\n',
                    '< copy of another test file\n',
                    '---\n',
                    '> this is another test file\n']
        f = os.popen('../fl diff mrpm2')
        got = f.readlines()
        f.close()
        testhelp.expectVSgot(expected, got)
Example #6
0
    def test_most_recent_prefix_match(self):
        """
        Test the routine most_recent_prefix_match()
        """
        tpbtools.writefile('mrpm1', ['this is a test file'])
        tpbtools.writefile('mrpm2', ['this is another test file'])
        os.system('cp mrpm1 mrpm1.2009-10-01')
        os.system('cp mrpm2 old/mrpm2.2009-08-31')

        a = most_recent_prefix_match('.', 'mrpm1')
        testhelp.expectVSgot('./mrpm1.2009-10-01', a)

        a = most_recent_prefix_match('.', 'mrpm2')
        testhelp.expectVSgot('./old/mrpm2.2009-08-31', a)
Example #7
0
 def test_newpy_x(self):
     '''
     Run "pytool newpy xyzzy". Verify that xyzzy and xyzzy.py are created
     and have the right contents.
     '''
     prepare_tests()
     safe_unlink(['xyzzy', 'xyzzy.py'])
     S = pexpect.spawn('../pytool newpy xyzzy')
     try:
         S.expect(pexpect.EOF)
     except pexpect.TIMEOUT:
         fail('pytool should not prompt in this case')
     assert(not os.path.exists('xyzzy'))
     assert(os.path.exists('xyzzy.py'))
     
     got = contents('xyzzy.py')
     expected = expected_xyzzy_py()
     testhelp.expectVSgot(expected, got)