test_url_cmp_and_hash.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from yarl import URL
  2. # comparison and hashing
  3. def test_ne_str():
  4. url = URL("http://example.com/")
  5. assert url != "http://example.com/"
  6. def test_eq():
  7. url = URL("http://example.com/")
  8. assert url == URL("http://example.com/")
  9. def test_hash():
  10. assert hash(URL("http://example.com/")) == hash(URL("http://example.com/"))
  11. def test_hash_double_call():
  12. url = URL("http://example.com/")
  13. assert hash(url) == hash(url)
  14. def test_le_less():
  15. url1 = URL("http://example1.com/")
  16. url2 = URL("http://example2.com/")
  17. assert url1 <= url2
  18. def test_le_eq():
  19. url1 = URL("http://example.com/")
  20. url2 = URL("http://example.com/")
  21. assert url1 <= url2
  22. def test_le_not_implemented():
  23. url = URL("http://example1.com/")
  24. assert url.__le__(123) is NotImplemented
  25. def test_lt():
  26. url1 = URL("http://example1.com/")
  27. url2 = URL("http://example2.com/")
  28. assert url1 < url2
  29. def test_lt_not_implemented():
  30. url = URL("http://example1.com/")
  31. assert url.__lt__(123) is NotImplemented
  32. def test_ge_more():
  33. url1 = URL("http://example1.com/")
  34. url2 = URL("http://example2.com/")
  35. assert url2 >= url1
  36. def test_ge_eq():
  37. url1 = URL("http://example.com/")
  38. url2 = URL("http://example.com/")
  39. assert url2 >= url1
  40. def test_ge_not_implemented():
  41. url = URL("http://example1.com/")
  42. assert url.__ge__(123) is NotImplemented
  43. def test_gt():
  44. url1 = URL("http://example1.com/")
  45. url2 = URL("http://example2.com/")
  46. assert url2 > url1
  47. def test_gt_not_implemented():
  48. url = URL("http://example1.com/")
  49. assert url.__gt__(123) is NotImplemented