feat: Add an Oracle base class

This commit is contained in:
2025-05-21 18:46:33 +02:00
parent 839bc22734
commit 52f598c8b3
3 changed files with 106 additions and 0 deletions

57
tests/test_oracle_base.py Normal file
View File

@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2025 2025
# SPDX-FileContributor: Gergely Polonkai
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for the base Oracle class"""
from typing import Literal
import pytest
from gm_assistant.oracle.base import Oracle
TEST_ORACLE_DATA = {
"type": "test-oracle",
"name": "Test Oracle",
"source": "Test Source",
}
class OracleTest(Oracle):
"""Test Oracle class"""
TYPE_MARKER = "test-oracle"
def generate(self) -> str: # pragma: no cover
return "Something"
@pytest.mark.parametrize("missing", ["type", "name", "source"])
def test_missing_data(missing: Literal["type", "name", "source"]) -> None:
"""Test if oracle_data doesnt have a type"""
oracle_data = TEST_ORACLE_DATA.copy()
del oracle_data[missing]
with pytest.raises(KeyError):
OracleTest(oracle_data)
def test_incorrect_type() -> None:
"""Test if the type in the oracle data doesnt match the class TYPE_MARKER"""
oracle_data = TEST_ORACLE_DATA.copy()
oracle_data["type"] = "something-else"
with pytest.raises(TypeError):
OracleTest(oracle_data)
def test_init() -> None:
"""Test if initialisation succeeds with valid data"""
oracle = OracleTest(TEST_ORACLE_DATA)
assert oracle.name == "Test Oracle"
assert oracle.source == "Test Source"
assert oracle.source_url is None