diff --git a/basic/catalog.py b/basic/catalog.py index 26c708c..3a02493 100644 --- a/basic/catalog.py +++ b/basic/catalog.py @@ -9,7 +9,9 @@ import basic.program import basic.constants as B import utils.path_const as P import utils.data_const as D +import utils.config_tool import utils.path_tool +import utils.file_tool import utils.tdata_tool EXP_KEY_MISSING = "key is missing {}" @@ -37,40 +39,66 @@ class Catalog: return Catalog.__instance - def getValue(self, domain, key): + def getValue(self, domain, key, job): """ this function gets the value of the domain an key :param domain: :param key: :return: """ - job = basic.program.Job.getInstance() - if not (isinstance(domain, str) and len(domain)): - raise Exception(EXP_KEY_MISSING, (domain, key)) - if not (isinstance(key, str) and len(key)): + if not (isinstance(domain, str) or len(domain) < 1): raise Exception(EXP_KEY_MISSING, (domain, key)) + if not (isinstance(key, str) or len(key) < 1): + job.m.setError(EXP_KEY_MISSING+" ("+domain+", "+key+")") + return "" if domain not in self.catalog: - self.readDomain(domain) - if key not in self.catalog[domain][key]: - raise Exception(EXP_KEY_DOESNT_EXIST, (domain, key)) + self.readDomain(domain, job) + if key not in self.catalog[domain]: + job.m.setError(EXP_KEY_DOESNT_EXIST+" ("+domain+", "+key+")") + return "" return self.catalog[domain][key] - def readDomain(self, domain): + def getKeys(self, domain, job): + """ + this function gets the value of the domain an key + :param domain: + :param key: + :return: + """ + if not (isinstance(domain, str) or len(domain) < 1): + raise Exception(EXP_KEY_MISSING, (domain)) + + if domain not in self.catalog: + self.readDomain(domain, job) + if domain not in self.catalog: + return [] + out = [] + for x in self.catalog[domain].keys(): + out.append(x) + return out + + + def readDomain(self, domain, job): """ this function reads the domain-entries :param domain: :return: """ - job = basic.program.Job.getInstance() - if not (isinstance(domain, str) and len(domain)): + if not (isinstance(domain, str) or len(domain) < 1): raise Exception(EXP_KEY_MISSING, (domain)) if domain in self.catalog: return - filename = utils.path_tool.rejoinPath(job.conf.getPath(P.ATTR_PATH_TDATA), "catalog", domain+".csv") - data = utils.tdata_tool.getCsvSpec(job.m, filename, D.CSV_SPECTYPE_KEYS) + pathname = utils.config_tool.getConfigPath(P.KEY_CATALOG, domain, job) + if pathname is None: + raise Exception(EXP_KEY_MISSING, (domain)) + if pathname[-4:] == ".csv": + data = utils.tdata_tool.getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_KEYS) + else: + data = utils.file_tool.readFileDict(pathname, job.m) self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS] + return data def exportXSD(self, domain): @@ -78,4 +106,4 @@ class Catalog: this function exports the domain into xsd-declaration of simple types :return: """ - pass \ No newline at end of file + pass diff --git a/test/test_02css.py b/test/test_02css.py index a081d4c..bd340b8 100644 --- a/test/test_02css.py +++ b/test/test_02css.py @@ -23,8 +23,6 @@ class MyTestCase(unittest.TestCase): "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "modus": "unit"} job.par.setParameterArgs(args) - if verbose: print("eeeeeeeee") - if verbose: print(json.dumps(job.conf.confs)) # ------- inline --------------- job.conf.setConfig("tools.csstyp", "inline") job.conf.confs.get("tools")["csstyp"] == "inline" diff --git a/test/test_07catalog.py b/test/test_07catalog.py index b34e9b6..f370718 100644 --- a/test/test_07catalog.py +++ b/test/test_07catalog.py @@ -2,6 +2,7 @@ import unittest import os import inspect import utils.path_tool +import basic.message import basic.program import basic.constants as B import test.constants @@ -13,9 +14,9 @@ HOME_PATH = test.constants.HOME_PATH OS_SYSTEM = test.constants.OS_SYSTEM # here you can select single testfunction for developping the tests -TEST_FUNCTIONS = ["test_01class", "test_02key"] -#TEST_FUNCTIONS = [ "test_02key"] -verbose = True +TEST_FUNCTIONS = ["test_01class", "test_02read", "test_03key"] +TEST_FUNCTIONS = [ "test_03key"] +verbose = False class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" @@ -29,16 +30,46 @@ class MyTestCase(unittest.TestCase): job = test.testtools.getJob() catalog = basic.catalog.Catalog.getInstance() self.assertIsNotNone(catalog) + cnttest += 1 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) - def test_02key(self): + def test_02read(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() + catalog = basic.catalog.Catalog.getInstance() + self.assertRaises(Exception, catalog.readDomain, ("xxx", job)) + cnttest += 1 + res = catalog.readDomain("countries", job) + self.assertEqual(isinstance(res, dict), True) + cnttest += 1 + countries = catalog.getKeys("countries", job) + self.assertEqual(len(countries), 21) + cnttest += 1 + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + + def test_03key(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + catalog = basic.catalog.Catalog.getInstance() + res = catalog.getValue("countries", "key", job) + self.assertEqual(res, "") + self.assertEqual(job.m.rc, basic.message.RC_ERROR) + cnttest += 1 + res = catalog.getValue("countries", "TD", job) + print(str(res)) + self.assertEqual(res["Land"], "Tschad") + print(str(res)) + cnttest += 1 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -47,4 +78,5 @@ class MyTestCase(unittest.TestCase): if __name__ == '__main__': + verbose = True unittest.main() diff --git a/test/test_24gen.py b/test/test_24gen.py new file mode 100644 index 0000000..83b0ee0 --- /dev/null +++ b/test/test_24gen.py @@ -0,0 +1,94 @@ +""" +unit-test +""" +import unittest +import inspect +import utils.gen_tool +import utils.gen_const as G +import basic.program +import test.testtools + +# the list of TEST_FUNCTIONS defines which function will be really tested. +# if you minimize the list you can check the specific test-function +TEST_FUNCTIONS = ["test_11getValueList", "test_12getCntElement", "test_13getMinCount", "test_14getElemList"] +TEST_FUNCTIONS = ["test_01getElemList"] +# with this variable you can switch prints on and off +verbose = False + + + +class MyTestCase(unittest.TestCase): + mymsg = "--------------------------------------------------------------" + + def test_01getElemList(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + res = utils.gen_tool.getElemList(G.KEY_LIST, "0 .. 5", 6, job) + print((str(res))) + res = utils.gen_tool.getElemList(G.KEY_LIST, "a, b, c, d", 6, job) + print((str(res))) + res = utils.gen_tool.getElemList(G.KEY_LIST, "cat:countries", 6, job) + print((str(res))) + + + + def test_11getValueList(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + for cnt in [3, 4, 6, 10]: + res = utils.gen_tool.getValueList(["A", "B", "C", "D"], cnt, job) + self.assertEqual(len(res), cnt) + cnttest += 1 + for cnt in [3, 4, 6, 10]: + res = utils.gen_tool.getValueList("[A, B, C, D]", cnt, job) + self.assertEqual(len(res), cnt) + cnttest += 1 + for cnt in [3, 4, 6, 10]: + res = utils.gen_tool.getValueList("0 .. 4", cnt, job) + self.assertEqual(len(res), cnt) + cnttest += 1 + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + + def test_12getCntElement(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + + + def test_13getMinCount(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + + + def test_14getElemList(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + + + def test_zzz(self): + if verbose: print(MyTestCase.mymsg) + + +if __name__ == '__main__': + verbose = True + unittest.main() diff --git a/utils/config_tool.py b/utils/config_tool.py index 2171d20..be9afa2 100644 --- a/utils/config_tool.py +++ b/utils/config_tool.py @@ -121,6 +121,25 @@ def getConfigPath(modul, name, subname="", job=None): job.debug(verify, "4 " + pathname) if os.path.exists(pathname): return pathname + elif modul == P.KEY_CATALOG: + for format in CONFIG_FORMAT: + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_TDATA), + P.KEY_CATALOG, name + "." + format) + job.debug(verify, "4 " + pathname) + if os.path.exists(pathname): + return pathname + for format in CONFIG_FORMAT: + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), + P.KEY_CATALOG, name + "." + format) + job.debug(verify, "4 " + pathname) + if os.path.exists(pathname): + return pathname + for format in CONFIG_FORMAT: + pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), + P.KEY_CATALOG, name + "." + format) + job.debug(verify, "4 " + pathname) + if os.path.exists(pathname): + return pathname else: pathname = utils.path_tool.composePath(P.P_TCPARFILE) job.debug(verify, "7 " + pathname) diff --git a/utils/data_const.py b/utils/data_const.py index 7a82991..17b8781 100644 --- a/utils/data_const.py +++ b/utils/data_const.py @@ -41,9 +41,11 @@ DATA_ATTR_COMP = "_comp" """ reference to using componente with their object """ DATA_ATTR_CHAR = "_char" """ character of the data in order to delete it ión initialization """ +DATA_ATTR_KEY = "_key" +""" key for a data-specification of a catalog-list - default: the first field is the key """ DATA_ATTR_ALIAS = "_alias" -LIST_DATA_ATTR = [DATA_ATTR_COUNT, DATA_ATTR_DATE, DATA_ATTR_CHAR, DATA_ATTR_COMP, DATA_ATTR_ALIAS] -LIST_ATTR_CONST = ["DATA_ATTR_COUNT", "DATA_ATTR_DATE", "DATA_ATTR_CHAR", "DATA_ATTR_COMP", "DATA_ATTR_ALIAS"] +LIST_DATA_ATTR = [DATA_ATTR_COUNT, DATA_ATTR_DATE, DATA_ATTR_CHAR, DATA_ATTR_COMP, DATA_ATTR_ALIAS,DATA_ATTR_KEY] +LIST_ATTR_CONST = ["DATA_ATTR_COUNT", "DATA_ATTR_DATE", "DATA_ATTR_CHAR", "DATA_ATTR_COMP", "DATA_ATTR_ALIAS", "DATA_ATTR_KEY"] HEAD_ATTR_DESCR = "decription" HEAD_ATTR_TARGET = "target" diff --git a/utils/gen_const.py b/utils/gen_const.py new file mode 100644 index 0000000..d507589 --- /dev/null +++ b/utils/gen_const.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# --------------------------------------------------------------------------------------------------------- +# Author : Ulrich Carmesin +# Source : gitea.ucarmesin.de +# https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/232-testfallgenerierung +# --------------------------------------------------------------------------------------------------------- + +KEY_RANDOM = "random" +KEY_LIST = "list" +KEY_VARNUM = "varnum" +KEY_VARSTR = "varstr" +KEY_VARDAT = "vardat" +KEY_PREFIX_X = "x" +VAL_DELIMITER = "," +VAL_SECTOR = " .. " +VAL_CATALOG = "cat" + +CLS_MISFORMAT = "missformat" +CLS_NONE = "none" +CLS_EMPTY = "empty" +CLS_LESS = "less" +CLS_GREATER = "more" +ATTR_MIN_COUNT = "mincount" \ No newline at end of file diff --git a/utils/gen_tool.py b/utils/gen_tool.py new file mode 100644 index 0000000..a537533 --- /dev/null +++ b/utils/gen_tool.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# --------------------------------------------------------------------------------------------------------- +# Author : Ulrich Carmesin +# Source : gitea.ucarmesin.de +# https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/232-testfallgenerierung +# --------------------------------------------------------------------------------------------------------- +import re +import utils.config_tool +import utils.path_const as P +import basic.constants as B +import basic.program +import utils.gen_const as G +import random +import basic.catalog + +VAL_CLASSES: { + "xvarnum": { + G.CLS_MISFORMAT: "str", + G.CLS_NONE: None, + G.CLS_EMPTY: 0, + G.CLS_LESS: True, + G.CLS_GREATER: True, + G.ATTR_MIN_COUNT: 5 + }, + "xvarnum": { + G.CLS_MISFORMAT: "str,feb", + G.CLS_NONE: None, + G.CLS_EMPTY: 0, + G.CLS_LESS: True, + G.CLS_GREATER: True, + G.ATTR_MIN_COUNT: 6 + }, + "xvarstr": { + G.CLS_MISFORMAT: "num,sym,koeln", + G.CLS_NONE: None, + G.CLS_EMPTY: 0, + G.CLS_LESS: False, + G.CLS_GREATER: False, + G.ATTR_MIN_COUNT: 7 + } +} + + +def getCntElement(values, job): + if G.VAL_SECTOR in values: + return 2 + elif G.VAL_DELIMITER in values: + a = values.split(G.VAL_DELIMITER) + return len(a) + elif G.VAL_CATALOG + ":" in values: + a = [0, 1, 2, 3, 4] + return len(a) + return 1 + + +def getValueList(values, count, job): + out = [] + for i in range(0, count): + out.append(values[i % len(values)]) + print(str(out)) + return out + + +def getMinCount(formula, values, job): + """ + :param formula: + :param values: definition of value-list + :param job: + :return: count of necessary values + """ + if G.KEY_RANDOM in formula: + return 1 + elif formula[0:1] == G.KEY_PREFIX_X: + elems = getCntElement(values, job) + factor = 1 + if VAL_CLASSES[formula][G.CLS_LESS]: + factor = factor * 2 + if VAL_CLASSES[formula][G.CLS_GREATER]: + factor = factor * 2 + return VAL_CLASSES[formula][G.ATTR_MIN_COUNT] + factor * (elems - 1) + elif formula == G.KEY_LIST: + return getCntElement(values, job) + return 1 + + +def getElemList(formula, values, count, job): + """ + + :param formula: + :param values: + :param count: + :param job: + :return: + """ + out = [] + verbose = False + if verbose: print(values+" , "+str(count)) + sector_regex = r"(.*)" + re.escape(G.VAL_SECTOR)+ r"(.*)" + delim_regex = r"(.*)" + re.escape(G.VAL_DELIMITER)+ r"(.*)" + catalog_regex = re.escape(G.VAL_CATALOG)+ r":(.*)" + if re.match(sector_regex, values): + if verbose: print("match 1") + temp = [] + res = re.search(sector_regex, values) + start = res.group(1) + target = res.group(2) + if start.isdecimal() and target.isdecimal(): + for i in range(int(start), int(target)): + temp.append(str(i)) + if target not in temp: + temp.append(target) + if verbose: print(str(start)+" - "+str(target)+" : "+str(temp)) + elif re.match(delim_regex, values): + if verbose: print("match 2") + temp = values.split(G.VAL_DELIMITER) + for i in range(0, len(temp)): temp[i] = temp[i].strip() + if verbose: print(str(temp)) + elif re.match(catalog_regex, values): + res = re.search(catalog_regex, values) + domain = res.group(1) + catalog = basic.catalog.Catalog.getInstance() + temp = catalog.getKeys(domain, job) + if not isinstance(temp, list): + temp = [] + max = 3 + while len(temp) > 0 and len(out) < count: + out += temp + max -= 1 + if max < 0: break + return out[0:count] diff --git a/utils/path_const.py b/utils/path_const.py index 8008c80..ef25c33 100644 --- a/utils/path_const.py +++ b/utils/path_const.py @@ -11,6 +11,7 @@ KEY_BACKUP = "backup" KEY_REFFILE = "reffile" KEY_TESTCASE = "tc" KEY_TESTSUITE = "ts" +KEY_CATALOG = "catalog" KEY_DEBUGNAME = "debugname" KEY_LOGNAME = "logname" KEY_BASIC = "basic" diff --git a/utils/path_tool.py b/utils/path_tool.py index 10b93a3..edd3078 100644 --- a/utils/path_tool.py +++ b/utils/path_tool.py @@ -186,9 +186,10 @@ def extractPath(pathtyp, path): """ job = basic.program.Job.getInstance() patterlist = extractPattern(pathtyp) + verbose = False work = path i = 0 - print("-- extractPatternList -- " + pathtyp + ":" + str(patterlist)) + if verbose: print("-- extractPatternList -- " + pathtyp + ":" + str(patterlist)) for p in patterlist: if len(p) < 1 : continue delim = p[0] @@ -199,13 +200,13 @@ def extractPath(pathtyp, path): nextdelim = "" else: nextdelim = patterlist[i+1][0] - print("xPath delim " + delim + " " + str(len(delim)) + ", " + nextdelim + " work " + work) + if verbose: print("xPath delim " + delim + " " + str(len(delim)) + ", " + nextdelim + " work " + work) work = work[len(delim):] - print("xPath key " + key + " i " + str(i) + " work " + work) + if verbose: print("xPath key " + key + " i " + str(i) + " work " + work) if val is not None: - print("val not none " + val) + if verbose: print("val not none " + val) if val in work: - print("val ok") + if verbose: print("val ok") work = work.replace(val, "") elif "time" in key and "job.par" in key: prop = "" @@ -214,25 +215,25 @@ def extractPath(pathtyp, path): else: prop = work key = key[8:] - print("setprop " + key + " = " + prop) + if verbose: print("setprop " + key + " = " + prop) if hasattr(job.par, key): delattr(job.par, key) setattr(job.par, key, val) else: - print("val not not ok " + val + " zu " + key) + if verbose: print("val not not ok " + val + " zu " + key) elif "job.par" in key: prop = "" if i < len(patterlist) - 1: - print("job.par nextdelim " + nextdelim) + if verbose: print("job.par nextdelim " + nextdelim) prop = work[0:work.index(nextdelim)] else: prop = work key = key[8:] - print("setprop " + key + " = " + prop) + if verbose: print("setprop " + key + " = " + prop) if hasattr(job.par, key): delattr(job.par, key) setattr(job.par, key, prop) work = work.replace(prop, "") else: - print("val is none " + key) + if verbose: print("val is none " + key) i = i +1 diff --git a/utils/tdata_tool.py b/utils/tdata_tool.py index 119079b..f58c8a4 100644 --- a/utils/tdata_tool.py +++ b/utils/tdata_tool.py @@ -162,10 +162,11 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): if len(list_blocks) < 1: setBlockLists(job) status = "start" + verbose = False tableAttr = {} # table tableDict = {} # table for l in lines: - print("lines "+l) + if verbose: print("lines "+l) fields = splitFields(l, D.CSV_DELIMITER, job) # check empty line, comment if (len(fields) < 1) or (len(l.strip().replace(D.CSV_DELIMITER,"")) < 1): @@ -175,23 +176,23 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): continue a = fields[0].lower().split(":") # keywords option, step, table - print(str(a)+" -- "+str(fields)) + if verbose: print(str(a)+" -- "+str(fields)) tableAttr = setTableAttribute(tableAttr, a[0], fields[1], job) if (tableAttr["hit"]): status = "TABLE_ALIAS" continue if (a[0].lower() in list_blocks[D.CSV_BLOCK_HEAD]): - print("head "+l) + if verbose: print("head "+l) setTdataLine(tdata, fields, D.CSV_BLOCK_HEAD, job) status = "start" continue elif (a[0].lower() in list_blocks[D.CSV_BLOCK_OPTION]): - print("option " + l) + if verbose: print("option " + l) setTdataLine(tdata, fields, D.CSV_BLOCK_OPTION, job) status = "start" continue elif (a[0].lower() in list_blocks[D.CSV_BLOCK_STEP]): - print("step "+l) + if verbose: print("step "+l) step = basic.step.parseStep(job, fields) if D.CSV_BLOCK_STEP not in tdata: tdata[D.CSV_BLOCK_STEP] = [] @@ -199,14 +200,14 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): status = "start" continue elif (a[0].lower() in list_blocks[D.CSV_BLOCK_IMPORT]): - print("includes " + l) + if verbose: print("includes " + l) if D.CSV_BLOCK_IMPORT not in tdata: tdata[D.CSV_BLOCK_IMPORT] = [] tdata[D.CSV_BLOCK_IMPORT].append(fields[1]) status = "start" continue elif (a[0].lower() in list_blocks[D.CSV_BLOCK_TABLES]): - print("tables "+l) + if verbose: print("tables "+l) h = a h[0] = B.DATA_NODE_TABLES if ttype == D.CSV_SPECTYPE_CONF: @@ -216,7 +217,7 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): status = D.CSV_SPECTYPE_DATA elif (status == D.CSV_SPECTYPE_DATA): tableDict = getTdataContent(msg, tdata, h) - print("setTableData "+str(h)+" "+str(tableDict)) + if verbose: print("setTableData "+str(h)+" "+str(tableDict)) setTableData(tableDict, fields, ttype, job) elif (status == "TABLE_ALIAS") and D.DATA_ATTR_ALIAS in tdata: alias = tdata[D.DATA_ATTR_ALIAS] @@ -234,7 +235,7 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): if B.DATA_NODE_TABLES in tdata and B.DATA_NODE_TABLES in tdata[B.DATA_NODE_TABLES]: for k in tdata[B.DATA_NODE_TABLES][B.DATA_NODE_TABLES]: if k in tdata[B.DATA_NODE_TABLES]: - print("Error") + if verbose: print("Error") else: tdata[B.DATA_NODE_TABLES][k] = tdata[B.DATA_NODE_TABLES][B.DATA_NODE_TABLES][k] tdata[B.DATA_NODE_TABLES].pop(B.DATA_NODE_TABLES) @@ -244,7 +245,7 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None): def setTableHeader(tableDict, tableAttr, fields, ttype, job): header = [] for i in range(1, len(fields)): - header.append(fields[i]) + header.append(fields[i].strip()) tableDict[B.DATA_NODE_HEADER] = header for attr in tableAttr: tableDict[attr] = tableAttr[attr] @@ -253,6 +254,9 @@ def setTableHeader(tableDict, tableAttr, fields, ttype, job): tableDict[B.DATA_NODE_DATA] = {} elif ttype == D.CSV_SPECTYPE_KEYS: tableDict[D.CSV_NODETYPE_KEYS] = {} + tableDict[D.DATA_ATTR_KEY] = 1 + if D.DATA_ATTR_KEY in tableAttr: + tableDict[D.DATA_ATTR_KEY] = header.index(tableAttr[D.DATA_ATTR_KEY]) + 1 else: tableDict[B.DATA_NODE_DATA] = [] return tableDict @@ -264,16 +268,16 @@ def setTableData(tableDict, fields, ttype, job): fields = [tableDict[D.DATA_ATTR_ALIAS]] + fields i = 1 for f in tableDict[B.DATA_NODE_HEADER]: - row[f] = fields[i] + row[f] = fields[i].strip() i += 1 if ttype == D.CSV_SPECTYPE_DATA: row[B.ATTR_DATA_COMP] = {} for c in fields[0].split(","): a = c.split(":") - row[B.ATTR_DATA_COMP][a[0]] = a[1] + row[B.ATTR_DATA_COMP][a[0]] = a[1].strip() tableDict[B.DATA_NODE_DATA].append(row) elif ttype == D.CSV_SPECTYPE_KEYS: - tableDict[D.CSV_NODETYPE_KEYS][fields[1]] = row + tableDict[D.CSV_NODETYPE_KEYS][fields[tableDict[D.DATA_ATTR_KEY]].strip()] = row elif ttype == D.CSV_SPECTYPE_CONF: tableDict[fields[1]] = row return tableDict @@ -282,7 +286,7 @@ def setTableData(tableDict, fields, ttype, job): def setTableAttribute(tableAttr, key, val, job): for attr in D.LIST_DATA_ATTR: if (key.lower() in list_blocks[attr]): - tableAttr[attr] = val + tableAttr[attr] = val.strip() tableAttr["hit"] = True return tableAttr tableAttr["hit"] = False