예제 #1
0
def test_close_process_when_normal():
    """Process leaks must not occur in successful cases"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert len(pl.commands) == 1
        assert pl.commands[0]._process.poll() is None

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #2
0
def test_close_process_when_normal():
    """Process leaks must not occur in successful cases"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert len(pl.commands) == 1
        assert pl.commands[0]._process.poll() is None

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #3
0
def test_close_process_when_aborted():
    """Process leaks must not occur when the pipeline is aborted"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert len(pl.commands) == 1
        assert pl.commands[0]._process.poll() is None
        pl.abort()

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #4
0
def test_close_process_when_aborted():
    """Process leaks must not occur when the pipeline is aborted"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert len(pl.commands) == 1
        assert pl.commands[0]._process.poll() is None
        pl.abort()

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #5
0
def test_close_process_when_exception():
    """Process leaks must not occur when an exception is raised"""
    exc = Exception('boom')

    with pytest.raises(Exception) as e:
        with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
            assert len(pl.commands) == 1
            assert pl.commands[0]._process.poll() is None
            raise exc

    assert e.value is exc

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #6
0
def test_close_process_when_exception():
    """Process leaks must not occur when an exception is raised"""
    exc = Exception('boom')

    with pytest.raises(Exception) as e:
        with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
            assert len(pl.commands) == 1
            assert pl.commands[0]._process.poll() is None
            raise exc

    assert e.value is exc

    # Failure means a failure to terminate the process.
    pipeline_wait(pl)
예제 #7
0
def test_double_close():
    """A file should is able to be closed twice without raising"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert isinstance(pl.stdin, pipebuf.NonBlockBufferedWriter)
        assert not pl.stdin.closed
        pl.stdin.close()
        assert pl.stdin.closed
        pl.stdin.close()

        assert isinstance(pl.stdout, pipebuf.NonBlockBufferedReader)
        assert not pl.stdout.closed
        pl.stdout.close()
        assert pl.stdout.closed
        pl.stdout.close()

    pipeline_wait(pl)
예제 #8
0
def test_double_close():
    """A file should is able to be closed twice without raising"""
    with pipeline.get_cat_pipeline(pipeline.PIPE, pipeline.PIPE) as pl:
        assert isinstance(pl.stdin, pipebuf.NonBlockBufferedWriter)
        assert not pl.stdin.closed
        pl.stdin.close()
        assert pl.stdin.closed
        pl.stdin.close()

        assert isinstance(pl.stdout, pipebuf.NonBlockBufferedReader)
        assert not pl.stdout.closed
        pl.stdout.close()
        assert pl.stdout.closed
        pl.stdout.close()

    pipeline_wait(pl)
예제 #9
0
파일: tar_partition.py 프로젝트: deis/wal-e
def cat_extract(tar, member, targetpath):
    """Extract a regular file member using cat for async-like I/O

    Mostly adapted from tarfile.py.

    """
    assert member.isreg()

    # Fetch the TarInfo object for the given name and build the
    # destination pathname, replacing forward slashes to platform
    # specific separators.
    targetpath = targetpath.rstrip("/")
    targetpath = targetpath.replace("/", os.sep)

    # Create all upper directories.
    upperdirs = os.path.dirname(targetpath)
    if upperdirs and not os.path.exists(upperdirs):
        try:
            # Create directories that are not part of the archive with
            # default permissions.
            os.makedirs(upperdirs)
        except EnvironmentError as e:
            if e.errno == errno.EEXIST:
                # Ignore an error caused by the race of
                # the directory being created between the
                # check for the path and the creation.
                pass
            else:
                raise

    with files.DeleteOnError(targetpath) as dest:
        with pipeline.get_cat_pipeline(pipeline.PIPE, dest.f) as pl:
            fp = tar.extractfile(member)
            copyfileobj.copyfileobj(fp, pl.stdin)

    if sys.version_info < (3, 5):
        tar.chown(member, targetpath)
    else:
        tar.chown(member, targetpath, False)

    tar.chmod(member, targetpath)
    tar.utime(member, targetpath)
예제 #10
0
def cat_extract(tar, member, targetpath):
    """Extract a regular file member using cat for async-like I/O

    Mostly adapted from tarfile.py.

    """
    assert member.isreg()

    # Fetch the TarInfo object for the given name and build the
    # destination pathname, replacing forward slashes to platform
    # specific separators.
    targetpath = targetpath.rstrip("/")
    targetpath = targetpath.replace("/", os.sep)

    # Create all upper directories.
    upperdirs = os.path.dirname(targetpath)
    if upperdirs and not os.path.exists(upperdirs):
        try:
            # Create directories that are not part of the archive with
            # default permissions.
            os.makedirs(upperdirs)
        except EnvironmentError as e:
            if e.errno == errno.EEXIST:
                # Ignore an error caused by the race of
                # the directory being created between the
                # check for the path and the creation.
                pass
            else:
                raise

    with files.DeleteOnError(targetpath) as dest:
        with pipeline.get_cat_pipeline(pipeline.PIPE, dest.f) as pl:
            fp = tar.extractfile(member)
            copyfileobj.copyfileobj(fp, pl.stdin)

    if sys.version_info < (3, 5):
        tar.chown(member, targetpath)
    else:
        tar.chown(member, targetpath, False)

    tar.chmod(member, targetpath)
    tar.utime(member, targetpath)