Beispiel #1
0
 def test_zero_length_copy(self):
     with _TestDirectory() as t:
         t.create()
         with self.getNewDestination() as dest:
             PyCopier(t.sourceDirectory, dest,
                      zeroLengthFiles=True).execute()
             assert t.checkMatch(dest, zeroLengthFiles=True)
Beispiel #2
0
 def test_permission_copy(self):
     with _TestDirectory() as t:
         t.create()
         with self.getNewDestination() as dest:
             PyCopier(t.sourceDirectory, dest,
                      copyPermissions=True).execute()
             assert t.checkMatch(dest, checkPermissions=True)
Beispiel #3
0
 def test_generic_copy_various_worker_count(self):
     for numWorkers in range(1, 16):
         with _TestDirectory() as t:
             t.create()
             with self.getNewDestination() as dest:
                 PyCopier(t.sourceDirectory, dest,
                          numWorkers=numWorkers).execute()
                 assert t.checkMatch(dest)
Beispiel #4
0
 def test_generic_copy_weird_buffer_size(self):
     for bufferSize in [1024, 4096, 8192, 1, 2]:
         with _TestDirectory() as t:
             t.create()
             with self.getNewDestination() as dest:
                 PyCopier(t.sourceDirectory, dest,
                          bufferSize=bufferSize).execute()
                 assert t.checkMatch(dest)
Beispiel #5
0
    def test_errors_ignored_on_copy(self):
        p = PyCopier(source=None, destination=None, ignoreErrorOnCopy=True)
        with self.getNewDestination() as dest:
            p._copyFile("/fake/file", dest)

        # nothing raised... nothing copied
        assert p.getSkippedCopiesCount() == 0
        assert p.getCopiedDataBytes() == 0
Beispiel #6
0
    def test_skip_same_looking_file_doesnt_happen_if_meta_doesnt_match(self):
        p = PyCopier(source=None, destination=None, skipSameLookingFiles=True)
        with self.getNewDestination() as dest:
            shutil.copy(__file__, dest)
            p._copyFile(__file__, dest)

        assert p.getSkippedCopiesCount() == 0
        assert p.getCopiedDataBytes() == os.path.getsize(__file__)
Beispiel #7
0
    def test_skip_same_looking_file(self):
        p = PyCopier(source=None, destination=None, skipSameLookingFiles=True)
        with self.getNewDestination() as dest:
            shutil.copy2(__file__, dest)
            p._copyFile(__file__, dest)

        assert p.getSkippedCopiesCount() == 1
        assert p.getCopiedDataBytes() == 0
Beispiel #8
0
    def test_purge_destination(self):
        with _TestDirectory() as t:
            t.create()
            with self.getNewDestination() as dest:
                os.mkdir(dest)
                fileThatShouldBePurged = os.path.join(dest, 'test_tmp')
                with open(fileThatShouldBePurged, 'w') as f:
                    f.write('test')

                PyCopier(t.sourceDirectory, dest,
                         purgeDestination=False).execute()
                assert os.path.exists(fileThatShouldBePurged)
                assert t.checkMatch(dest, ignoreExtraRight=True)

                PyCopier(t.sourceDirectory, dest,
                         purgeDestination=True).execute()
                assert not os.path.exists(fileThatShouldBePurged)
                assert t.checkMatch(dest)
Beispiel #9
0
    def test_generic_copy_file(self):
        p = PyCopier(source=None, destination=None)
        with self.getNewDestination() as dest:
            p._copyFile(__file__, dest)
            assert os.path.isfile(dest)
            assert filecmp.cmp(__file__, dest, shallow=False)

        assert p.getCopiedDataBytes() == os.path.getsize(__file__)
        assert p.getSkippedCopiesCount() == 0
Beispiel #10
0
    def test_copy_single_file_into_dir(self):
        with self.getNewDestination() as dest:
            os.mkdir(dest)

            p = PyCopier(source=__file__, destination=dest)
            p.execute()
            assert p.getCopiedDataBytes() == os.path.getsize(__file__)
            assert filecmp.cmp(__file__,
                               os.path.join(dest, os.path.basename(__file__)),
                               shallow=False)
Beispiel #11
0
    def test_quiet_param(self):
        with _TestDirectory() as t:
            t.create()
            output = io.StringIO()
            with self.getNewDestination() as dest:
                with contextlib.redirect_stdout(
                        output), contextlib.redirect_stderr(output):
                    PyCopier(t.sourceDirectory, dest, quiet=True).execute()

                assert t.checkMatch(dest)

            assert output.getvalue(
            ) == '', "Nothing should go to output if quiet"
Beispiel #12
0
    def test_cleaning_directory(self):
        p = PyCopier(source=None, destination=None, ignoreErrorOnCopy=False)
        with _TestDirectory() as t:
            t.create()

            # count files
            numFiles = 0
            for path, dirs, files in os.walk(t.sourceDirectory):
                numFiles += len(files)

            p._cleanDestinationDirectory(t.sourceDirectory, [])

        # nothing raised... nothing copied
        assert p.getPurgedFileCount() == numFiles
Beispiel #13
0
    def test_copy_single_file_with_move(self):
        with open(__file__, 'rb') as f:
            fileData = f.read()

        try:
            with self.getNewDestination() as dest:
                p = PyCopier(source=__file__, destination=dest, move=True)
                p.execute()
                assert p.getCopiedDataBytes() == len(fileData)
                with open(dest, 'rb') as f:
                    newFileData = f.read()

                assert fileData == newFileData
                assert not os.path.exists(__file__)
        finally:
            with open(__file__, 'wb') as f:
                f.write(fileData)
Beispiel #14
0
    def test_copy_single_file_into_dir_and_purge(self):
        with self.getNewDestination() as dest:
            os.mkdir(dest)
            TEST_PATH = os.path.join(dest, 'test')
            with open(TEST_PATH, 'wb') as f:
                f.write(b'abc' * 10)

            p = PyCopier(source=__file__,
                         destination=dest,
                         purgeDestination=True)
            p.execute()

            assert p.getCopiedDataBytes() == os.path.getsize(__file__)
            assert filecmp.cmp(__file__,
                               os.path.join(dest, os.path.basename(__file__)),
                               shallow=False)
            assert not os.path.exists(TEST_PATH)
Beispiel #15
0
 def test_copy_single_file(self):
     with self.getNewDestination() as dest:
         p = PyCopier(source=__file__, destination=dest)
         p.execute()
         assert p.getCopiedDataBytes() == os.path.getsize(__file__)
         assert filecmp.cmp(__file__, dest, shallow=False)
Beispiel #16
0
 def test_move(self):
     with _TestDirectory() as t:
         t.create()
         with self.getNewDestination() as dest:
             PyCopier(t.sourceDirectory, dest, move=True).execute()
             assert t.checkMatch(dest, move=True)