示例#1
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
示例#2
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__)
示例#3
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
示例#4
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
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
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)