MCPcopy Index your code
hub / github.com/reflex-dev/reflex / test_get_value

Function test_get_value

tests/units/test_state.py:4516–4544  ·  view source on GitHub ↗

Test the get_value method directly with various key types. Args: key_factory: Factory function to create the key for testing. expected_result: The expected return value from get_value. should_raise: Whether the test should expect a TypeError.

(key_factory, expected_result, should_raise)

Source from the content-addressed store, hash-verified

4514 ],
4515)
4516def test_get_value(key_factory, expected_result, should_raise):
4517 """Test the get_value method directly with various key types.
4518
4519 Args:
4520 key_factory: Factory function to create the key for testing.
4521 expected_result: The expected return value from get_value.
4522 should_raise: Whether the test should expect a TypeError.
4523 """
4524
4525 class GetValueState(rx.State):
4526 """Test state class for get_value testing."""
4527
4528 foo: str = "FOO"
4529 bar: str = "BAR"
4530
4531 state = GetValueState()
4532 key = key_factory(state)
4533
4534 if should_raise:
4535 with pytest.raises(TypeError, match="Invalid key type"):
4536 state.get_value(key)
4537 else:
4538 result = state.get_value(key)
4539 assert result == expected_result
4540
4541 # Verify dirty state is not affected
4542 initial_dirty_vars = copy.copy(state.dirty_vars)
4543 state.get_value(key)
4544 assert state.dirty_vars == initial_dirty_vars
4545
4546
4547def test_init_mixin() -> None:

Callers

nothing calls this directly

Calls 3

GetValueStateClass · 0.85
get_valueMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected