Skip to content

Commit

Permalink
Comment out pclist (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo committed Jan 31, 2023
1 parent 0e48ced commit e578956
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 132 deletions.
32 changes: 17 additions & 15 deletions pynecone/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _reassign_field(self, field_name: str):
Primarily for mutation in fields of mutable data types.
Args:
field_name (str): The name of the field we want to reassign
field_name: The name of the field we want to reassign
"""
setattr(
self,
Expand Down Expand Up @@ -287,9 +287,9 @@ def add_var(cls, name: str, type_: Any, default_value: Any = None):
defined statically in the model.
Args:
name (str): The name of the variable
type_ (Any): The type of the variable
default_value (Any): The default value of the variable
name: The name of the variable
type_: The type of the variable
default_value: The default value of the variable
Raises:
NameError: if a variable of this name already exists
Expand Down Expand Up @@ -688,17 +688,19 @@ def _convert_mutable_datatypes(
Returns:
The converted field_value
"""
if isinstance(field_value, list):
for index in range(len(field_value)):
field_value[index] = _convert_mutable_datatypes(
field_value[index], reassign_field, field_name
)

field_value = PCList(
field_value, reassign_field=reassign_field, field_name=field_name
)

elif isinstance(field_value, dict):
# TODO: The PCList class needs to be pickleable to work with Redis.
# We will uncomment this code once this is fixed.
# if isinstance(field_value, list):
# for index in range(len(field_value)):
# field_value[index] = _convert_mutable_datatypes(
# field_value[index], reassign_field, field_name
# )

# field_value = PCList(
# field_value, reassign_field=reassign_field, field_name=field_name
# )

if isinstance(field_value, dict):
for key, value in field_value.items():
field_value[key] = _convert_mutable_datatypes(
value, reassign_field, field_name
Expand Down
2 changes: 1 addition & 1 deletion pynecone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ def is_backend_variable(name: str) -> bool:
"""Check if this variable name correspond to a backend variable.
Args:
name (str): The name of the variable to check
name: The name of the variable to check
Returns:
bool: The result of the check
Expand Down
232 changes: 116 additions & 116 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,119 +222,119 @@ def add_jimmy_to_second_group(self):
return TestState()


@pytest.mark.asyncio
@pytest.mark.parametrize(
"event_tuples",
[
pytest.param(
[
(
"test_state.make_friend",
{"test_state": {"plain_friends": ["Tommy", "another-fd"]}},
),
(
"test_state.change_first_friend",
{"test_state": {"plain_friends": ["Jenny", "another-fd"]}},
),
],
id="append then __setitem__",
),
pytest.param(
[
(
"test_state.unfriend_first_friend",
{"test_state": {"plain_friends": []}},
),
(
"test_state.make_friend",
{"test_state": {"plain_friends": ["another-fd"]}},
),
],
id="delitem then append",
),
pytest.param(
[
(
"test_state.make_friends_with_colleagues",
{"test_state": {"plain_friends": ["Tommy", "Peter", "Jimmy"]}},
),
(
"test_state.remove_tommy",
{"test_state": {"plain_friends": ["Peter", "Jimmy"]}},
),
(
"test_state.remove_last_friend",
{"test_state": {"plain_friends": ["Peter"]}},
),
(
"test_state.unfriend_all_friends",
{"test_state": {"plain_friends": []}},
),
],
id="extend, remove, pop, clear",
),
pytest.param(
[
(
"test_state.add_jimmy_to_second_group",
{
"test_state": {
"friends_in_nested_list": [["Tommy"], ["Jenny", "Jimmy"]]
}
},
),
(
"test_state.remove_first_person_from_first_group",
{
"test_state": {
"friends_in_nested_list": [[], ["Jenny", "Jimmy"]]
}
},
),
(
"test_state.remove_first_group",
{"test_state": {"friends_in_nested_list": [["Jenny", "Jimmy"]]}},
),
],
id="nested list",
),
pytest.param(
[
(
"test_state.add_jimmy_to_tommy_friends",
{"test_state": {"friends_in_dict": {"Tommy": ["Jenny", "Jimmy"]}}},
),
(
"test_state.remove_jenny_from_tommy",
{"test_state": {"friends_in_dict": {"Tommy": ["Jimmy"]}}},
),
(
"test_state.tommy_has_no_fds",
{"test_state": {"friends_in_dict": {"Tommy": []}}},
),
],
id="list in dict",
),
],
)
async def test_list_mutation_detection__plain_list(
event_tuples: List[Tuple[str, List[str]]], list_mutation_state: State
):
"""Test list mutation detection
when reassignment is not explicitly included in the logic.
Args:
event_tuples: From parametrization.
list_mutation_state: A state with list mutation features.
"""
for event_name, expected_delta in event_tuples:
result = await list_mutation_state.process(
Event(
token="fake-token",
name=event_name,
router_data={"pathname": "/", "query": {}},
payload={},
)
)

assert result.delta == expected_delta
# @pytest.mark.asyncio
# @pytest.mark.parametrize(
# "event_tuples",
# [
# pytest.param(
# [
# (
# "test_state.make_friend",
# {"test_state": {"plain_friends": ["Tommy", "another-fd"]}},
# ),
# (
# "test_state.change_first_friend",
# {"test_state": {"plain_friends": ["Jenny", "another-fd"]}},
# ),
# ],
# id="append then __setitem__",
# ),
# pytest.param(
# [
# (
# "test_state.unfriend_first_friend",
# {"test_state": {"plain_friends": []}},
# ),
# (
# "test_state.make_friend",
# {"test_state": {"plain_friends": ["another-fd"]}},
# ),
# ],
# id="delitem then append",
# ),
# pytest.param(
# [
# (
# "test_state.make_friends_with_colleagues",
# {"test_state": {"plain_friends": ["Tommy", "Peter", "Jimmy"]}},
# ),
# (
# "test_state.remove_tommy",
# {"test_state": {"plain_friends": ["Peter", "Jimmy"]}},
# ),
# (
# "test_state.remove_last_friend",
# {"test_state": {"plain_friends": ["Peter"]}},
# ),
# (
# "test_state.unfriend_all_friends",
# {"test_state": {"plain_friends": []}},
# ),
# ],
# id="extend, remove, pop, clear",
# ),
# pytest.param(
# [
# (
# "test_state.add_jimmy_to_second_group",
# {
# "test_state": {
# "friends_in_nested_list": [["Tommy"], ["Jenny", "Jimmy"]]
# }
# },
# ),
# (
# "test_state.remove_first_person_from_first_group",
# {
# "test_state": {
# "friends_in_nested_list": [[], ["Jenny", "Jimmy"]]
# }
# },
# ),
# (
# "test_state.remove_first_group",
# {"test_state": {"friends_in_nested_list": [["Jenny", "Jimmy"]]}},
# ),
# ],
# id="nested list",
# ),
# pytest.param(
# [
# (
# "test_state.add_jimmy_to_tommy_friends",
# {"test_state": {"friends_in_dict": {"Tommy": ["Jenny", "Jimmy"]}}},
# ),
# (
# "test_state.remove_jenny_from_tommy",
# {"test_state": {"friends_in_dict": {"Tommy": ["Jimmy"]}}},
# ),
# (
# "test_state.tommy_has_no_fds",
# {"test_state": {"friends_in_dict": {"Tommy": []}}},
# ),
# ],
# id="list in dict",
# ),
# ],
# )
# async def test_list_mutation_detection__plain_list(
# event_tuples: List[Tuple[str, List[str]]], list_mutation_state: State
# ):
# """Test list mutation detection
# when reassignment is not explicitly included in the logic.

# Args:
# event_tuples: From parametrization.
# list_mutation_state: A state with list mutation features.
# """
# for event_name, expected_delta in event_tuples:
# result = await list_mutation_state.process(
# Event(
# token="fake-token",
# name=event_name,
# router_data={"pathname": "/", "query": {}},
# payload={},
# )
# )

# assert result.delta == expected_delta

0 comments on commit e578956

Please sign in to comment.