From 9ee9566640ddb38f835d2424d140780172bc8cf9 Mon Sep 17 00:00:00 2001 From: Ricardo Martincoski Date: Fri, 16 Nov 2018 01:57:27 -0200 Subject: 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 Signed-off-by: Thomas Petazzoni --- .../testing/tests/package/sample_python_constantly.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 support/testing/tests/package/sample_python_constantly.py (limited to 'support/testing/tests/package/sample_python_constantly.py') diff --git a/support/testing/tests/package/sample_python_constantly.py b/support/testing/tests/package/sample_python_constantly.py new file mode 100644 index 0000000000..570cf85b23 --- /dev/null +++ b/support/testing/tests/package/sample_python_constantly.py @@ -0,0 +1,19 @@ +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) -- cgit v1.2.3