-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test-snapshot): add prefix to snapshot fixture
- Loading branch information
Showing
12 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// store-000 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// store-001 | ||
3 |
2 changes: 2 additions & 0 deletions
2
tests/results/test_snapshot_fixture/prefix/store-custom_prefix-000.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// store-custom_prefix-000 | ||
0 |
2 changes: 2 additions & 0 deletions
2
tests/results/test_snapshot_fixture/prefix/store-custom_prefix-001.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// store-custom_prefix-001 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# ruff: noqa: D100, D101, D102, D103, D104, D107 | ||
from __future__ import annotations | ||
|
||
from immutable import Immutable | ||
|
||
from redux.basic_types import ( | ||
BaseAction, | ||
CreateStoreOptions, | ||
FinishAction, | ||
FinishEvent, | ||
) | ||
from redux.main import Store | ||
|
||
|
||
class StateType(Immutable): | ||
value: int | ||
|
||
|
||
StoreType = Store[StateType, BaseAction, FinishEvent] | ||
|
||
|
||
def test_snapshot() -> None: | ||
initial_state = StateType(value=0) | ||
|
||
store = Store( | ||
lambda state, __: state or initial_state, | ||
options=CreateStoreOptions(auto_init=True), | ||
) | ||
|
||
assert store.snapshot == {'value': 0} | ||
|
||
store.dispatch(FinishAction()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# ruff: noqa: D100, D101, D102, D103, D104, D107 | ||
from __future__ import annotations | ||
|
||
from dataclasses import replace | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
from immutable import Immutable | ||
|
||
from redux.basic_types import ( | ||
BaseAction, | ||
BaseEvent, | ||
CompleteReducerResult, | ||
CreateStoreOptions, | ||
FinishAction, | ||
FinishEvent, | ||
InitAction, | ||
InitializationActionError, | ||
) | ||
from redux.main import Store | ||
|
||
if TYPE_CHECKING: | ||
from redux_pytest.fixtures.snapshot import StoreSnapshot | ||
|
||
|
||
class StateType(Immutable): | ||
value: int | ||
|
||
|
||
class IncrementAction(BaseAction): ... | ||
|
||
|
||
class DummyEvent(BaseEvent): ... | ||
|
||
|
||
Action = IncrementAction | InitAction | FinishAction | ||
|
||
|
||
def reducer( | ||
state: StateType | None, | ||
action: Action, | ||
) -> StateType | CompleteReducerResult[StateType, Action, DummyEvent | FinishEvent]: | ||
if state is None: | ||
if isinstance(action, InitAction): | ||
return StateType(value=0) | ||
raise InitializationActionError(action) | ||
|
||
if isinstance(action, IncrementAction): | ||
return replace(state, value=state.value + 1) | ||
return state | ||
|
||
|
||
@pytest.fixture() | ||
def store() -> Store: | ||
return Store( | ||
reducer, | ||
options=CreateStoreOptions( | ||
auto_init=True, | ||
), | ||
) | ||
|
||
|
||
def test_monitor( | ||
store: Store, | ||
store_snapshot: StoreSnapshot[StateType], | ||
needs_finish: None, | ||
) -> None: | ||
_ = needs_finish | ||
store_snapshot.monitor(lambda state: state.value if state.value % 2 != 0 else None) | ||
store.dispatch(IncrementAction()) | ||
store.dispatch(IncrementAction()) | ||
store.dispatch(IncrementAction()) | ||
store.dispatch(IncrementAction()) | ||
|
||
|
||
class TestSnapshotPrefix: | ||
@pytest.fixture(scope='class') | ||
def snapshot_prefix(self: TestSnapshotPrefix) -> str: | ||
return 'custom_prefix' | ||
|
||
def test_prefix( | ||
self: TestSnapshotPrefix, | ||
store: Store, | ||
store_snapshot: StoreSnapshot[StateType], | ||
needs_finish: None, | ||
) -> None: | ||
_ = needs_finish | ||
store_snapshot.monitor(lambda state: state.value) | ||
store.dispatch(IncrementAction()) |