Ulrich Carmesin
2 years ago
11 changed files with 378 additions and 46 deletions
@ -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() |
@ -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" |
@ -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] |
Loading…
Reference in new issue