def testCopyingFilesWithWildcardPattern(progressSubject, filledSourceDirectory, dstDir, exampleFilenames, exampleDirectories): copy(filledSourceDirectory + '/*', dstDir, progressSubject) makeSureFilesAndFoldersExistAtDestinationWithoutLongPath( exampleFilenames, exampleDirectories, dstDir)
def testCopyingFromDirectoryToNonExistingCreatesFolderAndCopiesContent( progressSubject, filledSourceDirectory, dstDir, exampleFilenames, exampleDirectories): # src = dir, dst = not existent => create dst, copy content of src into dst shutil.rmtree(dstDir) copy(filledSourceDirectory, dstDir, progressSubject) makeSureFilesAndFoldersExistAtDestinationWithoutLongPath( exampleFilenames, exampleDirectories, dstDir)
def testCopyingManyFilesIntoNonFileDestination(progressSubject, filledSourceDirectory, dstDir, exampleFilenames, exampleDirectories): # src = dir/*, dst = not file => create dst if not exists, copy content of src into dst copy(filledSourceDirectory + '/*.*', dstDir, progressSubject) makeSureFilesAndFoldersExistAtDestinationWithoutLongPath( exampleFilenames, exampleDirectories, dstDir)
def testCopyingFromDirectoryToFileRaisesException(progressSubject, srcDir, dstDir): # src = dir, dst = file => error testSrcDir = os.path.join(srcDir, 'testdir') os.makedirs(testSrcDir) testDstDir = os.path.join(dstDir, 'testdir') with open(testDstDir, 'w'): pass with pytest.raises(OSError): copy(testSrcDir, testDstDir, progressSubject)
def testCopyingFromFileToDirectory(progressSubject, srcDir, dstDir): # src = file, dst = dir => copy into dst srcfile = os.path.join(srcDir, 'testfile') dstfile = os.path.join(dstDir, 'testfile2') with open(srcfile, 'w') as f: f.write('new') copy(srcfile, dstfile, progressSubject) with open(dstfile) as f: data = f.read() assert 'new' == data
def testCopyingFromFileToNonExistingDestination(progressSubject, srcDir, dstDir): # src = file, dst = not existent => create dst directories, copy src to dst srcfile = os.path.join(srcDir, 'testfile') dstfile = os.path.join(dstDir, 'newdir', 'testfile') with open(srcfile, 'w') as f: f.write('new') copy(srcfile, dstfile, progressSubject) with open(dstfile) as f: data = f.read() assert 'new' == data
def testCopyingFromFileToFileOverwritesDestination(progressSubject, srcDir, dstDir): srcfile = os.path.join(srcDir, 'testfile') with open(srcfile, 'w') as f: f.write('new') dstfile = os.path.join(dstDir, 'testfile') with open(dstfile, 'w') as f: f.write('old') copy(srcfile, dstfile, progressSubject) with open(dstfile) as f: data = f.read() assert 'new' == data
def testCopyingFromDirectoryToDirectoryCopiesContent(progressSubject, filledSourceDirectory, dstDir, exampleFilenames, exampleDirectories): # src = dir, dst = dir => copy src dir into dst copy(filledSourceDirectory, dstDir, progressSubject) makeSureFilesAndFoldersExistAtDestination(exampleFilenames, exampleDirectories, filledSourceDirectory, dstDir) copy(filledSourceDirectory, dstDir, progressSubject) for name in os.listdir( os.path.join(dstDir, os.path.basename(filledSourceDirectory))): assert name in exampleDirectories + exampleFilenames for dirname in exampleDirectories: a = os.path.join(dstDir, os.path.basename(filledSourceDirectory), dirname) for name in os.listdir(a): assert name in exampleFilenames