Ejemplo n.º 1
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))
Ejemplo n.º 2
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)))
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 9
0
def test_open_update_atime():
    f  = filepath()
    s0 = base.touch(f)
    time.sleep(1)
    s1 = base.touch(f)
    assert_less(s0.st_atime, s1.st_atime)
Ejemplo n.º 10
0
def test_open_wronly_should_raise_exception_when_file_does_not_exist():
    f = filepath()
    assert_raises(OSError, lambda: os.close(os.open(f, os.O_WRONLY)))
Ejemplo n.º 11
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")
Ejemplo n.º 12
0
def test_stat_should_return_the_correct_type_for_directories():
    d = filepath()
    os.mkdir(d)
    s = os.stat(d)