test_version.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. from typing import Callable, Type
  2. import pytest
  3. from multidict import MultiMapping
  4. def test_getversion_bad_param(multidict_getversion_callable):
  5. with pytest.raises(TypeError):
  6. multidict_getversion_callable(1)
  7. def test_ctor(
  8. any_multidict_class: Type[MultiMapping[str]],
  9. multidict_getversion_callable: Callable,
  10. ) -> None:
  11. m1 = any_multidict_class()
  12. v1 = multidict_getversion_callable(m1)
  13. m2 = any_multidict_class()
  14. v2 = multidict_getversion_callable(m2)
  15. assert v1 != v2
  16. def test_add(
  17. any_multidict_class: Type[MultiMapping[str]],
  18. multidict_getversion_callable: Callable,
  19. ) -> None:
  20. m = any_multidict_class()
  21. v = multidict_getversion_callable(m)
  22. m.add("key", "val")
  23. assert multidict_getversion_callable(m) > v
  24. def test_delitem(
  25. any_multidict_class: Type[MultiMapping[str]],
  26. multidict_getversion_callable: Callable,
  27. ) -> None:
  28. m = any_multidict_class()
  29. m.add("key", "val")
  30. v = multidict_getversion_callable(m)
  31. del m["key"]
  32. assert multidict_getversion_callable(m) > v
  33. def test_delitem_not_found(
  34. any_multidict_class: Type[MultiMapping[str]],
  35. multidict_getversion_callable: Callable,
  36. ) -> None:
  37. m = any_multidict_class()
  38. m.add("key", "val")
  39. v = multidict_getversion_callable(m)
  40. with pytest.raises(KeyError):
  41. del m["notfound"]
  42. assert multidict_getversion_callable(m) == v
  43. def test_setitem(
  44. any_multidict_class: Type[MultiMapping[str]],
  45. multidict_getversion_callable: Callable,
  46. ) -> None:
  47. m = any_multidict_class()
  48. m.add("key", "val")
  49. v = multidict_getversion_callable(m)
  50. m["key"] = "val2"
  51. assert multidict_getversion_callable(m) > v
  52. def test_setitem_not_found(
  53. any_multidict_class: Type[MultiMapping[str]],
  54. multidict_getversion_callable: Callable,
  55. ) -> None:
  56. m = any_multidict_class()
  57. m.add("key", "val")
  58. v = multidict_getversion_callable(m)
  59. m["notfound"] = "val2"
  60. assert multidict_getversion_callable(m) > v
  61. def test_clear(
  62. any_multidict_class: Type[MultiMapping[str]],
  63. multidict_getversion_callable: Callable,
  64. ) -> None:
  65. m = any_multidict_class()
  66. m.add("key", "val")
  67. v = multidict_getversion_callable(m)
  68. m.clear()
  69. assert multidict_getversion_callable(m) > v
  70. def test_setdefault(
  71. any_multidict_class: Type[MultiMapping[str]],
  72. multidict_getversion_callable: Callable,
  73. ) -> None:
  74. m = any_multidict_class()
  75. m.add("key", "val")
  76. v = multidict_getversion_callable(m)
  77. m.setdefault("key2", "val2")
  78. assert multidict_getversion_callable(m) > v
  79. def test_popone(
  80. any_multidict_class: Type[MultiMapping[str]],
  81. multidict_getversion_callable: Callable,
  82. ) -> None:
  83. m = any_multidict_class()
  84. m.add("key", "val")
  85. v = multidict_getversion_callable(m)
  86. m.popone("key")
  87. assert multidict_getversion_callable(m) > v
  88. def test_popone_default(
  89. any_multidict_class: Type[MultiMapping[str]],
  90. multidict_getversion_callable: Callable,
  91. ) -> None:
  92. m = any_multidict_class()
  93. m.add("key", "val")
  94. v = multidict_getversion_callable(m)
  95. m.popone("key2", "default")
  96. assert multidict_getversion_callable(m) == v
  97. def test_popone_key_error(
  98. any_multidict_class: Type[MultiMapping[str]],
  99. multidict_getversion_callable: Callable,
  100. ) -> None:
  101. m = any_multidict_class()
  102. m.add("key", "val")
  103. v = multidict_getversion_callable(m)
  104. with pytest.raises(KeyError):
  105. m.popone("key2")
  106. assert multidict_getversion_callable(m) == v
  107. def test_pop(
  108. any_multidict_class: Type[MultiMapping[str]],
  109. multidict_getversion_callable: Callable,
  110. ) -> None:
  111. m = any_multidict_class()
  112. m.add("key", "val")
  113. v = multidict_getversion_callable(m)
  114. m.pop("key")
  115. assert multidict_getversion_callable(m) > v
  116. def test_pop_default(
  117. any_multidict_class: Type[MultiMapping[str]],
  118. multidict_getversion_callable: Callable,
  119. ) -> None:
  120. m = any_multidict_class()
  121. m.add("key", "val")
  122. v = multidict_getversion_callable(m)
  123. m.pop("key2", "default")
  124. assert multidict_getversion_callable(m) == v
  125. def test_pop_key_error(
  126. any_multidict_class: Type[MultiMapping[str]],
  127. multidict_getversion_callable: Callable,
  128. ) -> None:
  129. m = any_multidict_class()
  130. m.add("key", "val")
  131. v = multidict_getversion_callable(m)
  132. with pytest.raises(KeyError):
  133. m.pop("key2")
  134. assert multidict_getversion_callable(m) == v
  135. def test_popall(
  136. any_multidict_class: Type[MultiMapping[str]],
  137. multidict_getversion_callable: Callable,
  138. ) -> None:
  139. m = any_multidict_class()
  140. m.add("key", "val")
  141. v = multidict_getversion_callable(m)
  142. m.popall("key")
  143. assert multidict_getversion_callable(m) > v
  144. def test_popall_default(
  145. any_multidict_class: Type[MultiMapping[str]],
  146. multidict_getversion_callable: Callable,
  147. ) -> None:
  148. m = any_multidict_class()
  149. m.add("key", "val")
  150. v = multidict_getversion_callable(m)
  151. m.popall("key2", "default")
  152. assert multidict_getversion_callable(m) == v
  153. def test_popall_key_error(
  154. any_multidict_class: Type[MultiMapping[str]],
  155. multidict_getversion_callable: Callable,
  156. ) -> None:
  157. m = any_multidict_class()
  158. m.add("key", "val")
  159. v = multidict_getversion_callable(m)
  160. with pytest.raises(KeyError):
  161. m.popall("key2")
  162. assert multidict_getversion_callable(m) == v
  163. def test_popitem(
  164. any_multidict_class: Type[MultiMapping[str]],
  165. multidict_getversion_callable: Callable,
  166. ) -> None:
  167. m = any_multidict_class()
  168. m.add("key", "val")
  169. v = multidict_getversion_callable(m)
  170. m.popitem()
  171. assert multidict_getversion_callable(m) > v
  172. def test_popitem_key_error(
  173. any_multidict_class: Type[MultiMapping[str]],
  174. multidict_getversion_callable: Callable,
  175. ) -> None:
  176. m = any_multidict_class()
  177. v = multidict_getversion_callable(m)
  178. with pytest.raises(KeyError):
  179. m.popitem()
  180. assert multidict_getversion_callable(m) == v