test_errors.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:makemkv 作者: Robpol86 项目源码 文件源码
def test_rip_error(request, tmpdir):
    """Test failed rips error handling.

    :param request: pytest fixture.
    :param py.path.local tmpdir: pytest fixture.
    """
    # Duplicate ISO.
    iso = tmpdir.join('truncated.iso')
    py.path.local(__file__).dirpath().join('sample.iso').copy(iso)

    # Load the ISO.
    pytest.cdload(iso)

    # Execute.
    output = tmpdir.ensure_dir('output')
    command = ['docker', 'run', '--device=/dev/cdrom', '-v', '{}:/output'.format(output), '-e', 'DEBUG=true',
               'robpol86/makemkv']
    master, slave = pty.openpty()
    request.addfinalizer(lambda: [os.close(master), os.close(slave)])
    proc = subprocess.Popen(command, bufsize=1, cwd=HERE, stderr=subprocess.STDOUT, stdin=slave, stdout=subprocess.PIPE)

    # Read output.
    caught = False
    while proc.poll() is None or proc.stdout.peek(1):
        for line in proc.stdout:
            # Watch for specific line, then truncate ISO.
            if b'Analyzing seamless segments' in line:
                iso.open('w').close()
            elif b'ERROR: One or more titles failed.' in line:
                caught = True
            print(line)  # Write to stdout, pytest will print if test fails.

    # Verify.
    assert proc.poll() > 0
    assert caught is True
    pytest.verify_failed_file(output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号