gen_pickles.py 763 B

12345678910111213141516171819202122232425262728
  1. import pickle
  2. from importlib import import_module
  3. from pathlib import Path
  4. TESTS_DIR = Path(__file__).parent.resolve()
  5. def write(tag, cls, proto):
  6. d = cls([("a", 1), ("a", 2)])
  7. file_basename = f"{cls.__name__.lower()}-{tag}"
  8. with (TESTS_DIR / f"{file_basename}.pickle.{proto}").open("wb") as f:
  9. pickle.dump(d, f, proto)
  10. def generate():
  11. _impl_map = {
  12. "c-extension": "_multidict",
  13. "pure-python": "_multidict_py",
  14. }
  15. for proto in range(pickle.HIGHEST_PROTOCOL + 1):
  16. for tag, impl_name in _impl_map.items():
  17. impl = import_module(f"multidict.{impl_name}")
  18. for cls in impl.CIMultiDict, impl.MultiDict:
  19. write(tag, cls, proto)
  20. if __name__ == "__main__":
  21. generate()