""" unit-test """ import unittest import inspect import utils.gen_tool import utils.gen_const as G import basic.program import test.testtools # the list of TEST_FUNCTIONS defines which function will be really tested. # if you minimize the list you can check the specific test-function TEST_FUNCTIONS = ["test_11getValueList", "test_12getCntElement", "test_13getMinCount", "test_14getElemList"] TEST_FUNCTIONS = ["test_01getElemList"] # with this variable you can switch prints on and off verbose = False class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" def test_01getElemList(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() res = utils.gen_tool.getElemList(G.KEY_LIST, "0 .. 5", 6, job) print((str(res))) res = utils.gen_tool.getElemList(G.KEY_LIST, "a, b, c, d", 6, job) print((str(res))) res = utils.gen_tool.getElemList(G.KEY_LIST, "cat:countries", 6, job) print((str(res))) def test_11getValueList(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() for cnt in [3, 4, 6, 10]: res = utils.gen_tool.getValueList(["A", "B", "C", "D"], cnt, job) self.assertEqual(len(res), cnt) cnttest += 1 for cnt in [3, 4, 6, 10]: res = utils.gen_tool.getValueList("[A, B, C, D]", cnt, job) self.assertEqual(len(res), cnt) cnttest += 1 for cnt in [3, 4, 6, 10]: res = utils.gen_tool.getValueList("0 .. 4", cnt, job) self.assertEqual(len(res), cnt) cnttest += 1 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_12getCntElement(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() def test_13getMinCount(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() def test_14getElemList(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() def test_zzz(self): if verbose: print(MyTestCase.mymsg) if __name__ == '__main__': verbose = True unittest.main()