all repos — mgba @ e820e4dcbb71bd3e7486e9a828a0226075103bc3

mGBA Game Boy Advance Emulator

src/platform/python/tests/mgba/test_vfs.py (view raw)

 1import pytest
 2import os
 3
 4import mgba.vfs as vfs
 5from mgba._pylib import ffi
 6
 7def test_vfs_open():
 8    with open(__file__) as f:
 9        vf = vfs.open(f)
10        assert vf
11        assert vf.close()
12
13def test_vfs_openPath():
14    vf = vfs.openPath(__file__)
15    assert vf
16    assert vf.close()
17
18def test_vfs_read():
19    vf = vfs.openPath(__file__)
20    buffer = ffi.new('char[13]')
21    assert vf.read(buffer, 13) == 13
22    assert ffi.string(buffer) == 'import pytest'
23    vf.close()
24
25def test_vfs_readline():
26    vf = vfs.openPath(__file__)
27    buffer = ffi.new('char[16]')
28    linelen = vf.readline(buffer, 16)
29    assert linelen in (14, 15)
30    if linelen == 14:
31        assert ffi.string(buffer) == 'import pytest\n'
32    elif linelen == 15:
33        assert ffi.string(buffer) == 'import pytest\r\n'
34    vf.close()
35
36def test_vfs_readAllSize():
37    vf = vfs.openPath(__file__)
38    buffer = vf.readAll()
39    assert buffer
40    assert len(buffer)
41    assert len(buffer) == vf.size()
42    vf.close()
43
44def test_vfs_seek():
45    vf = vfs.openPath(__file__)
46    assert vf.seek(0, os.SEEK_SET) == 0
47    assert vf.seek(1, os.SEEK_SET) == 1
48    assert vf.seek(1, os.SEEK_CUR) == 2
49    assert vf.seek(-1, os.SEEK_CUR) == 1
50    assert vf.seek(0, os.SEEK_CUR) == 1
51    assert vf.seek(0, os.SEEK_END) == vf.size()
52    assert vf.seek(-1, os.SEEK_END) == vf.size() -1
53    vf.close()
54
55def test_vfs_openPath_invalid():
56    vf = vfs.openPath('.invalid')
57    assert not vf