import unittest, os import utils.file_tool as t import utils.path_tool import basic.program import test.constants HOME_PATH = test.constants.HOME_PATH class MyTestCase(unittest.TestCase): def runTest(self): self.test_encoding() self.test_getFiles() self.test_pathTool() def test_getFiles(self): job = basic.program.Job("unit") args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", "modus": "unit"} job.par.setParameterArgs(args) r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", "file_.*.py", None) self.assertEqual((len(r) == 1), True) r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", "file__.*.py", None) self.assertEqual((len(r) == 0), True) r = t.getFiles(job.m, job.conf.confs.get("paths").get("program") + "/utils", ".*_tool.py", None) self.assertEqual((len(r) > 2), True) r = t.getFilesRec(job.m, job.conf.confs.get("paths").get("program"), ".*?file.*.py") # print (r) def test_pathTool(self): job = basic.program.Job("unit") args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "job_tool", "modus": "unit"} job.par.setParameterArgs(args) #self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), # os.path.join(HOME_PATH, "components","testA","COFIG.yml")) def test_encoding(self): job = basic.program.Job("unit") print("------- test_encoding") encodings = ['utf-8', 'windows-1250', 'iso-8859-1'] res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_iso8859.txt")) self.assertEqual(res, "iso-8859-1") res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_win1250.txt")) self.assertEqual(res, "iso-8859-1") res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_utf8.txt")) self.assertEqual(res, "utf-8") if __name__ == '__main__': unittest.main()