import unittest import os import inspect import utils.file_tool as t import utils.path_tool import basic.program import test.constants import test.testtools HOME_PATH = test.constants.HOME_PATH DATA_PATH = test.constants.DATA_PATH TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"] class MyTestCase(unittest.TestCase): mymsg = "" def test_getFiles(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_t.*.py", None) self.assertEqual(len(r), 1) cnttest += 3 r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file__.*.py", None) self.assertEqual((len(r) == 0), True) r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None) self.assertEqual((len(r) > 2), True) cnttest += 3 r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py") MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) def test_pathTool(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() #self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), # os.path.join(HOME_PATH, "components","testA","COFIG.yml")) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) def test_encoding(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() print("------- test_encoding") encodings = ['utf-8', 'windows-1250', 'iso-8859-1'] res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_iso8859.txt")) self.assertEqual(res, "iso-8859-1") res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_win1250.txt")) self.assertEqual(res, "iso-8859-1") res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_utf8.txt")) self.assertEqual(res, "utf-8") cnttest += 3 MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) def test_zzz(self): print(MyTestCase.mymsg) if __name__ == '__main__': unittest.main()