test_exceptions.py 934 B

12345678910111213141516171819202122232425262728293031323334
  1. import itertools
  2. import pytest
  3. from referencing import Resource, exceptions
  4. def pairs(choices):
  5. return itertools.combinations(choices, 2)
  6. TRUE = Resource.opaque(True)
  7. thunks = (
  8. lambda: exceptions.CannotDetermineSpecification(TRUE),
  9. lambda: exceptions.NoSuchResource("urn:example:foo"),
  10. lambda: exceptions.NoInternalID(TRUE),
  11. lambda: exceptions.InvalidAnchor(resource=TRUE, anchor="foo", ref="a#b"),
  12. lambda: exceptions.NoSuchAnchor(resource=TRUE, anchor="foo", ref="a#b"),
  13. lambda: exceptions.PointerToNowhere(resource=TRUE, ref="urn:example:foo"),
  14. lambda: exceptions.Unresolvable("urn:example:foo"),
  15. lambda: exceptions.Unretrievable("urn:example:foo"),
  16. )
  17. @pytest.mark.parametrize("one, two", pairs(each() for each in thunks))
  18. def test_eq_incompatible_types(one, two):
  19. assert one != two
  20. @pytest.mark.parametrize("thunk", thunks)
  21. def test_hash(thunk):
  22. assert thunk() in {thunk()}