Skip to content

Commit

Permalink
Add serialization, deserialization function test in trivial cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 2, 2024
1 parent bc3b3fc commit e343f48
Showing 1 changed file with 147 additions and 0 deletions.
147 changes: 147 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Any

import pytest
from pydantic import BaseModel

from github_app_geo_project import module
from github_app_geo_project.module.modules import MODULES
from github_app_geo_project.module.tests import TestModule

Expand Down Expand Up @@ -28,3 +32,146 @@ def test_conversions() -> None:
def test_all_empty_status() -> None:
for module in MODULES.values():
module.transversal_status_to_json(module.transversal_status_from_json({}))


class ConfigDictModule(module.Module[dict[str, Any], None, None]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_configuration_from_json(data) -> None:
test_module = ConfigDictModule()

assert test_module.configuration_from_json(data) == data


class EventDataDictModule(module.Module[None, dict[str, Any], None]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_event_data_from_json(data) -> None:
test_module = EventDataDictModule()

assert test_module.event_data_from_json(data) == data


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_envent_data_to_json(data) -> None:
test_module = EventDataDictModule()

assert test_module.event_data_to_json(data) == data


class TransversalStatusDictModule(module.Module[None, None, dict[str, Any]]):
pass


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_transversal_status_from_json(data) -> None:
test_module = TransversalStatusDictModule()

assert test_module.transversal_status_from_json(data) == data


@pytest.mark.parametrize(
"data",
[
{},
{"type": "success"},
],
)
def test_json_transversal_status_to_json(data) -> None:
test_module = TransversalStatusDictModule()

assert test_module.transversal_status_to_json(data) == data


class Data(BaseModel):
value: str


class ConfigDataModule(module.Module[Data, None, None]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_configuration_from_json(data, expected) -> None:
test_module = ConfigDataModule()

assert test_module.configuration_from_json(data) == expected


class EventDataDataModule(module.Module[None, Data, None]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_event_data_from_json(data, expected) -> None:
test_module = EventDataDataModule()

assert test_module.event_data_from_json(data) == expected


@pytest.mark.parametrize("data,expected", [[Data(value="test"), {"value": "test"}]])
def test_data_event_data_to_json(data, expected) -> None:
test_module = EventDataDataModule()

assert test_module.event_data_to_json(data) == expected


class TransversalStatusDataModule(module.Module[None, None, Data]):
pass


@pytest.mark.parametrize(
"data,expected",
[
[{"value": "test"}, Data(value="test")],
],
)
def test_data_transversal_status_from_json(data, expected) -> None:
test_module = TransversalStatusDataModule()

assert test_module.transversal_status_from_json(data) == expected


@pytest.mark.parametrize("data,expected", [[Data(value="test"), {"value": "test"}]])
def test_data_transversal_status_to_json(data, expected) -> None:
test_module = TransversalStatusDataModule()

assert test_module.transversal_status_to_json(data) == expected

0 comments on commit e343f48

Please sign in to comment.