-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathgen_pickles.py
32 lines (24 loc) · 939 Bytes
/
gen_pickles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pickle
from importlib import import_module
from pathlib import Path
from typing import Union
from multidict import CIMultiDict, MultiDict
TESTS_DIR = Path(__file__).parent.resolve()
_MD_Classes = Union[type[MultiDict[int]], type[CIMultiDict[int]]]
def write(tag: str, cls: _MD_Classes, proto: int) -> None:
d = cls([("a", 1), ("a", 2)])
file_basename = f"{cls.__name__.lower()}-{tag}"
with (TESTS_DIR / f"{file_basename}.pickle.{proto}").open("wb") as f:
pickle.dump(d, f, proto)
def generate() -> None:
_impl_map = {
"c-extension": "_multidict",
"pure-python": "_multidict_py",
}
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for tag, impl_name in _impl_map.items():
impl = import_module(f"multidict.{impl_name}")
for cls in impl.CIMultiDict, impl.MultiDict:
write(tag, cls, proto)
if __name__ == "__main__":
generate()