test_pickle.py 436 B

1234567891011121314151617181920212223
  1. import pickle
  2. from yarl import URL
  3. # serialize
  4. def test_pickle():
  5. u1 = URL("test")
  6. hash(u1)
  7. v = pickle.dumps(u1)
  8. u2 = pickle.loads(v)
  9. assert u1._cache
  10. assert not u2._cache
  11. assert hash(u1) == hash(u2)
  12. def test_default_style_state():
  13. u = URL("test")
  14. hash(u)
  15. u.__setstate__((None, {"_val": "test", "_strict": False, "_cache": {"hash": 1}}))
  16. assert not u._cache
  17. assert u._val == "test"