diff --git a/tests/conftest.py b/tests/conftest.py index 7c5a554..fdbd19c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,13 @@ import os +from typing import BinaryIO import pytest -def open_data(name): +def open_data(name: str) -> BinaryIO: return open(os.path.join(os.path.dirname(__file__), name), "rb") @pytest.fixture -def sqlite_db(): +def sqlite_db() -> BinaryIO: return open_data("data/test.sqlite") diff --git a/tests/test_sqlite.py b/tests/test_sqlite.py index e5f0226..38d4960 100644 --- a/tests/test_sqlite.py +++ b/tests/test_sqlite.py @@ -1,8 +1,13 @@ +from io import BytesIO +from typing import Any, BinaryIO + +import pytest + from dissect.sql import sqlite3 from dissect.sql.c_sqlite3 import SQLITE3_HEADER_MAGIC -def test_sqlite(sqlite_db): +def test_sqlite(sqlite_db: BinaryIO) -> None: s = sqlite3.SQLite3(sqlite_db) assert s.header.magic == SQLITE3_HEADER_MAGIC @@ -35,3 +40,14 @@ def test_sqlite(sqlite_db): assert len(rows) == len(list(table)) assert table.row(0).__dict__ == rows[0].__dict__ assert list(rows[0]) == [("id", 1), ("name", "testing"), ("value", 1337)] + + +@pytest.mark.parametrize( + "input, encoding, expected_output", + [ + (b"\x04\x00\x1b\x02testing\x059", "utf-8", ([0, 27, 2], [None, "testing", 1337])), + (b"\x02\x65\x80\x81\x82\x83", "utf-8", ([101], [b"\x80\x81\x82\x83"])), + ], +) +def test_sqlite_read_record(input: bytes, encoding: str, expected_output: tuple[list[int], list[Any]]) -> None: + assert sqlite3.read_record(BytesIO(input), encoding) == expected_output