add simple test that minified state names are unique

This commit is contained in:
Benedikt Bartscher 2024-07-25 23:14:07 +02:00 committed by Masen Furer
parent 51aef9fd22
commit 7bf15b4f44
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95
2 changed files with 18 additions and 1 deletions

View File

@ -286,7 +286,7 @@ def get_var_for_field(cls: Type[BaseState], f: ModelField):
# Keep track of all state instances to calculate minified state names
state_count = 0
state_count: int = 0
all_state_names: Set[str] = set()

View File

@ -0,0 +1,17 @@
from typing import Set
from reflex.state import all_state_names, next_minified_state_name
def test_next_minified_state_name():
"""Test that the next_minified_state_name function returns unique state names."""
current_state_count = len(all_state_names)
state_names: Set[str] = set()
gen: int = 10000
for _ in range(gen):
state_name = next_minified_state_name()
assert state_name not in state_names
state_names.add(state_name)
assert len(state_names) == gen
assert len(all_state_names) == current_state_count + gen