Skip to content

Commit

Permalink
feat(core): add _type field to the serialized immutable instances
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Sep 3, 2024
1 parent 616dfc2 commit 3708af6
Show file tree
Hide file tree
Showing 83 changed files with 247 additions and 101 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.16.1

- feat(core): add `_type` field to the serialized immutable instances

## Version 0.16.0

- feat(core): add blocking `wait_for_event_handlers` method to `Store` to wait for all event handlers to finish
Expand Down
172 changes: 96 additions & 76 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-redux"
version = "0.16.0"
version = "0.16.1"
description = "Redux implementation for Python"
authors = ["Sassan Haradji <sassanh@gmail.com>"]
license = "Apache-2.0"
Expand All @@ -14,14 +14,16 @@ packages = [{ include = "redux" }, { include = "redux_pytest" }]
python = "^3.11"
python-immutable = "^1.1.1"
python-strtobool = "^1.0.0"
pyright = "^1.1.378"
ruff = "^0.6.3"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.4"
pyright = "^1.1.376"
ruff = "^0.5.7"
ruff = "^0.6.0"
pytest = "^8.1.1"
pytest-cov = "^4.1.0"
pytest-timeout = "^2.3.1"
Expand Down
2 changes: 1 addition & 1 deletion redux/serialization_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _serialize_dataclass_to_dict(
cls: type[SerializationMixin],
obj: Immutable,
) -> dict[str, Any]:
result = {}
result: dict[str, object] = {'_type': obj.__class__.__name__}
for field in dataclasses.fields(obj):
value = cls.serialize_value(getattr(obj, field.name))
result[field.name] = value
Expand Down
2 changes: 1 addition & 1 deletion redux_pytest/fixtures/event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_task(self: LoopThread, coro: Coroutine) -> None:
self.loop.call_soon_threadsafe(self.loop.create_task, coro)


@pytest.fixture()
@pytest.fixture
def event_loop() -> LoopThread:
loop_thread = LoopThread()
loop_thread.start()
Expand Down
2 changes: 1 addition & 1 deletion redux_pytest/fixtures/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def monitor(self: StoreMonitor, store: Store) -> None:
self.store.register_event_middleware(self._event_middleware)


@pytest.fixture()
@pytest.fixture
def store_monitor(store: Store, mocker: MockerFixture) -> StoreMonitor:
"""Fixture to check if an action was dispatched."""
monitor = StoreMonitor(mocker)
Expand Down
4 changes: 2 additions & 2 deletions redux_pytest/fixtures/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ def close(self: StoreSnapshot[State]) -> None:
assert not json_path.exists(), f'Snapshot {filename} not taken'


@pytest.fixture()
@pytest.fixture
def snapshot_prefix() -> str | None:
"""Return the prefix for the snapshots."""
return None


@pytest.fixture()
@pytest.fixture
def store_snapshot(
request: SubRequest,
store: Store,
Expand Down
6 changes: 3 additions & 3 deletions redux_pytest/fixtures/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from redux.main import Store


@pytest.fixture()
def store() -> Store: # noqa: PT004 # pragma: no cover
@pytest.fixture
def store() -> Store: # pragma: no cover
"""Provide current store (this is a placeholder returning None)."""
msg = 'This fixture should be overridden.'
raise NotImplementedError(msg)


@pytest.fixture()
@pytest.fixture
def needs_finish(store: Store) -> Generator:
"""Dispatch a finish action after the test."""
yield None
Expand Down
2 changes: 1 addition & 1 deletion redux_pytest/fixtures/wait_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def wrapper(*args: WaitForArgs.args, **kwargs: WaitForArgs.kwargs) -> None:
return decorator(check) if check else decorator


@pytest.fixture()
@pytest.fixture
def wait_for() -> Generator[WaitFor, None, None]:
"""Provide `wait_for` decorator."""
context = WaitFor()
Expand Down
1 change: 1 addition & 0 deletions tests/results/test_autorun/callability/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-000
{
"_type": "StateType",
"value": 0
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/callability/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-001
{
"_type": "StateType",
"value": 1
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/callability/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-002
{
"_type": "StateType",
"value": 3
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/callability/store-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-003
{
"_type": "StateType",
"value": 4
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/general/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-000
{
"_type": "StateType",
"value": 0
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/general/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-001
{
"_type": "StateType",
"value": 1
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/general/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-002
{
"_type": "StateType",
"value": 3
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/general/store-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-003
{
"_type": "StateType",
"value": 4
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/subscription/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-000
{
"_type": "StateType",
"value": 0
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/subscription/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-001
{
"_type": "StateType",
"value": 1
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/subscription/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-002
{
"_type": "StateType",
"value": 3
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/subscription/store-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-003
{
"_type": "StateType",
"value": 4
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/value_property/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-000
{
"_type": "StateType",
"value": 0
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/value_property/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-001
{
"_type": "StateType",
"value": 1
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/value_property/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-002
{
"_type": "StateType",
"value": 3
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/value_property/store-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-003
{
"_type": "StateType",
"value": 4
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/with_comparator/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-000
{
"_type": "StateType",
"value": 0
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/with_comparator/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-001
{
"_type": "StateType",
"value": 1
}
1 change: 1 addition & 0 deletions tests/results/test_autorun/with_comparator/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// store-002
{
"_type": "StateType",
"value": 4
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-000
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 10
},
"straight": {
"_type": "CountStateType",
"count": 0
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-001
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 11
},
"straight": {
"_type": "CountStateType",
"count": 1
}
}
4 changes: 4 additions & 0 deletions tests/results/test_features/general/store-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// store-002
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 12
},
"inverse": {
"_type": "CountStateType",
"count": -1
},
"straight": {
"_type": "CountStateType",
"count": 2
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-003
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 12
},
"inverse": {
"_type": "CountStateType",
"count": -1
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-004.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-004
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 10
},
"inverse": {
"_type": "CountStateType",
"count": 1
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-005.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-005
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 8
},
"inverse": {
"_type": "CountStateType",
"count": 3
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-autorun-000.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-autorun-000
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 10
},
"straight": {
"_type": "CountStateType",
"count": 0
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-autorun-001.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-autorun-001
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 11
},
"straight": {
"_type": "CountStateType",
"count": 1
}
}
4 changes: 4 additions & 0 deletions tests/results/test_features/general/store-autorun-002.jsonc
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// store-autorun-002
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 12
},
"inverse": {
"_type": "CountStateType",
"count": -1
},
"straight": {
"_type": "CountStateType",
"count": 2
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-autorun-003.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-autorun-003
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 10
},
"inverse": {
"_type": "CountStateType",
"count": 1
}
}
3 changes: 3 additions & 0 deletions tests/results/test_features/general/store-autorun-004.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-autorun-004
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 8
},
"inverse": {
"_type": "CountStateType",
"count": 3
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// store-autorun_subscription-000
{
"_id": "e3e70682c2094cac629f6fbed82c07cd",
"_type": "StateType",
"base10": {
"_type": "CountStateType",
"count": 10
},
"straight": {
"_type": "CountStateType",
"count": 0
}
}
Loading

0 comments on commit 3708af6

Please sign in to comment.