Пример #1
0
def test_file_read_rb(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    lfs.file_write(mounted_fs, fh, b'0123456789')
    lfs.file_close(mounted_fs, fh)

    fh = lfs.file_open(mounted_fs, 'test.txt', 'rb')
    data = lfs.file_read(mounted_fs, fh, 10)
    assert data == b'0123456789'
Пример #2
0
def test_file_open_exist(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'wb')
    lfs.file_write(mounted_fs, fh, b'0123456789')
    lfs.file_close(mounted_fs, fh)

    with pytest.raises(LittleFSError) as excinfo:
        fh = lfs.file_open(mounted_fs, 'test.txt', 'x')

    assert excinfo.value.code == LittleFSError.Error.LFS_ERR_EXIST
Пример #3
0
def test_file_open_a(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    lfs.file_write(mounted_fs, fh, b'0123456789')
    lfs.file_close(mounted_fs, fh)

    fh = lfs.file_open(mounted_fs, 'test.txt', 'a')
    lfs.file_write(mounted_fs, fh, b'0123456789')
    lfs.file_close(mounted_fs, fh)

    info = lfs.stat(mounted_fs, 'test.txt')
    assert info.size == 20
Пример #4
0
def test_file_open_isdir(mounted_fs):
    lfs.mkdir(mounted_fs, 'testdir')

    with pytest.raises(LittleFSError) as excinfo:
        fh = lfs.file_open(mounted_fs, 'testdir', "r")

    assert excinfo.value.code == LittleFSError.Error.LFS_ERR_ISDIR
Пример #5
0
def test_file_seek(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    # Seek whenece:
    #   0: Absolute
    #   1: Relative to Current Position
    #   2: Relative to EOF
    new_pos = lfs.file_seek(mounted_fs, fh, 10, 0)
    assert new_pos == 10
Пример #6
0
def test_stat_file(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    lfs.file_write(mounted_fs, fh, b'0123456789')
    lfs.file_close(mounted_fs, fh)

    stat = lfs.stat(mounted_fs, 'test.txt')

    assert stat.size == 10
    assert stat.type == 1
    assert stat.name == 'test.txt'
Пример #7
0
def test_file_size(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    assert lfs.file_size(mounted_fs, fh) == 0
Пример #8
0
def test_file_open_wb(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'wb')
Пример #9
0
def test_file_truncate(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    assert lfs.file_truncate(mounted_fs, fh, 10) == 0
Пример #10
0
def test_file_write(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    lfs.file_write(mounted_fs, fh, b'0123456789')
Пример #11
0
def test_file_sync(mounted_fs):
    fh = lfs.file_open(mounted_fs, 'test.txt', 'w')
    lfs.file_sync(mounted_fs, fh)
Пример #12
0
def test_file_open_noent(mounted_fs):
    with pytest.raises(LittleFSError) as excinfo:
        flags = lfs.LFSFileFlag.rdonly
        fh = lfs.file_open(mounted_fs, 'test.txt', flags)

    assert excinfo.value.code == LittleFSError.Error.LFS_ERR_NOENT
Пример #13
0
def test_file_open_flags(mounted_fs):
    flags = lfs.LFSFileFlag.wronly | lfs.LFSFileFlag.creat
    fh = lfs.file_open(mounted_fs, 'test.txt', flags)