Ejemplo n.º 1
0
    def test_file(self) -> None:
        p = StdPath("test").with_streams(
            filein=OpenBytesIO(b"hello world"), fileout=OpenBytesIO()
        )

        assert p.read_text() == "hello world"

        p.write_text("hello mars")

        assert p.fileout.read() == b"hello mars"
Ejemplo n.º 2
0
    def test_pep263(self) -> None:
        p = StdPath("-").with_streams(
            stdin=io.BytesIO("# -*- coding: ascii -*-\nпривет".encode("utf-8")),
            stdout=io.BytesIO(),
        )

        assert p.is_file()

        with pytest.raises(UnicodeDecodeError):
            assert p.read_text()
Ejemplo n.º 3
0
    def test_stdin(self) -> None:
        p = StdPath("-").with_streams(
            stdin=io.BytesIO(b"  hello\n  world\n"), stdout=io.BytesIO()
        )

        assert p.is_file()

        assert p.read_text() == "hello\nworld\n"

        p.write_text("hello\nmars\n")
        p.stdout.seek(0)

        assert p.stdout.read() == b"  hello\n  mars\n"