conftest.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. """Test fixtures."""
  2. import platform
  3. from typing import Generator
  4. import pytest
  5. from pynecone.state import State
  6. @pytest.fixture(scope="function")
  7. def windows_platform() -> Generator:
  8. """Check if system is windows.
  9. Yields:
  10. whether system is windows.
  11. """
  12. yield platform.system() == "Windows"
  13. @pytest.fixture
  14. def list_mutation_state():
  15. """Create a state with list mutation features.
  16. Returns:
  17. A state with list mutation features.
  18. """
  19. class TestState(State):
  20. """The test state."""
  21. # plain list
  22. plain_friends = ["Tommy"]
  23. def make_friend(self):
  24. self.plain_friends.append("another-fd")
  25. def change_first_friend(self):
  26. self.plain_friends[0] = "Jenny"
  27. def unfriend_all_friends(self):
  28. self.plain_friends.clear()
  29. def unfriend_first_friend(self):
  30. del self.plain_friends[0]
  31. def remove_last_friend(self):
  32. self.plain_friends.pop()
  33. def make_friends_with_colleagues(self):
  34. colleagues = ["Peter", "Jimmy"]
  35. self.plain_friends.extend(colleagues)
  36. def remove_tommy(self):
  37. self.plain_friends.remove("Tommy")
  38. # list in dict
  39. friends_in_dict = {"Tommy": ["Jenny"]}
  40. def remove_jenny_from_tommy(self):
  41. self.friends_in_dict["Tommy"].remove("Jenny")
  42. def add_jimmy_to_tommy_friends(self):
  43. self.friends_in_dict["Tommy"].append("Jimmy")
  44. def tommy_has_no_fds(self):
  45. self.friends_in_dict["Tommy"].clear()
  46. # nested list
  47. friends_in_nested_list = [["Tommy"], ["Jenny"]]
  48. def remove_first_group(self):
  49. self.friends_in_nested_list.pop(0)
  50. def remove_first_person_from_first_group(self):
  51. self.friends_in_nested_list[0].pop(0)
  52. def add_jimmy_to_second_group(self):
  53. self.friends_in_nested_list[1].append("Jimmy")
  54. return TestState()
  55. @pytest.fixture
  56. def dict_mutation_state():
  57. """Create a state with dict mutation features.
  58. Returns:
  59. A state with dict mutation features.
  60. """
  61. class TestState(State):
  62. """The test state."""
  63. # plain dict
  64. details = {"name": "Tommy"}
  65. def add_age(self):
  66. self.details.update({"age": 20}) # type: ignore
  67. def change_name(self):
  68. self.details["name"] = "Jenny"
  69. def remove_last_detail(self):
  70. self.details.popitem()
  71. def clear_details(self):
  72. self.details.clear()
  73. def remove_name(self):
  74. del self.details["name"]
  75. def pop_out_age(self):
  76. self.details.pop("age")
  77. # dict in list
  78. address = [{"home": "home address"}, {"work": "work address"}]
  79. def remove_home_address(self):
  80. self.address[0].pop("home")
  81. def add_street_to_home_address(self):
  82. self.address[0]["street"] = "street address"
  83. # nested dict
  84. friend_in_nested_dict = {"name": "Nikhil", "friend": {"name": "Alek"}}
  85. def change_friend_name(self):
  86. self.friend_in_nested_dict["friend"]["name"] = "Tommy"
  87. def remove_friend(self):
  88. self.friend_in_nested_dict.pop("friend")
  89. def add_friend_age(self):
  90. self.friend_in_nested_dict["friend"]["age"] = 30
  91. return TestState()