feat: Add an Oracle base class
This commit is contained in:
57
tests/test_oracle_base.py
Normal file
57
tests/test_oracle_base.py
Normal 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 doesn’t 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 doesn’t 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
|
||||
Reference in New Issue
Block a user