Browse Source

further refactoring tests

master
Ulrich Carmesin 2 years ago
parent
commit
cfcff71d1c
  1. 22
      test/test_compare.py
  2. 164
      test/test_tdata.py

22
test/test_compare.py

@ -7,7 +7,7 @@ import basic.constants as B
import utils.data_const as D import utils.data_const as D
import utils.match_tool import utils.match_tool
import utils.match_const as M import utils.match_const as M
import components.component import basic.component
tdata = { tdata = {
M.MATCH_SIDE_POSTEXPECT: { M.MATCH_SIDE_POSTEXPECT: {
@ -69,8 +69,8 @@ conf = {
"scheme": { "scheme": {
"table": { "table": {
"id": { D.DDL_FNAME: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3" }, "id": { D.DDL_FNAME: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3" },
"name": { D.DDL_FNAME: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:1" }, "name": { D.DDL_FNAME: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: M.SIM_BUSINESS+":1" },
"year": { D.DDL_FNAME: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:2" }, "year": { D.DDL_FNAME: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: M.SIM_BUSINESS+":2" },
"position": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" }, "position": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" },
"hobby": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" }, "hobby": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" },
"_header": ["id", "name", "year", "position", "hobby"] "_header": ["id", "name", "year", "position", "hobby"]
@ -93,7 +93,7 @@ class MyTestCase(unittest.TestCase):
def test_matchstart(self): def test_matchstart(self):
job = Job("unit") job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = components.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.conf = conf comp.conf = conf
comp.name = "component" comp.name = "component"
@ -102,7 +102,7 @@ class MyTestCase(unittest.TestCase):
print(matching.htmltext) print(matching.htmltext)
def test_hitmanage(self): def test_hitmanage(self):
comp = components.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
@ -127,7 +127,7 @@ class MyTestCase(unittest.TestCase):
def test_bestfit(self): def test_bestfit(self):
job = Job("unit") job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = components.component.Component() comp = basic.component.Component()
comp.name = "component" comp.name = "component"
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.conf = conf comp.conf = conf
@ -147,7 +147,7 @@ class MyTestCase(unittest.TestCase):
def test_compareRow(self): def test_compareRow(self):
job = Job("unit") job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = components.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
@ -167,7 +167,7 @@ class MyTestCase(unittest.TestCase):
def test_compareRows(self): def test_compareRows(self):
job = Job("unit") job = Job("unit")
comp = components.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
@ -186,11 +186,11 @@ class MyTestCase(unittest.TestCase):
job = Job("unit") job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31") setattr(job.par, "tctime", "2022-03-25_19-25-31")
comp = components.component.Component() comp = basic.component.Component()
comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
basic.componentHandling.comps["component"] = comp cm.comps["component"] = comp
# tdata["postReq"] = tdata["preAct"] # tdata["postReq"] = tdata["preAct"]
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(comp)
@ -206,7 +206,7 @@ class MyTestCase(unittest.TestCase):
job = Job("unit") job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31") setattr(job.par, "tctime", "2022-03-25_19-25-31")
comp = components.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf

164
test/test_tdata.py

@ -1,38 +1,53 @@
import unittest import unittest
import inspect
import utils.tdata_tool as t import utils.tdata_tool as t
import basic.constants as B import basic.constants as B
import utils.data_const as D import utils.data_const as D
import test.testtools
import test.constants
import basic.program import basic.program
import os import os
class MyTestCase(unittest.TestCase): HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern"]
#TEST_FUNCTIONS = ["test_getCsvSpec_key"]
def runTest(self): class MyTestCase(unittest.TestCase):
self.test_tdata() mymsg = "--------------------------------------------------------------"
def xtest_tdata(self): def test_tdata(self):
job = basic.program.Job("unit") global mymsg
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", actfunction = str(inspect.currentframe().f_code.co_name)
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", cnttest = 0
"modus": "unit"} if actfunction not in TEST_FUNCTIONS:
job.par.setParameterArgs(args) return
job = test.testtools.getJob()
setattr(job.par, "tdtyp", "dir")
setattr(job.par, "tdsrc", "TC0001")
setattr(job.par, "tdname", "testspec")
filename = str(job.conf.confs["paths"]["testdata"]) + "/" + getattr(job.par, "tdsrc") + "/" + getattr(job.par, "tdname") + ".csv" filename = str(job.conf.confs["paths"]["testdata"]) + "/" + getattr(job.par, "tdsrc") + "/" + getattr(job.par, "tdname") + ".csv"
tdata = t.readCsv(job.m, filename, None) #tdata = t.readCsv(job.m, filename, None)
self.assertEqual(len(tdata["testa1"]), 3) #self.assertEqual(len(tdata["testa1"]), 3)
setattr(job.par, "tdtyp", "dir") setattr(job.par, "tdtyp", "dir")
setattr(job.par, "tdsrc", "TST001") setattr(job.par, "tdsrc", "TST001")
tdata = t.getTestdata() #tdata = t.getTestdata()
self.assertEqual(("steps" in tdata), True) #self.assertEqual(("steps" in tdata), True)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_data(self): def test_getCsvSpec_data(self):
job = basic.program.Job("unit") global mymsg
tdata = {} actfunction = str(inspect.currentframe().f_code.co_name)
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", cnttest = 0
"tdtyp": "csv", "tdsrc": "TC0001", "tdname": "testspec", if actfunction not in TEST_FUNCTIONS:
"modus": "unit"} return
job.par.setParameterArgs(args) job = test.testtools.getJob()
filename = os.path.join(job.conf.confs["paths"]["testdata"], getattr(job.par, "tdsrc"), getattr(job.par, "tdname") + ".csv") # filename = os.path.join(job.conf.confs["paths"]["testdata"], getattr(job.par, "tdsrc"), getattr(job.par, "tdname") + ".csv")
""" """
a) data : like a table with data-array of key-value-pairs a) data : like a table with data-array of key-value-pairs
a_0 is keyword [option, step, CSV_HEADER_START ] a_0 is keyword [option, step, CSV_HEADER_START ]
@ -47,6 +62,7 @@ class MyTestCase(unittest.TestCase):
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA)
self.assertEqual(0, len(tdata)) self.assertEqual(0, len(tdata))
cnttest += 1
if "malformated" in tests: if "malformated" in tests:
malformat = "option;arg;;;;;" malformat = "option;arg;;;;;"
specLines = [ specLines = [
@ -56,6 +72,7 @@ class MyTestCase(unittest.TestCase):
"#;;;;;;" "#;;;;;;"
] ]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA)) self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA))
cnttest += 1
malformat = "step;component;1;arg:val;;;;;" malformat = "step;component;1;arg:val;;;;;"
specLines = [ specLines = [
"step:1;component;1;arg:val;;;", "step:1;component;1;arg:val;;;",
@ -69,6 +86,7 @@ class MyTestCase(unittest.TestCase):
malformat malformat
] ]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA)) self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA))
cnttest += 1
specLines = [ specLines = [
"option:par;arg;;;;;", "option:par;arg;;;;;",
"#option:nopar;arg;;;;;", "#option:nopar;arg;;;;;",
@ -83,6 +101,7 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
print(tdata) print(tdata)
self.assertIn(D.CSV_BLOCK_OPTION, tdata) self.assertIn(D.CSV_BLOCK_OPTION, tdata)
cnttest += 2
if D.CSV_BLOCK_STEP in tests: if D.CSV_BLOCK_STEP in tests:
specLines = [ specLines = [
"step:1;testa;1;table:_lofts,action:import;;;;;", "step:1;testa;1;table:_lofts,action:import;;;;;",
@ -93,11 +112,13 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertIn(B.DATA_NODE_STEPS, tdata) self.assertIn(B.DATA_NODE_STEPS, tdata)
self.assertIsInstance(tdata[B.DATA_NODE_STEPS], list) self.assertIsInstance(tdata[B.DATA_NODE_STEPS], list)
cnttest += 3
for step in tdata[B.DATA_NODE_STEPS]: for step in tdata[B.DATA_NODE_STEPS]:
print(step) print(step)
self.assertIn(B.DATA_NODE_COMP, step) self.assertIn(B.DATA_NODE_COMP, step)
self.assertIn(B.ATTR_DATA_REF, step) self.assertIn(B.ATTR_DATA_REF, step)
self.assertIn(B.ATTR_STEP_ARGS, step) self.assertIn(B.ATTR_STEP_ARGS, step)
cnttest += 3
if B.DATA_NODE_TABLES in tests: if B.DATA_NODE_TABLES in tests:
specLines = [ specLines = [
"table:testa:lofts;_nr;street;city;zip;state;beds;baths;sqft;type;price;latitude;longitude", "table:testa:lofts;_nr;street;city;zip;state;beds;baths;sqft;type;price;latitude;longitude",
@ -109,48 +130,101 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertIn(B.DATA_NODE_TABLES, tdata) self.assertIn(B.DATA_NODE_TABLES, tdata)
self.assertIsInstance(tdata[B.DATA_NODE_TABLES], dict) self.assertIsInstance(tdata[B.DATA_NODE_TABLES], dict)
cnttest += 3
for k in tdata[B.DATA_NODE_TABLES]["testa"]: for k in tdata[B.DATA_NODE_TABLES]["testa"]:
table = tdata[B.DATA_NODE_TABLES]["testa"][k] table = tdata[B.DATA_NODE_TABLES]["testa"][k]
self.assertIn(B.DATA_NODE_HEADER, table) self.assertIn(B.DATA_NODE_HEADER, table)
self.assertIn(B.DATA_NODE_DATA, table) self.assertIn(B.DATA_NODE_DATA, table)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def xtest_getCsvSpec_tree(self): def test_getCsvSpec_tree(self):
job = basic.program.Job("unit") global mymsg
tdata = {} actfunction = str(inspect.currentframe().f_code.co_name)
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", cnttest = 0
"tdtyp": "csv", "tdsrc": "TC0001", "tdname": "testspec", if actfunction not in TEST_FUNCTIONS:
"modus": "unit"} return
job.par.setParameterArgs(args) job = test.testtools.getJob()
"""" """"
b) tree : as a tree - the rows must be unique identified by the first column b) tree : as a tree - the rows must be unique identified by the first column
a_0 is keyword in CSV_HEADER_START a_0 is keyword in CSV_HEADER_START
a_0 : { .. a_n : { _header : [ fields.. ], _data : { field : value } a_0 : { .. a_n : { _header : [ fields.. ], _data : { field : value }
""" """
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def xtest_getCsvSpec_key(self): def test_getCsvSpec_key(self):
job = basic.program.Job("unit") global mymsg
tdata = {} actfunction = str(inspect.currentframe().f_code.co_name)
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", cnttest = 0
"tdtyp": "csv", "tdsrc": "TC0001", "tdname": "testspec", if actfunction not in TEST_FUNCTIONS:
"modus": "unit"} return
job.par.setParameterArgs(args) job = test.testtools.getJob()
"""" """"
c) keys : as a tree - the rows must be unique identified by the first column c) keys : as a tree - the rows must be unique identified by the first column
a_0 is keyword in CSV_HEADER_START a_0 is keyword in CSV_HEADER_START
a_1 ... a_n is key characterized by header-field like _fk* or _pk* a_1 ... a_n is key characterized by header-field like _fk* or _pk*
a_0 : { .. a_n : { _keys : [ _fpk*.. ] , _header : [ fields.. ], _data : { pk_0 : { ... pk_n : { field : value } a_0 : { .. a_n : { _keys : [ _fpk*.. ] , _header : [ fields.. ], _data : { pk_0 : { ... pk_n : { field : value }
""" """
tests = ["malformated", "comments", B.DATA_NODE_TABLES]
if "comments" in tests:
specLines = [
";;;;;;",
"#;;;;;;"
]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS)
self.assertEqual(0, len(tdata))
cnttest += 1
if "malformated" in tests:
malformat = "table;key;;;;;"
specLines = [
malformat,
"#;;;;;;"
]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_KEYS))
cnttest += 1
if B.DATA_NODE_TABLES in tests:
specLines = [
"table:capital;key;val;;;;",
";athens;;;;;",
";berlin;;;;;",
";cairo;;;;;"
]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS)
print(str(tdata))
self.assertEqual(1, len(tdata))
self.assertEqual(1, len(tdata["_tables"]))
self.assertEqual(2, len(tdata["_tables"]["capital"]))
self.assertEqual(3, len(tdata["_tables"]["capital"]["_keys"]))
cnttest += 4
specLines = [
"table:capital;key;val;;;;",
";athens;;;;;",
";berlin;;;;;",
"table:country;key;val;;;;",
";greece;;;;;",
";germany;;;;;"
]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS)
#tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_TREE)
print(str(tdata))
self.assertEqual(1, len(tdata))
self.assertNotIn("capital", tdata["_tables"])
self.assertEqual(1, len(tdata["_tables"]))
self.assertEqual(2, len(tdata["_tables"]["country"]))
self.assertEqual(2, len(tdata["_tables"]["country"]["_keys"]))
cnttest += 4
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def xtest_getCsvSpec_conf(self): def test_getCsvSpec_conf(self):
job = basic.program.Job("unit") global mymsg
tdata = {} actfunction = str(inspect.currentframe().f_code.co_name)
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", cnttest = 0
"tdtyp": "csv", "tdsrc": "TC0001", "tdname": "testspec", if actfunction not in TEST_FUNCTIONS:
"modus": "unit"} return
job.par.setParameterArgs(args) job = test.testtools.getJob()
"""" """"
d) conf: d) conf:
_header : [ field_0, ... ] _header : [ field_0, ... ]
@ -167,10 +241,16 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertNotIn(B.DATA_NODE_TABLES, tdata) self.assertNotIn(B.DATA_NODE_TABLES, tdata)
self.assertIn("lofts", tdata) self.assertIn("lofts", tdata)
cnttest += 3
table = tdata["lofts"] table = tdata["lofts"]
self.assertIn(B.DATA_NODE_HEADER, table) self.assertIn(B.DATA_NODE_HEADER, table)
self.assertIn(B.DATA_NODE_DATA, table) self.assertNotIn(B.DATA_NODE_DATA, table)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save