本文整理汇总了Python中junit_xml.TestSuite.to_file方法的典型用法代码示例。如果您正苦于以下问题:Python TestSuite.to_file方法的具体用法?Python TestSuite.to_file怎么用?Python TestSuite.to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类junit_xml.TestSuite
的用法示例。
在下文中一共展示了TestSuite.to_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize_and_read
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def serialize_and_read(test_suites, to_file=False, prettyprint=None):
"""writes the test suite to an XML string and then re-reads it using minidom,
returning => (test suite element, list of test case elements)"""
try:
iter(test_suites)
except TypeError:
test_suites = [test_suites]
if to_file:
fd, filename = tempfile.mkstemp(text=True)
with os.fdopen(fd, 'w') as f:
TestSuite.to_file(f, test_suites)
print("Serialized XML to temp file [%s]" % filename)
xmldoc = minidom.parse(filename)
os.remove(filename)
else:
if prettyprint is not None:
xml_string = TestSuite.to_xml_string(test_suites, prettyprint=prettyprint)
else:
xml_string = TestSuite.to_xml_string(test_suites)
print("Serialized XML to string:\n%s" % xml_string)
xmldoc = minidom.parseString(xml_string)
ret = []
suites = xmldoc.getElementsByTagName("testsuites")[0]
for suite in suites.getElementsByTagName("testsuite"):
cases = suite.getElementsByTagName("testcase")
ret.append((suite, cases))
return ret
示例2: main
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def main():
args = parse_args()
spawn_func = None
spawn_arg = None
if args.port is not None:
spawn_func = spawn_port
spawn_arg = args.port
elif args.executable is not None:
spawn_func = spawn_exec
spawn_arg = args.executable
name = args.name or ""
global debug
if args.debug:
debug = True
if spawn_func is None:
debug_print("Please specify port or executable", file=sys.stderr)
return 1
mocks = {}
if args.mock is not None:
mocks_mod = imp.load_source('mocks', args.mock)
mocks = mock_decorators.env
with spawn_func(spawn_arg) as sp:
ts = run_tests(sp, name, mocks)
if args.output:
with open(args.output, "w") as f:
TestSuite.to_file(f, [ts])
return 0
示例3: run_everything_else
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def run_everything_else(xml = False):
mega_suite = []
tests = [
run_test_arakoon_changes,
run_tests_cli,
run_test_big_object
]
for x in tests:
r = x ()
mega_suite.append(r)
if is_true(xml):
from junit_xml import TestSuite, TestCase
test_cases = []
for (suite, results) in mega_suite:
for (name,result, delta) in results:
test_case = TestCase(name, suite, elapsed_sec = delta)
if not result:
test_case.add_error_info(message = "failed")
test_cases.append(test_case)
ts = [TestSuite("run_everything_else", test_cases)]
with open('./testresults.xml', 'w') as f:
TestSuite.to_file(f,ts)
else:
print mega_suite
示例4: generateJUnitReport
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def generateJUnitReport(self, lstRunResult, runResultDir):
#create junit xml report file use junit-xml 1.4 pip install junit-xml
resultFileName = runResultDir + os.path.sep + 'RunResult.xml'
previousCaseModuleName = ''
rowIndex = 0
lstTestSuites = []
testSuite = []
for runResult in lstRunResult:
#runResult (sheetName, moduleName, testCaseID, runResult, timeElapsedSec, failureMessage)
#test
testCaseName = runResult[2]
className = runResult[1] + '.' + runResult[2]
timeElapsedSec = runResult[4]
failureMessage = runResult[5]
testCase = TestCase(testCaseName, className, timeElapsedSec)
testCase.add_failure_info(None, failureMessage)
currTestCaseModuleName = runResult[1]
if not currTestCaseModuleName == previousCaseModuleName:
testSuite = TestSuite(currTestCaseModuleName)
lstTestSuites.append(testSuite)
testSuite.test_cases.append(testCase)
#print TestSuite.to_xml_string(lstTestSuites)
#Write the xml content to result file
with open(runResultDir + os.path.sep + 'Result.xml', 'w') as f:
TestSuite.to_file(f, lstTestSuites)
示例5: main
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def main():
args = parse_args()
spawn_func = None
spawn_arg = None
if args.port is not None:
spawn_func = spawn_port
spawn_arg = args.port
elif args.executable is not None:
spawn_func = spawn_exec
spawn_arg = args.executable
name = args.name or ""
global debug
if args.debug:
debug = True
if spawn_func is None:
debug_print("Please specify port or executable", file=sys.stderr)
return 1
env_vars = []
if args.env_file is not None:
cfg = ConfigParser()
cfg.optionxform = str
with args.env_file as fp:
cfg.readfp(fp)
env_vars = cfg.items('global')
mocks = {}
if args.mock is not None:
mocks_mod = imp.load_source('mocks', args.mock)
mocks = mock_decorators.env
with spawn_func(spawn_arg) as sp:
ts = run_tests(sp, name, mocks, env_vars)
if args.output:
with open(args.output, "w") as f:
TestSuite.to_file(f, [ts])
return 0
示例6: dump_junit_xml
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def dump_junit_xml():
from junit_xml import TestSuite, TestCase
test_cases = [TestCase('testname', 'package.test', 123.345, 'I am stdout!', 'I am stderr!')]
ts = [ TestSuite("stress test suite", test_cases) ]
with open('./testresults.xml', mode='w') as f:
TestSuite.to_file(f, ts)
示例7: generate
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def generate(self):
"""
Generates the report
"""
self._setup()
for config_name in self.report_info.config_to_test_names_map.keys():
config_dir = os.path.join(self.report_info.resource_dir, config_name)
utils.makedirs(config_dir)
testsuite = self._generate_junit_xml(config_name)
with open(os.path.join(self.report_info.junit_xml_path, 'zopkio_junit_reports.xml'), 'w') as file:
TestSuite.to_file(file, [testsuite], prettyprint=False)
示例8: Run
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def Run(conf, xmldir):
logfile = "%s/pacemaker.log" % xmldir
cluster_env = readClusterConf(conf)
testcases = []
#Name of Test Suite
TestSuiteName = "Running pacemaker-cts"
#Name of junit xml file
JunitXML = "junit-pacemakerCTS-ha.xml"
#Define testcases
#testcases = [(TestcaseName, TestcaseClass, TestcaseFunction)]
#eg.
# ('PacemakerService', 'SetupCluster.service', runPackmakerService)
#Define function runPackmakerService before using
cases_def = [("Test Flip", "Flip.PacemakerCTS.service", get_result),
("Test Restart", "Restart.PacemakerCTS.service", get_result),
("Test Stonithd", "Stonithd.PacemakerCTS.service", get_result),
("Test StartOnebyOne", "StartOnebyOne.PacemakerCTS.service", get_result),
("Test SimulStart", "SimulStart.PacemakerCTS.service", get_result),
("Test SimulStop", "SimulStop.PacemakerCTS.service", get_result),
("Test StopOnebyOne", "StopOnebyOne.PacemakerCTS.service", get_result),
("Test RestartOnebyOne", "RestartOnebyOne.PacemakerCTS.service", get_result),
("Test PartialStart", "PartialStart.PacemakerCTS.service", get_result),
("Test Standby", "Standby.PacemakerCTS.service", get_result),
("Test MaintenanceMode", "MaintenanceMode.PacemakerCTS.service", get_result),
("Test ResourceRecover", "ResourceRecover.PacemakerCTS.service", get_result),
("Test ComponentFail", "ComponentFail.PacemakerCTS.service", get_result),
("Test Reattach", "Reattach.PacemakerCTS.service", get_result),
("Test SpecialTest1", "SpecialTest1.PacemakerCTS.service", get_result),
("Test NearQuorumPoint", "NearQuorumPoint.PacemakerCTS.service", get_result),
("Test RemoteBasic", "RemoteBasic.PacemakerCTS.service", get_result),
("Test RemoteStonithd", "RemoteStonithd.PacemakerCTS.service", get_result),
("Test RemoteMigrate", "RemoteMigrate.PacemakerCTS.service", get_result),
("Test RemoteRscFailure","RemoteRscFailure.PacemakerCTS.service", get_result)]
#Not necessary to modify the lines below!
skip_flag = False
for a_case in cases_def:
case = TestCase(a_case[0], a_case[1])
testcases.append(case)
if skip_flag:
skipCase(case, "Pacemaker service of the first node not started.")
continue
skip_flag = assertCase(case, a_case[2], cluster_env, a_case[0], logfile)
ts = TestSuite(TestSuiteName, testcases)
with open(xmldir+"/"+JunitXML, "w") as f:
ts.to_file(f, [ts])
示例9: build_packages
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def build_packages(self, packages):
self._results = []
for package, version in packages:
if self._should_package_be_build(package, version):
logger.info('Building %s %s', package, version)
try:
wheel_file = self._builder(package, version)
self._upload_package(package, version, wheel_file)
self._log_success(package, version)
except wheeler.BuildError as e:
self._log_fail(e, package, version)
if self._junit_xml:
with open(self._junit_xml, 'w') as output:
test_suite = TestSuite('devpi-builder results', self._results)
TestSuite.to_file(output, [test_suite])
示例10: _output_normal
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def _output_normal(self, test_result):
# Need refactor
if test_result == {}:
print '[what?!] there are not any test result, what is the test case id?'
else:
print
xml_test_suites = []
summary_dict = self._get_summary_dict(test_result)
self.report_create_time = str(time.strftime('%Y%m%d_%H%M%S', time.localtime()))
for case_classify in test_result.keys():
xml_test_cases = []
if 'result' in test_result[case_classify].keys():
# Generate HTML report
self._generate_html_file(
case_classify, test_result[case_classify]['result'],
test_result[case_classify]['summary'])
# Save the result into the CSV
self._output_result_to_csv(test_result)
# Show in Console
print '{0} {1} {2}'.format('='*16, case_classify, '='*16)
test_case_result = test_result[case_classify]['result']
for case_id in test_case_result.keys():
print '[{0}][{1}] {2}, {3}, {4}'.format(case_classify, case_id,
test_case_result[case_id][0],
test_case_result[case_id][1],
str(test_case_result[case_id][2]))
# Produce xml file
test_case = TestCase(case_id, case_classify, int(test_case_result[case_id][2]))
if test_case_result[case_id][0] == 'Fail' or test_case_result[case_id][0] == 'Error':
try:
test_case.add_failure_info('msg' + test_case_result[case_id][1])
except:
test_case.add_failure_info('msg' + str(test_case_result[case_id]))
xml_test_cases.append(test_case)
xml_test_suites.append(TestSuite(case_classify, xml_test_cases))
with open(os.path.join(self.latest_reports_dir, case_classify + '.xml'), 'w') as f:
TestSuite.to_file(f, xml_test_suites, prettyprint=True)
self._generate_summary_html_file(summary_dict)
print '{0} {1} {2}'.format('='*16, 'Summary', '='*16)
pprint.pprint(summary_dict)
示例11: publish_result
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def publish_result(file=None):
ts = [TestSuite("Manifest launcher", test_cases)]
if file:
with open(file, 'w') as f:
TestSuite.to_file(f, ts, prettyprint=True, encoding='utf-8')
else:
err = 0
pas = 0
for case in test_cases:
if case.is_error() or case.is_failure():
print case.name+':'+case.classname+' ... FAIL'
print case.failure_message
err+=1
else:
print case.name+':'+case.classname+'... PASS'
pas+=1
print "Passed: %d, failed: %d\n" % (pas, err)
示例12: parseLog
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def parseLog(TestSuiteName, xmlfile, caseset, test_results, cluster_env):
testcases = []
#Not necessary to modify the lines below!
skip_flag = False
for a_case in caseset:
case = TestCase(a_case[0], a_case[1])
testcases.append(case)
if skip_flag:
skipCase(case, "This case is not scheduled.")
continue
skip_flag = assertCase(case, a_case[2], cluster_env, a_case[0], test_results)
ts = TestSuite(TestSuiteName, testcases)
with open(xmlfile, "w") as f:
ts.to_file(f, [ts])
示例13: serialize_and_read
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def serialize_and_read(test_suites, to_file=False, prettyprint=False, encoding=None):
"""writes the test suite to an XML string and then re-reads it using minidom,
returning => (test suite element, list of test case elements)"""
try:
iter(test_suites)
except TypeError:
test_suites = [test_suites]
if to_file:
fd, filename = tempfile.mkstemp(text=True)
os.close(fd)
with codecs.open(filename, mode='w', encoding=encoding) as f:
TestSuite.to_file(f, test_suites, prettyprint=prettyprint, encoding=encoding)
print("Serialized XML to temp file [%s]" % filename)
xmldoc = minidom.parse(filename)
os.remove(filename)
else:
xml_string = TestSuite.to_xml_string(
test_suites, prettyprint=prettyprint, encoding=encoding)
if PY2:
assert isinstance(xml_string, unicode)
print("Serialized XML to string:\n%s" % xml_string)
if encoding:
xml_string = xml_string.encode(encoding)
xmldoc = minidom.parseString(xml_string)
def remove_blanks(node):
for x in node.childNodes:
if x.nodeType == minidom.Node.TEXT_NODE:
if x.nodeValue:
x.nodeValue = x.nodeValue.strip()
elif x.nodeType == minidom.Node.ELEMENT_NODE:
remove_blanks(x)
remove_blanks(xmldoc)
xmldoc.normalize()
ret = []
suites = xmldoc.getElementsByTagName("testsuites")[0]
for suite in suites.getElementsByTagName("testsuite"):
cases = suite.getElementsByTagName("testcase")
ret.append((suite, cases))
return ret
示例14: Run
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def Run(conf, xmldir):
cluster_env = readClusterConf(conf)
testcases = []
#Name of Test Suite
TestSuiteName = "Setup HA Cluster"
#Name of junit xml file
JunitXML = "junit-setup-ha.xml"
#Define testcases
#testcases = [(TestcaseName, TestcaseClass, TestcaseFunction)]
#eg.
# ('PacemakerService', 'SetupCluster.service', runPackmakerService)
#Define function runPackmakerService before using
cases_def = [('PacemakerService', 'SetupCluster.service', runPackmakerService),
('NodesNumber', 'SetupCluster.nodes', runNodesNumber),
('NodesStatus', 'SetupCluster.nodes', runNodesStatus)]
#('ConfigureRes', 'SetupCluster.resources', runConfigureRes)]
#Not necessary to modify the lines below!
skip_flag = False
for a_case in cases_def:
case = TestCase(a_case[0], a_case[1])
testcases.append(case)
if skip_flag:
skipCase(case, "Can not test!",
"Pacemaker service of the first node not started.")
continue
skip_flag = assertCase(case, a_case[2], cluster_env)
ts = TestSuite(TestSuiteName, testcases)
with open(xmldir+"/"+JunitXML, "w") as f:
ts.to_file(f, [ts])
lines = os.popen("ssh [email protected]%s crm_mon -1r" % cluster_env["IP_NODE1"]).readlines()
with open(xmldir+"/"+"crm_mon", "w") as p:
p.writelines(lines)
lines = os.popen("ssh [email protected]%s cat /etc/YaST2/*build*" % cluster_env["IP_NODE1"]).readlines()
with open(xmldir+"/"+"host-build", "w") as p:
p.writelines(lines)
示例15: Run
# 需要导入模块: from junit_xml import TestSuite [as 别名]
# 或者: from junit_xml.TestSuite import to_file [as 别名]
def Run(conf, xmldir):
cluster_env = readClusterConf(conf)
testcases = []
#Name of Test Suite
TestSuiteName = "Setup HA Cluster"
#Name of junit xml file
JunitXML = "junit-drbd-pacemaker.xml"
#Define testcases
#testcases = [(TestcaseName, TestcaseClass, TestcaseFunction)]
#eg.
# ('PacemakerService', 'SetupCluster.service', runPackmakerService)
#Define function runPackmakerService before using
cases_def = [('drbdPacemakerRes', 'SetupCluster.drbd', configurePacemaker),
('drbdUpToDateBefore', 'DRBD.disks', checkDRBDState),
('drbdPrimaryBefore', 'DRBD.state', checkDRBDRole),
('drbdShowInPacemaker', 'DRBD.pacemaker', checkPacemakerStatus),
('drbdSwitchMaster', 'DRBD.pacemaker', switchDRBD),
('drbdUpToDateAfter', 'DRBD.disks', checkDRBDState),
('drbdPrimaryAfter', 'DRBD.state', checkDRBDRole),
('drbdShowInPacemakerAfter', 'DRBD.pacemaker', checkPacemakerStatus)]
#('ConfigureRes', 'SetupCluster.resources', runConfigureRes)]
#Not necessary to modify the lines below!
skip_flag = False
for a_case in cases_def:
case = TestCase(a_case[0], a_case[1])
testcases.append(case)
if skip_flag:
skipCase(case, "Can not test!",
"Pacemaker service of the first node not started or didn't configure DRBD.")
continue
skip_flag = assertCase(case, a_case[2], cluster_env)
sleep(3)
ts = TestSuite(TestSuiteName, testcases)
with open(xmldir+"/"+JunitXML, "w") as f:
ts.to_file(f, [ts])