21 changed files with 553 additions and 239 deletions
			
			
		| @ -0,0 +1,173 @@ | |||
| import json | |||
| import unittest | |||
| from basic.program import Job | |||
| import utils.match_tool | |||
| import components.component | |||
| tdata = { | |||
|     "postReq": { | |||
|         "database": { | |||
|             "scheme": { | |||
|                 "table": { | |||
|                     "_data": [] | |||
|                 } | |||
|             } | |||
|         } | |||
|     }, | |||
|     "preAct": { | |||
|         "database": { | |||
|             "scheme": { | |||
|                 "table": { | |||
|                     "_data": [ | |||
|                         {"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"}, | |||
|                         {"id": 2, "name": "Meier", "year": 2015, "position": "first", "hobby": "reading" }, | |||
|                         {"id": 3, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"}, | |||
|                         {"id": 4, "name": "Smith", "year": 2019, "position": "third", "hobby": "executing"} | |||
|                     ] | |||
|                 } | |||
|             } | |||
|         } | |||
|     }, | |||
|     "postAct": { | |||
|         "database": { | |||
|             "scheme": { | |||
|                 "table": { | |||
|                     "_data": [ | |||
|                         {"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"}, | |||
|                         {"id": 2, "name": "Maier", "year": 2015, "position": "first", "hobby": "reading"}, | |||
|                         {"id": 4, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"}, | |||
|                         {"id": 3, "name": "Smith", "year": 2019, "position": "third", "hobby": "executing"} | |||
|                     ] | |||
|                 } | |||
|             } | |||
|         } | |||
|     } | |||
| } | |||
| conf = { | |||
|     "ddl": { | |||
|         "database": { | |||
|             "scheme": { | |||
|                 "table": { | |||
|                     "id": { "feld": "id", "type": "int", "acceptance": "ignore", "key": "T:3" }, | |||
|                     "name": { "feld": "name", "type": "string", "acceptance": "must", "key": "F:1" }, | |||
|                     "year": { "feld": "year", "type": "int", "acceptance": "must", "key": "F:2" }, | |||
|                     "position": { "feld": "id", "type": "string", "acceptance": "must", "key": "" }, | |||
|                     "hobby": { "feld": "id", "type": "string", "acceptance": "must", "key": "" }, | |||
|                     "_header": ["id", "name", "year", "position", "hobby"] | |||
|                 } | |||
|             } | |||
|         } | |||
|     } | |||
| } | |||
| 
 | |||
| class MyTestCase(unittest.TestCase): | |||
|     def runTest(self): | |||
|         self.test_matchstart() | |||
|         self.test_hitmanage() | |||
|         self.test_similarity() | |||
|         self.test_bestfit() | |||
|         self.test_compareRow() | |||
|         self.test_compareRows() | |||
|         self.test_match() | |||
| 
 | |||
|     def test_matchstart(self): | |||
|         job = Job("unit") | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = utils.match_tool.Matching(comp) | |||
|         matching.setData(tdata, utils.match_tool.MATCH_PREPOST) | |||
|         print(matching.htmltext) | |||
| 
 | |||
|     def test_hitmanage(self): | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = utils.match_tool.Matching(comp) | |||
|         matching.linksA = { "a0001": "null", "a0002": "null", "a0003": "null", "a0004": "null"} | |||
|         matching.linksB = { "b0001": "null", "b0002": "null", "b0003": "null", "b0004": "null"} | |||
|         self.assertEqual(matching.isHitA("a0001"), False, "with value null") | |||
|         self.assertEqual(matching.isHitB("b0005"), False, "doesnt exist") | |||
|         self.assertEqual(("b0005" not in matching.linksB), True, "doesnt exist") | |||
|         matching.setHit("a0001", "b0005") | |||
|         self.assertEqual(matching.isHitA("a0001"), True, "with value null") | |||
|         self.assertEqual(matching.isHitB("b0005"), True, "doesnt exist") | |||
|         self.assertEqual(("b0005" in matching.linksB), True, "doesnt exist") | |||
| 
 | |||
|     def test_similarity(self): | |||
|         matching = self.getMatching() | |||
|         utils.match_tool.getSimilarity(matching, ":database:scheme:table:_data", | |||
|             tdata["preAct"]["database"]["scheme"]["table"]["_data"][0], | |||
|             tdata["postAct"]["database"]["scheme"]["table"]["_data"][0],1) | |||
| 
 | |||
|     def test_bestfit(self): | |||
|         job = Job("unit") | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = utils.match_tool.Matching(comp) | |||
|         matching.sideA = tdata["preAct"]["database"]["scheme"]["table"]["_data"] | |||
|         matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] | |||
|         utils.match_tool.matchBestfit(matching, ":database:scheme:table:_data") | |||
|         print(json.dumps(matching.linksA)) | |||
|         print(json.dumps(matching.linksB)) | |||
|         print(json.dumps(matching.nomatch)) | |||
|         utils.match_tool.matchRestfit(matching) | |||
|         print(json.dumps(matching.linksA)) | |||
|         print(json.dumps(matching.linksB)) | |||
|         print(json.dumps(matching.nomatch)) | |||
| 
 | |||
|     def test_compareRow(self): | |||
|         job = Job("unit") | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = self.getMatching() | |||
|         matching.sideA = tdata["preAct"]["database"]["scheme"]["table"]["_data"] | |||
|         matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] | |||
|         ddl = conf["ddl"]["database"]["scheme"]["table"] | |||
|         header = [] | |||
|         for f in ddl["_header"]: | |||
|             header.append({"field": f, "type": ddl[f]["type"], "acceptance": ddl[f]["acceptance"]}) | |||
|         i = 1 | |||
|         text = utils.match_tool.compareRow(matching, header, tdata["preAct"]["database"]["scheme"]["table"]["_data"][i], tdata["postAct"]["database"]["scheme"]["table"]["_data"][i]) | |||
|         print(text) | |||
| 
 | |||
|     def test_compareRows(self): | |||
|         job = Job("unit") | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = self.getMatching() | |||
|         matching.sideA = tdata["preAct"]["database"]["scheme"]["table"]["_data"] | |||
|         matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] | |||
|         linksA = {"a0001": "b0001", "a0002": "b0002" } | |||
|         matching.linksA = linksA | |||
|         text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data") | |||
|         print(text) | |||
| 
 | |||
|     def test_match(self): | |||
|             job = Job("unit") | |||
|             comp = components.component.Component() | |||
|             comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|             # tdata["postReq"] = tdata["preAct"] | |||
|             comp.conf = conf | |||
|             matching = utils.match_tool.Matching(comp) | |||
|             matching.setData(tdata, utils.match_tool.MATCH_POSTCOND) | |||
|             text = utils.match_tool.matchTree(matching) | |||
|             print("\n-------------\n") | |||
|             print(text) | |||
|             print("\n-------------\n") | |||
|             print(matching.difftext) | |||
| 
 | |||
|     def getMatching(self): | |||
|         job = Job("unit") | |||
|         comp = components.component.Component() | |||
|         comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} | |||
|         comp.conf = conf | |||
|         matching = utils.match_tool.Matching(comp) | |||
|         matching.setData(tdata, utils.match_tool.MATCH_PREPOST) | |||
|         matching.difftext = "" | |||
|         return matching | |||
| 
 | |||
| if __name__ == '__main__': | |||
|     unittest.main() | |||
| @ -1,19 +0,0 @@ | |||
| import sys, os | |||
| import unittest | |||
| import basic.program | |||
| import utils.conn_tool | |||
| sys.path.append((0, os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib', 'python3.9', 'site-packages', 'mysql'))) | |||
| #import mysql.connector | |||
| import db_tool | |||
| 
 | |||
| class MyTestCase(unittest.TestCase): | |||
|     def test_something(self): | |||
|         job = basic.program.Job("unit") | |||
|         args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", "tool" : "job_tool"} | |||
|         job.par.setParameterArgs(args) | |||
|         print(sys.path) | |||
|         dbconn = db_tool.getConnector() | |||
|         print (dbconn) | |||
|         pass | |||
| if __name__ == '__main__': | |||
|     unittest.main() | |||
| @ -1,16 +0,0 @@ | |||
| import unittest, os | |||
| import utils.path_tool as path_tool | |||
| import basic.program as program | |||
| import test.constants | |||
| 
 | |||
| HOME_PATH = test.constants.HOME_PATH | |||
| 
 | |||
| class MyTestCase(unittest.TestCase): | |||
|     def test_pathTool(self): | |||
|         x = program.Job("test:application=TEST:application=ENV01") | |||
|         self.assertEqual(path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), | |||
|             os.path.join(HOME_PATH, "components","testA","CONFIG.yml")) | |||
| 
 | |||
| 
 | |||
| if __name__ == '__main__': | |||
|     unittest.main() | |||
| @ -1,72 +0,0 @@ | |||
| import unittest | |||
| #import basic.program | |||
| import utils.xml_tool | |||
| import utils.xml_tool | |||
| 
 | |||
| class MyTestCase(unittest.TestCase): | |||
|     def xtest_xmlTool(self): | |||
|         #job = basic.program.Job("unit") | |||
|         args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", | |||
|                 "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", | |||
|                 "modus": "unit"} | |||
|         beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}} | |||
|         tree = {} | |||
|         tree["root"] = args | |||
|         xml = utils.xml_tool.dict2xml(tree) | |||
|         print(xml) | |||
|         xml = utils.xml_tool.dict2xml(beispiel_json) | |||
|         print(xml) | |||
|         self.assertEqual(1, 1) | |||
|         f = utils.xml_tool.fcts() | |||
| 
 | |||
|     def xtest_addSingle(self): | |||
|         tree = {} | |||
|         # tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', 2, "abc") | |||
|         tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc") | |||
|         self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc") | |||
|         self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") | |||
| 
 | |||
|     def xtest_addTwo(self): | |||
|         # a-b-b | |||
|         # c-a-a c-a-b | |||
|         tree = {} | |||
|         print("--------------------------------------------------------------------------------") | |||
|         tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc") | |||
|         print("--------------------------------------------------------------------------------") | |||
|         tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="LAND"]/wert', 2, "xyz") | |||
|         baum = {} | |||
|         baum["root"] = tree | |||
|         print("<------"+str(baum["root"])) | |||
|         self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc") | |||
|         self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") | |||
|         self.assertEqual(tree["kratz"]["mm"][1]["wert"], "xyz") | |||
|         self.assertEqual(tree["kratz"]["mm"][1]["@name"], "LAND") | |||
| 
 | |||
|     def xtest_addOnePaths(self): | |||
|         tree = {} | |||
|         print("--------------------------------------------------------------------------------") | |||
|         tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") | |||
|         baum = {} | |||
|         baum["root"] = tree | |||
|         print("<------"+str(baum["root"])) | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["wert"], "abc") | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") | |||
| 
 | |||
|     def test_addTwoPaths(self): | |||
|         tree = {} | |||
|         print("--------------------------------------------------------------------------------") | |||
|         tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") | |||
|         print("--------------------------------------------------------------------------------") | |||
|         tree = utils.xml_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="LAND"]/wert', "xyz") | |||
|         baum = {} | |||
|         baum["root"] = tree | |||
|         print("<------"+str(baum["root"])) | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["wert"], "abc") | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") | |||
|         self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") | |||
| 
 | |||
| 
 | |||
| if __name__ == '__main__': | |||
|     unittest.main() | |||
| 
 | |||
					Loading…
					
					
				
		Reference in new issue