|
|
@ -2,41 +2,52 @@ import json |
|
|
|
import unittest |
|
|
|
from basic.program import Job |
|
|
|
import utils.match_tool |
|
|
|
import utils.match_tool as M |
|
|
|
import components.component |
|
|
|
|
|
|
|
tdata = { |
|
|
|
"postReq": { |
|
|
|
"database": { |
|
|
|
"scheme": { |
|
|
|
"table": { |
|
|
|
"_data": [] |
|
|
|
M.MATCH_SIDE_POSTEXPECT: { |
|
|
|
"path": "", |
|
|
|
"data": { |
|
|
|
"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"} |
|
|
|
] |
|
|
|
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"} |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
"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"} |
|
|
|
] |
|
|
|
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"} |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -62,12 +73,12 @@ conf = { |
|
|
|
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() |
|
|
|
#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") |
|
|
@ -75,10 +86,10 @@ class MyTestCase(unittest.TestCase): |
|
|
|
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.setData(tdata, utils.match_tool.MATCH_SUCCESS) |
|
|
|
print(matching.htmltext) |
|
|
|
|
|
|
|
def test_hitmanage(self): |
|
|
|
def xtest_hitmanage(self): |
|
|
|
comp = components.component.Component() |
|
|
|
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} |
|
|
|
comp.conf = conf |
|
|
@ -93,20 +104,20 @@ class MyTestCase(unittest.TestCase): |
|
|
|
self.assertEqual(matching.isHitB("b0005"), True, "doesnt exist") |
|
|
|
self.assertEqual(("b0005" in matching.linksB), True, "doesnt exist") |
|
|
|
|
|
|
|
def test_similarity(self): |
|
|
|
def xtest_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) |
|
|
|
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0], |
|
|
|
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0],1) |
|
|
|
|
|
|
|
def test_bestfit(self): |
|
|
|
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["preAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
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)) |
|
|
@ -116,30 +127,32 @@ class MyTestCase(unittest.TestCase): |
|
|
|
print(json.dumps(matching.linksB)) |
|
|
|
print(json.dumps(matching.nomatch)) |
|
|
|
|
|
|
|
def test_compareRow(self): |
|
|
|
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["preAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
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["preAct"]["database"]["scheme"]["table"]["_data"][i], tdata["postAct"]["database"]["scheme"]["table"]["_data"][i]) |
|
|
|
|
|
|
|
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 test_compareRows(self): |
|
|
|
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["preAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
matching.sideB = tdata["postAct"]["database"]["scheme"]["table"]["_data"] |
|
|
|
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") |
|
|
@ -165,7 +178,7 @@ class MyTestCase(unittest.TestCase): |
|
|
|
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.setData(tdata, M.MATCH_SUCCESS) |
|
|
|
matching.difftext = "" |
|
|
|
return matching |
|
|
|
|
|
|
|