コード例 #1
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
def testCopyingFilesWithWildcardPattern(progressSubject, filledSourceDirectory,
                                        dstDir, exampleFilenames,
                                        exampleDirectories):
    copy(filledSourceDirectory + '/*', dstDir, progressSubject)

    makeSureFilesAndFoldersExistAtDestinationWithoutLongPath(
        exampleFilenames, exampleDirectories, dstDir)
コード例 #2
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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)
コード例 #3
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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)
コード例 #4
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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)
コード例 #5
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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
コード例 #6
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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
コード例 #7
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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
コード例 #8
0
ファイル: test_system.py プロジェクト: mpice-mn/python-opsi
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