예제 #1
0
파일: test_main.py 프로젝트: lazka/giofile
def test_readable_writable(gfile):
    with gopen(gfile, "rb") as f:
        assert f.readable()
        assert not f.writable()

    with gopen(gfile, "r+b") as f:
        assert f.readable()
        assert f.writable()
예제 #2
0
파일: test_main.py 프로젝트: lazka/giofile
def test_http():
    gfile = Gio.File.new_for_uri(
        "http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus")
    with pytest.raises(IOError):
        gopen(gfile, "r+b")

    with gopen(gfile, "rb") as f:
        assert f.name == "ehren-paper_lights-96.opus"
        with pytest.raises(IOError):
            f.fileno()
예제 #3
0
파일: test_main.py 프로젝트: lazka/giofile
def test_close(gfile):
    with gopen(gfile, "r+b") as f:
        assert not f.closed
        f.close()
        assert f.closed
        f.close()

    with gopen(gfile, "r+b") as f:
        pass
    assert f.closed
예제 #4
0
파일: test_main.py 프로젝트: lazka/giofile
def test_readline(gfile):
    with gopen(gfile, "r+b") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo\nbar")
        assert f.readline() == b"foo\n"
        assert f.readline() == b"bar"
        assert f.readline() == b""
예제 #5
0
파일: test_main.py 프로젝트: lazka/giofile
def test_buffered_reader(gfile):
    with gopen(gfile, "rb") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo")
        assert f.peek(3) == b"foo"
        assert f.tell() == 0
        f.read1(10)
예제 #6
0
파일: test_main.py 프로젝트: lazka/giofile
def test_read_write(gfile):
    with gopen(gfile, "r+b") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo")
        assert f.read(1) == b"f"
        assert f.read() == b"oo"
        assert f.write(b"bar") == 3
예제 #7
0
파일: test_main.py 프로젝트: lazka/giofile
def test_truncate(gfile):
    with gopen(gfile, "r+b") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo")
        assert f.seek(0, 2) == 3
        f.seek(0, 0)
        f.truncate()
        assert f.seek(0, 2) == 0
예제 #8
0
파일: test_main.py 프로젝트: lazka/giofile
def test_buffered_writer(gfile):
    cancel = Gio.Cancellable.new()
    with gopen(gfile, "r+b", cancellable=cancel) as f:
        with open(f.name, "wb") as h:
            h.write(b"foo")
        with io.BufferedWriter(f) as b:
            b.write(b"x")
            b.flush()
            f.seek(0)
            assert f.read() == b"xoo"
예제 #9
0
파일: test_main.py 프로젝트: lazka/giofile
def test_readinto(gfile):
    data = b"x" * (io.DEFAULT_BUFFER_SIZE * 10)
    with gopen(gfile, "r+b") as f:
        with open(f.name, "wb") as h:
            h.write(data)

        assert f.read() == data
        f.seek(0)
        buf = bytearray(len(data))
        f.readinto(buf)
        assert buf == data
예제 #10
0
파일: test_main.py 프로젝트: lazka/giofile
def test_kwargs(gfile):
    with pytest.raises(TypeError):
        gopen(gfile, foo=1)
예제 #11
0
파일: test_main.py 프로젝트: lazka/giofile
def test_iter(gfile):
    with gopen(gfile, "r+b") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo\nbar")
        assert [l for l in f] == [b"foo\n", b"bar"]
예제 #12
0
파일: test_main.py 프로젝트: lazka/giofile
def test_tell(gfile):
    with gopen(gfile, "rb") as f:
        assert f.seek(1, 0) == f.tell()
예제 #13
0
파일: test_main.py 프로젝트: lazka/giofile
def test_seek(gfile):
    with gopen(gfile, "rb") as f:
        assert f.seekable()
        assert f.seek(0, 0) == 0
예제 #14
0
파일: test_main.py 프로젝트: lazka/giofile
def test_invalid_buffering(gfile):
    with pytest.raises(ValueError):
        gopen(gfile, "r", buffering=0)

    with pytest.raises(ValueError):
        gopen(gfile, "rb", buffering=1)
예제 #15
0
파일: test_main.py 프로젝트: lazka/giofile
def test_line_buffering(gfile):
    with gopen(gfile, "r") as f:
        assert not f.line_buffering

    with gopen(gfile, "r", buffering=1) as f:
        assert f.line_buffering
예제 #16
0
파일: test_main.py 프로젝트: lazka/giofile
def test_isatty(gfile):
    with gopen(gfile, "r+b") as f:
        assert not f.isatty()
예제 #17
0
파일: test_main.py 프로젝트: lazka/giofile
def test_fileno(gfile):
    with gopen(gfile, "rb") as f:
        assert isinstance(f.fileno(), int)
예제 #18
0
파일: test_main.py 프로젝트: lazka/giofile
def test_text_mode(gfile):
    with gopen(gfile, "r") as f:
        with open(f.name, "wb") as h:
            h.write(b"foo")
        assert f.read() == u"foo"
예제 #19
0
파일: test_main.py 프로젝트: lazka/giofile
def test_flush_closed(gfile):
    with gopen(gfile, "r+b") as f:
        pass
    with pytest.raises(ValueError):
        f.flush()