Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI committed Mar 7, 2024
1 parent ca4cab8 commit 85d8915
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 17 additions & 1 deletion tests/test_sqlite.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 85d8915

Please sign in to comment.