sample_python_constantly.py 401 B

12345678910111213141516171819
  1. from constantly import ValueConstant, Values
  2. class RESULT(Values):
  3. OK = ValueConstant(0)
  4. FAIL = ValueConstant(-1)
  5. @classmethod
  6. def get(cls, rc):
  7. if rc == 0:
  8. return cls.OK
  9. else:
  10. return cls.FAIL
  11. print(list(RESULT.iterconstants()))
  12. assert RESULT.OK < RESULT.FAIL
  13. assert RESULT.OK.value > RESULT.FAIL.value
  14. assert RESULT.get(-5) == RESULT.FAIL