gm-assistant/tests/test_oracle_base.py

58 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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