Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

121 lines
4.5 KiB

import unittest
import os
import inspect
import utils.file_tool as t
import utils.path_tool
import basic.program
import test.constants as T
import test.testtools
import pprint
import json
HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
TEST_FUNCTIONS = ["test_getFiles", "test_02getModTime", "test_pathTool", "test_encoding", "test_11readYml", "test_14readXml"]
TEST_FUNCTIONS = ["test_02getModTime"]
verbose = False
class MyTestCase(unittest.TestCase):
mymsg = ""
def test_02getModTime(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
filepath = "/etc/hosts"
result = utils.file_tool.getModTime(job, filepath)
print("result "+result)
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, job.conf.getPath("program") + "/utils", "^file_t.*.py", None)
self.assertEqual(len(r), 1)
cnttest += 3
r = t.getFiles(job.m, job, job.conf.getPath("program") + "/utils", "^file__.*.py", None)
self.assertEqual((len(r) == 0), True)
r = t.getFiles(job.m, job, job.conf.getPath("program") + "/utils", ".*_tool.py", None)
self.assertEqual((len(r) > 2), True)
cnttest += 3
r = t.getFilesRec(job.m, job, 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, job, os.path.join(DATA_PATH, "tdata", "encoded_iso8859.txt"))
self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, job, os.path.join(DATA_PATH, "tdata", "encoded_win1250.txt"))
self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, job, os.path.join(DATA_PATH, "tdata", "encoded_utf8.txt"))
self.assertEqual(res, "utf-8")
cnttest += 3
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_11readYml(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pathname = os.path.join(T.COMP_PATH, "testrest", "mapping-rest.yml")
res = utils.file_tool.readFileDict(job, pathname, job.m)
print(res)
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "rest-message.xml")
utils.file_tool.writeFileDict(job.m, job, pathname, res)
def test_14readXml(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder.xml")
res = utils.file_tool.readFileDict(job, pathname, job.m)
res = dict(res)
print(res)
self.assertIn("shiporder", res)
self.assertIn("@orderid", res["shiporder"])
for x in res["shiporder"]:
print(x+" "+str(type(res["shiporder"][x])))
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder-res.yml")
utils.file_tool.writeFileDict(job.m, job, pathname, res)
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
verbose = True
unittest.main()