示例#1
0
def test_read_greater_than_pagesize():
    f = filepath()
    s = os.sysconf("SC_PAGE_SIZE") * 2 + 1
    with base.posix_open(f, os.O_RDWR | os.O_CREAT) as fd:
        base.random_data(fd, s)
    # time.sleep(1)
    with base.posix_open(f, os.O_RDONLY) as fd:
        assert_equals(s, len(os.read(fd, s)))
示例#2
0
def test_read_and_stat_size_field():
    f = filepath()
    with base.posix_open(f, os.O_RDWR | os.O_CREAT) as fd:
        written = base.random_data(fd, random.randint(1024, 8192))
    with base.posix_open(f, os.O_RDONLY) as fd:
        data = os.read(fd, 8192)
        stat = os.fstat(fd)
        assert_equals(written, len(data))
        assert_equals(written, stat.st_size)
示例#3
0
def test_read_returns_eof_corretly():
    f = filepath()
    with open(f, "w") as fh:
        fh.write("foobar")
    with base.posix_open(f, os.O_RDONLY) as fd:
        os.read(fd, 6)
        assert_equals("", os.read(fd, 6))
示例#4
0
def test_open_truncate_set_size_to_zero():
    f = filepath()
    with open(f, "w") as fh:
        fh.write("foobar")
    assert_greater(os.stat(f).st_size, 0)
    with base.posix_open(f, os.O_RDWR | os.O_TRUNC):
        pass
    assert_equals(os.stat(f).st_size, 0)
示例#5
0
def test_write_update_mtime():
    f = filepath()
    with base.posix_open(f, os.O_RDWR | os.O_CREAT) as fd:
        s0 = os.fstat(fd)
        time.sleep(1)
        os.write(fd, "foobar")
        os.fsync(fd) # TODO:fix fstat
        s1 = os.fstat(fd)
        assert_less(s0.st_mtime, s1.st_mtime)
示例#6
0
def test_write_updates_size_field():
    f = filepath()
    with base.posix_open(f, os.O_RDWR | os.O_CREAT) as fd:
        s = os.fstat(fd)
        assert_equal(0, s.st_size)
        os.write(fd, "foobar")
        os.fsync(fd) # TODO:fix fstat
        s = os.fstat(fd)
        assert_equal(6, s.st_size)
示例#7
0
def test_read_with_buffersize_greater_than_file():
    f = filepath()
    with open(f, "w") as fh:
        fh.write("foobar")
    with base.posix_open(f, os.O_RDONLY) as fd:
        assert_equals("foobar", os.read(fd, 1024))
示例#8
0
def test_read():
    f = filepath()
    with open(f, "w") as fh:
        fh.write("foobar")
    with base.posix_open(f, os.O_RDONLY) as fd:
        assert_equals("foobar", os.read(fd, 6))
示例#9
0
def test_open_rdonly_should_not_allow_writing():
    f = filepath()
    base.touch(f)
    with base.posix_open(f, os.O_RDONLY) as fd:
        assert_raises(OSError, os.write, fd, "foobar")