kumquat-buildroot/support/testing/tests/package/sample_python_constantly.py
Ricardo Martincoski 9ee9566640 support/testing: add python-constantly tests
Add a simple test case to check the basic usage by creating a class with
two constants.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2018-11-23 22:05:46 +01:00

20 lines
404 B
Python

from constantly import ValueConstant, Values
class RESULT(Values):
OK = ValueConstant(0)
FAIL = ValueConstant(-1)
@classmethod
def get(cls, rc):
if rc == 0:
return cls.OK
else:
return cls.FAIL
print(list(RESULT.iterconstants()))
assert(RESULT.OK < RESULT.FAIL)
assert(RESULT.OK.value > RESULT.FAIL.value)
assert(RESULT.get(-5) == RESULT.FAIL)