Beispiel #1
0
    def test_copy ( self ):
        """ file copy """

        content = 'print "Hello World!"\n'

        f = File( 'data/foo.py' )
        self.assertEqual( f.exists, False )

        # Create the file.
        f.create_file( content )
        self.assertEqual( f.exists, True )
        self.failUnlessRaises( ValueError, f.create_file, content )

        self.assertEqual( f.children, None )
        self.assertEqual( f.ext, '.py' )
        self.assertEqual( f.is_file, True )
        self.assertEqual( f.is_folder, False )
        self.assertEqual( f.mime_type, 'text/x-python' )
        self.assertEqual( f.name, 'foo' )
        self.assertEqual( f.path, 'data/foo.py' )

        # Copy the file.
        g = File( 'data/bar.py' )
        self.assertEqual( g.exists, False )

        f.copy( g )
        self.assertEqual( g.exists, True )

        self.assertEqual( g.children, None )
        self.assertEqual( g.ext, '.py' )
        self.assertEqual( g.is_file, True )
        self.assertEqual( g.is_folder, False )
        self.assertEqual( g.mime_type, 'text/x-python' )
        self.assertEqual( g.name, 'bar' )
        self.assertEqual( g.path, 'data/bar.py' )

        # Attempt to copy a non-existent file (should do nothing).
        f = File( 'data/bogus.xx' )
        self.assertEqual( f.exists, False )

        g = File( 'data/bogus_copy.py' )
        self.assertEqual( g.exists, False )

        f.copy( g )
        self.assertEqual( g.exists, False )

        return
    def test_copy ( self ):
        """ folder copy """

        f = File( 'data/sub' )
        self.assertEqual( f.exists, False )

        # Create the folder.
        f.create_folder()
        self.assertEqual( f.exists, True )
        self.failUnlessRaises( ValueError, f.create_folder )

        self.assertEqual( len( f.children ), 0 )
        self.assertEqual( f.ext, '' )
        self.assertEqual( f.is_file, False )
        self.assertEqual( f.is_folder, True )
        self.assertEqual( f.mime_type, 'content/unknown' )
        self.assertEqual( f.name, 'sub' )
        self.assertEqual( f.path, 'data/sub' )

        # Copy the folder.
        g = File( 'data/copy' )
        self.assertEqual( g.exists, False )

        f.copy( g )
        self.assertEqual( g.exists, True )

        self.assertEqual( len( g.children ), 0 )
        self.assertEqual( g.ext, '' )
        self.assertEqual( g.is_file, False )
        self.assertEqual( g.is_folder, True )
        self.assertEqual( g.mime_type, 'content/unknown' )
        self.assertEqual( g.name, 'copy' )
        self.assertEqual( g.path, 'data/copy' )

        # Attempt to copy a non-existent folder (should do nothing).
        f = File( 'data/bogus' )
        self.assertEqual( f.exists, False )

        g = File( 'data/bogus_copy' )
        self.assertEqual( g.exists, False )

        f.copy( g )
        self.assertEqual( g.exists, False )

        return