示例#1
0
def test_pickling_and_unpickling_enocded_file():
    # See https://bitbucket.org/pytest-dev/pytest/pull-request/194
    # pickle.loads() raises infinite recursion if
    # EncodedFile.__getattr__ is not implemented properly
    ef = capture.EncodedFile(None, None)
    ef_as_str = pickle.dumps(ef)
    pickle.loads(ef_as_str)
示例#2
0
def test_encodedfile_writelines(tmpfile: BinaryIO) -> None:
    ef = capture.EncodedFile(tmpfile, "utf-8")
    with pytest.raises(AttributeError):
        ef.writelines([b"line1", b"line2"])  # type: ignore[list-item]  # noqa: F821
    assert ef.writelines(["line1", "line2"]) is None  # type: ignore[func-returns-value]  # noqa: F821
    tmpfile.seek(0)
    assert tmpfile.read() == b"line1line2"
    tmpfile.close()
    with pytest.raises(ValueError):
        ef.read()
示例#3
0
def test_encodedfile_writelines(tmpfile: BinaryIO) -> None:
    ef = capture.EncodedFile(tmpfile, encoding="utf-8")
    with pytest.raises(TypeError):
        ef.writelines([b"line1", b"line2"])
    assert ef.writelines(["line3", "line4"]) is None  # type: ignore[func-returns-value]  # noqa: F821
    ef.flush()
    tmpfile.seek(0)
    assert tmpfile.read() == b"line3line4"
    tmpfile.close()
    with pytest.raises(ValueError):
        ef.read()