当前位置: 首页>>代码示例>>Python>>正文


Python junit_xml.TestSuite类代码示例

本文整理汇总了Python中junit_xml.TestSuite的典型用法代码示例。如果您正苦于以下问题:Python TestSuite类的具体用法?Python TestSuite怎么用?Python TestSuite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestSuite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serialize_and_read

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
开发者ID:diarmuid,项目名称:python-junit-xml,代码行数:30,代码来源:test_junit_xml.py

示例2: main

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
开发者ID:AdrianMonenci,项目名称:Arduino,代码行数:27,代码来源:runner.py

示例3: test_to_xml_string_test_suites_not_a_list

    def test_to_xml_string_test_suites_not_a_list(self):
        test_suites = TestSuite('suite1', [TestCase('Test1')])

        try:
            TestSuite.to_xml_string(test_suites)
        except Exception as exc:
            self.assertEqual(str(exc), 'test_suites must be a list of test suites')
开发者ID:diarmuid,项目名称:python-junit-xml,代码行数:7,代码来源:test_junit_xml.py

示例4: generateJUnitReport

 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)
开发者ID:Light07,项目名称:PythonAutomation,代码行数:25,代码来源:Runner.py

示例5: run_everything_else

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
开发者ID:DarumasLegs,项目名称:alba,代码行数:26,代码来源:dev.py

示例6: main

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
开发者ID:4m1g0,项目名称:Arduino,代码行数:34,代码来源:runner.py

示例7: dump_junit_xml

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)
开发者ID:fxfactorial,项目名称:alba,代码行数:8,代码来源:alba.py

示例8: generate

 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)
开发者ID:JahanviB,项目名称:Zopkio,代码行数:11,代码来源:junit_reporter.py

示例9: take_action

    def take_action(self, args):
        test_cases = []
        if args.playbook is not None:
            playbooks = args.playbook
            results = (models.TaskResult().query
                       .join(models.Task)
                       .filter(models.TaskResult.task_id == models.Task.id)
                       .filter(models.Task.playbook_id.in_(playbooks)))
        else:
            results = models.TaskResult().query.all()

        for result in results:
            task_name = result.task.name
            if not task_name:
                task_name = result.task.action
            additional_results = {
                'host': result.host.name,
                'playbook_path': result.task.playbook.path
            }
            result_str = jsonutils.dumps(additional_results)
            test_path = \
                u'{playbook_file}.{play_name}'.format(
                    playbook_file=os.path.basename(result.task.playbook.path),
                    play_name=result.task.play.name)
            test_case = TestCase(
                name=task_name,
                classname=test_path,
                elapsed_sec=result.duration.seconds,
                stdout=result_str)
            if result.status == 'skipped':
                test_case.add_skipped_info(message=result.result)
            elif ((result.status in ('failed', 'unreachable') and
                    result.ignore_errors is False and
                    'EXPECTED FAILURE' not in task_name and
                    'TOGGLE RESULT' not in task_name) or
                    (result.status == 'ok' and 'TOGGLE RESULT' in task_name)):
                test_case.add_failure_info(message=result.result)
            test_cases.append(test_case)
        test_suite = TestSuite('Ansible Tasks', test_cases)

        # TODO: junit_xml doesn't order the TestCase parameters.
        # This makes it so the order of the parameters for the same exact
        # TestCase is not guaranteed to be the same and thus results in a
        # different stdout (or file). This is easily reproducible on Py3.
        xml_string = six.text_type(test_suite.to_xml_string([test_suite]))
        if args.output_file == '-':
            if six.PY2:
                sys.stdout.write(encodeutils.safe_encode(xml_string))
            else:
                sys.stdout.buffer.write(encodeutils.safe_encode(xml_string))
        else:
            with open(args.output_file, 'wb') as f:
                f.write(encodeutils.safe_encode(xml_string))
开发者ID:dmsimard,项目名称:ara,代码行数:53,代码来源:generate.py

示例10: Run

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])
开发者ID:nick-wang,项目名称:ha-clustering-auto,代码行数:51,代码来源:ctsTestCase.py

示例11: parse

def parse(infile, outfile, format_type, classname, suitename):
    testcases = list()
    testcase_logs = list()
    current = None
    test_block_delimiter = known_formats[format_type]['tb_delimiter']

    # separate log file into test blocks by test block delimiter
    for line in infile:
        if test_block_delimiter(line):
            if current: # non-empty list
                testcase_logs.append(current)
            current = list()
        if current is not None:
            current.append(line)

    # add last record if present
    if current not in testcase_logs:
        testcase_logs.append(current)

    # create test cases from test blocks
    for entry in testcase_logs:
        testcases.append(known_formats[format_type]['test_parser'](entry, classname))

    # generate test suite result using provided test cases
    test_suite = TestSuite(suitename, testcases)

    # get rid of unnecessary 'disabled' strings in formatted xml string
    s = TestSuite.to_xml_string([test_suite])
    s = s.replace(' disabled=\"0\"', '')

    # write xml to outfile
    outfile.write(s)
开发者ID:a-ilango,项目名称:libfabric,代码行数:32,代码来源:parse_results.py

示例12: exporter_junit_ioper

    def exporter_junit_ioper(self, test_result_ext, test_suite_properties=None):
        from junit_xml import TestSuite, TestCase

        test_suites = []
        test_cases = []

        for platform in sorted(test_result_ext.keys()):
            # {platform : ['Platform', 'Result', 'Scope', 'Description'])
            test_cases = []
            for tr_result in test_result_ext[platform]:
                result, name, scope, description = tr_result

                classname = "test.ioper.%s.%s.%s" % (platform, name, scope)
                elapsed_sec = 0
                _stdout = description
                _stderr = ""
                # Test case
                tc = TestCase(name, classname, elapsed_sec, _stdout, _stderr)
                # Test case extra failure / error info
                if result == "FAIL":
                    tc.add_failure_info(description, _stdout)
                elif result == "ERROR":
                    tc.add_error_info(description, _stdout)
                elif result == "SKIP" or result == "NOT_SUPPORTED":
                    tc.add_skipped_info(description, _stdout)

                test_cases.append(tc)
            ts = TestSuite("test.suite.ioper.%s" % (platform), test_cases)
            test_suites.append(ts)
        return TestSuite.to_xml_string(test_suites)
开发者ID:jaustin,项目名称:mbed,代码行数:30,代码来源:test_exporters.py

示例13: exporter_junit

def exporter_junit(test_result_ext, test_suite_properties=None):
    """! Export test results in JUnit XML compliant format
    @details This function will import junit_xml library to perform report conversion
    @return String containing Junit XML formatted test result output
    """
    from junit_xml import TestSuite, TestCase

    test_suites = []
    test_cases = []

    targets = sorted(test_result_ext.keys())
    for target in targets:
        test_cases = []
        tests = sorted(test_result_ext[target].keys())
        for test in tests:
            test_results = test_result_ext[target][test]
            classname = 'test.%s.%s' % (target, test)
            elapsed_sec = test_results['elapsed_time']
            _stdout = test_results['single_test_output']
            _stderr = ''
            # Test case
            tc = TestCase(test, classname, elapsed_sec, _stdout, _stderr)
            # Test case extra failure / error info
            if test_results['single_test_result'] == 'FAIL':
                message = test_results['single_test_result']
                tc.add_failure_info(message, _stdout)
            elif test_results['single_test_result'] != 'OK':
                message = test_results['single_test_result']
                tc.add_error_info(message, _stdout)

            test_cases.append(tc)
        ts = TestSuite("test.suite.%s" % target, test_cases)
        test_suites.append(ts)
    return TestSuite.to_xml_string(test_suites)
开发者ID:pombredanne,项目名称:greentea,代码行数:34,代码来源:mbed_report_api.py

示例14: _test

def _test():
    test_case1 = TestCase('Testname1', 'SetupCluster.Name')
    test_case2 = TestCase('Testname2', 'SetupCluster.Name')
    test_case3 = TestCase('Testname3', 'SetupCluster.Misc')
    test_case4 = TestCase('Testname4', 'SetupCluster.Misc')

    test_cases = [test_case1, test_case2, test_case3, test_case4]
    ts = TestSuite("My Test Suite", test_cases)

    #Run and verify test case
    assertCase(test_case1, _exampleFunc(True))
    assertCase(test_case2, _exampleFunc(False))
    assertCase(test_case3, _exampleFunc(True))
    #Skip test case
    skipCase(test_case4, "Skip Testname4.", "Testname2 is failed.")

    print(ts.to_xml_string([ts]))
开发者ID:nick-wang,项目名称:ha-clustering-auto,代码行数:17,代码来源:libJunitXml.py

示例15: build_packages

    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])
开发者ID:akabos,项目名称:devpi-builder,代码行数:17,代码来源:cli.py


注:本文中的junit_xml.TestSuite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。