field_test.py 686 B

123456789101112131415161718192021222324252627
  1. from pyrsistent._compat import Enum
  2. from pyrsistent import field, pvector_field
  3. # NB: This derives from the internal `pyrsistent._compat.Enum` in order to
  4. # simplify coverage across python versions. Since we use
  5. # `pyrsistent._compat.Enum` in `pyrsistent`'s implementation, it's useful to
  6. # use it in the test coverage as well, for consistency.
  7. class TestEnum(Enum):
  8. x = 1
  9. y = 2
  10. def test_enum():
  11. f = field(type=TestEnum)
  12. assert TestEnum in f.type
  13. assert len(f.type) == 1
  14. # This is meant to exercise `_seq_field`.
  15. def test_pvector_field_enum_type():
  16. f = pvector_field(TestEnum)
  17. assert len(f.type) == 1
  18. assert TestEnum is list(f.type)[0].__type__