Ulrich Carmesin
3 years ago
13 changed files with 583 additions and 56 deletions
@ -0,0 +1,158 @@ |
|||
import unittest |
|||
import os |
|||
|
|||
import basic.program |
|||
import basic.program |
|||
import components.component |
|||
from basic.componentHandling import ComponentManager |
|||
import init_testcase |
|||
import test_executer |
|||
import test.constants |
|||
import utils.report_tool |
|||
import utils.match_tool as M |
|||
import basic.constants as B |
|||
|
|||
HOME_PATH = test.constants.HOME_PATH |
|||
|
|||
class MyTestCase(unittest.TestCase): |
|||
|
|||
def getReport(self): |
|||
job = basic.program.Job.getInstance() |
|||
report = utils.report_tool.Report() |
|||
archiv = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV]+"/" |
|||
i = 0 |
|||
for m in M.MATCH_TYPES: |
|||
report.setPaths("TC0001", "comp01", "arte01", m, archiv+"path0111"+str(i), archiv+"path0111"+str(i)+"02") |
|||
report.setPaths("TC0001", "comp01", "arte02", m, archiv+"path0112"+str(i)+"", archiv+"path0112"+str(i)+"02") |
|||
report.setPaths("TC0001", "comp02", "arte01", m, archiv+"path0121"+str(i)+"", archiv+"path0121"+str(i)+"02") |
|||
report.setPaths("TC0002", "comp01", "arte01", m, archiv+"path0211"+str(i)+"", archiv+"path0211"+str(i)+"02") |
|||
report.setPaths("TC0002", "comp02", "arte01", m, archiv+"path0221"+str(i)+"", archiv+"path0221"+str(i)+"02") |
|||
report.setMatchResult("TC0001", "comp01", "arte01", m, "result" + str(i), "<table>" + str(i) + "</table>") |
|||
report.setMatchResult("TC0001", "comp01", "arte02", m, "result" + str(i), "<table>" + str(i) + "</table>") |
|||
report.setMatchResult("TC0001", "comp02", "arte01", m, "result" + str(1), "<table>" + str(i) + "</table>") |
|||
report.setMatchResult("TC0002", "comp01", "arte01", m, "result" + str(1), "<table>" + str(i) + "</table>") |
|||
report.setMatchResult("TC0002", "comp02", "arte01", m, "result" + str(i), "<table>" + str(i) + "</table>") |
|||
i += 1 |
|||
if i > 4: |
|||
i = 0 |
|||
return report |
|||
|
|||
def test_cssClass(self): |
|||
job = basic.program.Job("unit") |
|||
args = { "application": "TEST", "environment": "ENV01", "modus": "unit", "tstime": "2022-03-19_12-09-09", |
|||
"tsdir": '/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf/testlauf/TST001_2022-03-19_12-09-09', |
|||
"step": 2 } |
|||
# "usecase": "TST001", "tstime": "2022-03-17_17-28"} |
|||
job.par.setParameterArgs(args) |
|||
job.setProgram("test_executer") |
|||
report = self.getReport() |
|||
i = 0 |
|||
for m in M.MATCH_TYPES: |
|||
cssClass = report.getCssClass("TC0001", "comp01", "arte01", m) |
|||
print(m + " test0111 " + cssClass) |
|||
self.assertEqual(cssClass, "result"+str(i)) |
|||
i += 1 |
|||
if i > 4: |
|||
i = 0 |
|||
cssClass = report.getCssClass("TC0002", "comp01", "arte01", m) |
|||
print(m + " test0121 " + cssClass) |
|||
cssClass = report.getCssClass("TC0001", "comp01", "arte02") |
|||
self.assertEqual(cssClass, "result4") |
|||
print("test0112 "+cssClass) |
|||
cssClass = report.getCssClass("TC0001", "comp02", "arte01") |
|||
print("test0121 "+cssClass) |
|||
self.assertEqual(cssClass, "result1") |
|||
cssClass = report.getCssClass("TC0002", "comp01") |
|||
self.assertEqual(cssClass, "result1") |
|||
cssClass = report.getCssClass("TC0002") |
|||
self.assertEqual(cssClass, "result4") |
|||
|
|||
def test_title(self): |
|||
job = basic.program.Job.getInstance() |
|||
print(" ---------- test_title") |
|||
setattr(job.par, "testsuite", "TST001") |
|||
report = self.getReport() |
|||
html = report.getTitle("TC0001", "comp01", "arte01", M.MATCH_POSTCOND) |
|||
print(html) |
|||
html = report.getTitle("TC0001") |
|||
self.assertEqual((utils.report_tool.REP_TITLE in html), True) |
|||
self.assertEqual((utils.report_tool.REP_TC in html), True) |
|||
self.assertEqual(("TC0001" in html), True) |
|||
html = report.getTitle() |
|||
self.assertEqual((utils.report_tool.REP_TITLE in html), True) |
|||
self.assertEqual((utils.report_tool.REP_TS in html), True) |
|||
self.assertEqual(("TST001" in html), True) |
|||
|
|||
def test_overview(self): |
|||
job = basic.program.Job.getInstance() |
|||
print(" ---------- test_overview") |
|||
report = self.getReport() |
|||
html = report.getOverview("TC0001") |
|||
print(html) |
|||
|
|||
def test_filename(self): |
|||
job = basic.program.Job.getInstance() |
|||
setattr(job.par, "testcase", "TC0001") |
|||
setattr(job.par, "tctime", "2022-03-23_21-23-32") |
|||
print(" ---------- test_filename") |
|||
cm = basic.componentHandling.ComponentManager() |
|||
for c in ["comp02"]: |
|||
comp = components.component.Component() |
|||
comp.name = c |
|||
basic.componentHandling.comps[c] = comp |
|||
report = self.getReport() |
|||
html = report.getFilepath("TC0001", "comp02", "arte01", M.MATCH_POSTCOND) |
|||
print(html) |
|||
|
|||
|
|||
def test_headlines(self): |
|||
job = basic.program.Job.getInstance() |
|||
setattr(job.par, "testcase", "TC0001") |
|||
setattr(job.par, "tctime", "2022-03-23_21-23-32") |
|||
cm = basic.componentHandling.ComponentManager() |
|||
for c in ["comp02"]: |
|||
comp = components.component.Component() |
|||
comp.name = c |
|||
basic.componentHandling.comps[c] = comp |
|||
print(" ---------- test_headlines") |
|||
report = self.getReport() |
|||
html = report.getTestcaseHead("TC0001") |
|||
print(html) |
|||
html = report.getComponentHead("TC0001", "comp02") |
|||
print(html) |
|||
html = report.getArtefactBlock("TC0001", "comp02", "arte01") |
|||
print(html) |
|||
|
|||
def test_reportS(self): |
|||
job = basic.program.Job.getInstance() |
|||
setattr(job.par, "testcase", "TC0001") |
|||
setattr(job.par, "testcases", ["TC0001", "TC0002"]) |
|||
setattr(job.par, "tctime", "2022-03-23_21-23-32") |
|||
print(" ---------- reportTestcase") |
|||
report = self.getReport() |
|||
cm = basic.componentHandling.ComponentManager() |
|||
for compname in ["comp01", "comp02"]: |
|||
conf = {} |
|||
comp = components.component.Component() |
|||
comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"} |
|||
comp.name = compname |
|||
comp.conf = conf |
|||
basic.componentHandling.comps[compname] = comp |
|||
html_1 = report.reportTestcase("TC0001") |
|||
print(html_1) |
|||
print("<<---------------------------------- TC0001") |
|||
report.extractTestcase("TC0001", html_1) |
|||
setattr(job.par, "testcase", "TC0002") |
|||
html_2 = report.reportTestcase("TC0002") |
|||
print(html_2) |
|||
print("<<---------------------------------- TC0002") |
|||
report.extractTestcase("TC0002", html_2) |
|||
setattr(job.par, "testsuite", "TST001") |
|||
html = report.reportTestsuite() |
|||
print(html) |
|||
print("<<---------------------------------- TST001") |
|||
|
|||
if __name__ == '__main__': |
|||
unittest.main() |
|||
|
|||
# report.setPaths("TC0001", "comp01", "arte01", m, archiv+"path0111"+str(i), archiv+"path0111"+str(i)+"02") |
@ -0,0 +1,45 @@ |
|||
import os, sys, json |
|||
import xmltodict |
|||
import pprint |
|||
|
|||
class fcts: |
|||
def dict2xml(tree): |
|||
out = xmltodict.unparse(tree, pretty=True) |
|||
return out |
|||
|
|||
def xml2dict(xmlstring): |
|||
tree = {} |
|||
pp = pprint.PrettyPrinter(indent=4) |
|||
tree = xmlstring.parse(xmlstring) |
|||
return tree |
|||
|
|||
def readXml(filename): |
|||
pass |
|||
|
|||
def addNode(xpath, value): |
|||
pass |
|||
|
|||
def writeDataTable(teststatus, tdata, comp): |
|||
""" |
|||
writes the testdata into a csv-file for documentation of the test-run |
|||
:param teststatus: |
|||
:param tdata: |
|||
:param comp: if specific else None |
|||
:return: |
|||
""" |
|||
#output = xmljson.badgerfish.etree(tdata, root=xmljson.badgerfish.Element('root')) |
|||
result = bf.etree(tdata, root=Element('xml')) |
|||
# xmljson.badgerfish.tostring(output) |
|||
txt = tostring(result, pretty_print=True) |
|||
print (txt.decode('utf-8')) |
|||
|
|||
# out = tostring(result, pretty_print=True) |
|||
#print (prettify(result)) |
|||
pass |
|||
|
|||
def prettify(elem): |
|||
"""Return a pretty-printed XML string for the Element. |
|||
""" |
|||
rough_string = tostring(elem, 'utf-8') |
|||
reparsed = xml.dom.minidom.parseString(rough_string ) |
|||
return reparsed.toprettyxml(indent=" ") |
@ -0,0 +1,51 @@ |
|||
import zipfile |
|||
import tarfile |
|||
import os |
|||
|
|||
ZIEL = '/home/ulrich/tmp' |
|||
QUELLE = '/home/ulrich/1_privat' |
|||
FOLDER = '64-UMKER' |
|||
|
|||
|
|||
def untarFolder(): |
|||
tar_file = tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'r:gz') |
|||
tar_file.extractall(path=os.path.join(ZIEL, 'tarliste')) |
|||
tar_file.close() |
|||
pass |
|||
|
|||
def tarFolder(): |
|||
with tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'w:gz') as tar_file: |
|||
for folderName, subfolders, filenames in os.walk(os.path.join(QUELLE, FOLDER)): |
|||
for filename in filenames: |
|||
folderShort = folderName.replace(QUELLE + '/', '') |
|||
# create complete filepath of file in directory |
|||
filePath = os.path.join(folderName, filename) |
|||
# Add file to zip |
|||
tar_file.add(filePath, os.path.join(folderShort, filename)) |
|||
tar_file.close() |
|||
|
|||
|
|||
def unzipFolder(): |
|||
zip_file = zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'r') |
|||
zip_file.extractall(path=os.path.join(ZIEL, 'liste')) |
|||
zip_file.close() |
|||
pass |
|||
|
|||
def zipFolder(): |
|||
with zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'w') as zip_file: |
|||
# Iterate over all the files in directory |
|||
for folderName, subfolders, filenames in os.walk(os.path.join(QUELLE, FOLDER)): |
|||
for filename in filenames: |
|||
folderShort = folderName.replace(QUELLE+'/', '') |
|||
# create complete filepath of file in directory |
|||
filePath = os.path.join(folderName, filename) |
|||
# Add file to zip |
|||
zip_file.write(filePath, os.path.join(folderShort, filename)) |
|||
zip_file.close() |
|||
return "" |
|||
|
|||
if __name__ == '__main__': |
|||
zipFolder() |
|||
unzipFolder() |
|||
tarFolder() |
|||
untarFolder() |
Loading…
Reference in new issue