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.
 
 
 

186 lines
7.8 KiB

import json
import unittest
from basic.program import Job
import utils.match_tool
import utils.match_tool as M
import components.component
tdata = {
M.MATCH_SIDE_POSTEXPECT: {
"path": "",
"data": {
"database": {
"scheme": {
"table": {
"_data": []
}
}
}
}
},
M.MATCH_SIDE_PREACTUAL: {
"path": "",
"data": {
"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"}
]
}
}
}
}
},
M.MATCH_SIDE_POSTACTUAL: {
"path": "",
"data": {
"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_SUCCESS)
print(matching.htmltext)
def xtest_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 xtest_similarity(self):
matching = self.getMatching()
utils.match_tool.getSimilarity(matching, ":database:scheme:table:_data",
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0],1)
def xtest_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[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["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 xtest_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[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["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[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"][i],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"][i])
print(text)
def xtest_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[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["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, M.MATCH_SUCCESS)
matching.difftext = ""
return matching
if __name__ == '__main__':
unittest.main()