コード例 #1
0
ファイル: runner.py プロジェクト: BuzzBurrowes/Arduino
 def run_tests(self):
     test_cases = []
     for test in self.tests:
         desc = test['desc']
         name = test['name']
         index = test['id']
         test_case = TestCase(name, self.name)
         if '[.]' in desc:
             print('skipping test "{}"'.format(name))
             test_case.add_skipped_info(message="Skipped test marked with [.]")
         else:
             test_output = StringIO()
             self.sp.logfile = test_output
             t_start = time.time()
             result = self.run_test(index)
             t_stop = time.time()
             self.sp.logfile = None
             test_case.elapsed_sec = t_stop - t_start
             debug_print('test output was:')
             debug_print(test_output.getvalue())
             if result == BSTestRunner.SUCCESS:
                 test_case.stdout = test_output.getvalue()
                 print('test "{}" passed'.format(name))
             else:
                 print('test "{}" failed'.format(name))
                 test_case.add_failure_info('Test failed', output=test_output.getvalue())
             test_output.close()
         test_cases += [test_case];
     return TestSuite(self.name, test_cases)
コード例 #2
0
 def run_tests(self):
     test_cases = []
     should_update_env = True
     for test in self.tests:
         desc = test['desc']
         name = test['name']
         index = test['id']
         test_case = TestCase(name, self.name)
         if '[.]' in desc:
             print('skipping test "{}"'.format(name))
             test_case.add_skipped_info(
                 message="Skipped test marked with [.]")
         else:
             test_output = StringIO()
             self.sp.logfile = test_output
             print('running test "{}"'.format(name))
             if should_update_env:
                 res = self.update_env(self.env_vars)
                 if res != BSTestRunner.SUCCESS:
                     print('failed to set environment variables')
                     break
                 res = self.pretest()
                 if res != BSTestRunner.SUCCESS:
                     print('failed to run pretest init')
                     break
                 should_update_env = False
             if name in self.mocks:
                 debug_print('setting up mocks')
                 self.mocks[name]['request_env'] = self.request_env
                 self.mocks[name]['setup']()
                 extra_env = mock_decorators.get_all_envs(name)
                 if extra_env is not None:
                     self.update_env(extra_env)
             t_start = time.time()
             result = self.run_test(index)
             if name in self.mocks:
                 debug_print('tearing down mocks')
                 try:
                     self.mocks[name]['teardown']()
                 except AssertionError:
                     debug_print('teardown assert failure')
                     result = BSTestRunner.FAIL
             t_stop = time.time()
             self.sp.logfile = None
             test_case.elapsed_sec = t_stop - t_start
             debug_print('test output was:')
             debug_print(test_output.getvalue())
             if result == BSTestRunner.SUCCESS:
                 test_case.stdout = filter(lambda c: ord(c) < 128,
                                           test_output.getvalue())
                 print('test "{}" passed'.format(name))
             else:
                 print('test "{}" failed'.format(name))
                 test_case.add_failure_info('Test failed',
                                            output=test_output.getvalue())
                 should_update_env = True
             test_output.close()
         test_cases += [test_case]
     return TestSuite(self.name, test_cases)
コード例 #3
0
ファイル: runner.py プロジェクト: 4m1g0/Arduino
 def run_tests(self):
     test_cases = []
     should_update_env = True
     for test in self.tests:
         desc = test['desc']
         name = test['name']
         index = test['id']
         test_case = TestCase(name, self.name)
         if '[.]' in desc:
             print('skipping test "{}"'.format(name))
             test_case.add_skipped_info(message="Skipped test marked with [.]")
         else:
             test_output = StringIO()
             self.sp.logfile = test_output
             print('running test "{}"'.format(name))
             if should_update_env:
                 res = self.update_env(self.env_vars)
                 if res != BSTestRunner.SUCCESS:
                     print('failed to set environment variables')
                     break;
                 should_update_env = False
             if name in self.mocks:
                 debug_print('setting up mocks')
                 self.mocks[name]['request_env'] = self.request_env
                 self.mocks[name]['setup']()
                 extra_env = mock_decorators.get_all_envs(name)
                 if extra_env is not None:
                     self.update_env(extra_env)
             t_start = time.time()
             result = self.run_test(index)
             if name in self.mocks:
                 debug_print('tearing down mocks')
                 try:
                     self.mocks[name]['teardown']()
                 except AssertionError:
                     debug_print('teardown assert failure')
                     result = BSTestRunner.FAIL
             t_stop = time.time()
             self.sp.logfile = None
             test_case.elapsed_sec = t_stop - t_start
             debug_print('test output was:')
             debug_print(test_output.getvalue())
             if result == BSTestRunner.SUCCESS:
                 test_case.stdout = test_output.getvalue()
                 print('test "{}" passed'.format(name))
             else:
                 print('test "{}" failed'.format(name))
                 test_case.add_failure_info('Test failed', output=test_output.getvalue())
                 should_update_env = True
             test_output.close()
         test_cases += [test_case];
     return TestSuite(self.name, test_cases)
コード例 #4
0
ファイル: report_utils.py プロジェクト: InbarRose/irtools
def create_junit_results(data, output=None, **kwargs):
    """
    Creates a Junit result, can write to a file if desired, or return xml string. (used by Jenkins)
    input either dict(dict(dict())) or dict(list(dict()))
    dict = {suite: {test: {stderr,stdout,time,class,err,fail,skip}}}
    list = {suite: [(test, {stderr,stdout,time,class,err,fail,skip})]}
    :param data: A dictionary with dict or list hierarchy
    :param output: A filename to write results to  /path/to/file/*.junit.xml
    :return: Returns an XML string if no output, else nothing.
    """
    log.debug('creating junit results: output={}'.format(output))
    stdout_format = kwargs.pop('stdout_format', None)
    test_class = kwargs.pop('test_class', None)
    package = kwargs.pop('package', None)
    from junit_xml import TestSuite, TestCase
    test_suites = []
    for suite, tests in data.items():
        test_cases = []
        for test, result in (tests if isinstance(tests, list) else tests.items()):
            tc = TestCase(test)
            stdout = result.get('stdout')
            if stdout_format is not None and callable(stdout_format):
                if hasattr(stdout_format, 'func_code') and 'kwargs' in stdout_format.func_code.co_varnames:
                    stdout = stdout_format(stdout, suite_name=suite, test_name=test, **kwargs)
                else:
                    stdout = stdout_format(stdout)
            tc.stdout = stdout
            tc.stderr = result.get('stderr')
            tc.elapsed_sec = result.get('time')
            tc.classname = result.get('class', test_class)
            err = result.get('err')
            if err:
                tc.add_error_info(*err if isinstance(err, (list, tuple)) else [err])
            fail = result.get('fail')
            if fail:
                tc.add_failure_info(*fail if isinstance(fail, (list, tuple)) else [fail])
            skip = result.get('skip')
            if skip:
                tc.add_skipped_info(*skip if isinstance(skip, (list, tuple)) else [skip])
            test_cases.append(tc)
        ts = TestSuite(suite, test_cases, package=package)
        test_suites.append(ts)

    if output:
        check_makedir(os.path.dirname(output))
        with open(output, 'w') as out:
            TestSuite.to_file(out, test_suites)
        return output
    else:
        return TestSuite.to_xml_string(test_suites)
コード例 #5
0
def getSLATestSuites(test, group, sla):
    #pprint(vars(sla))

    slaprofile = sla.element.category  #"SLANAME"
    userpath = "" if sla.element.userpath is None else sla.element.userpath
    suitename = "com.neotys." + slaprofile + "." + group + (
        "" if userpath == "" else "." + userpath)
    testname = sla.kpi
    tc = TestCase(testname, suitename)
    if sla.status == "PASSED":
        tc.stdout = ""  #"Value is " + str(sla.value)
    elif sla.status == "FAILED":
        txt = getSLAJUnitText(test, group.lower(), sla, slaprofile, userpath)
        tc.add_error_info("SLA failed", txt, 'NeoLoad SLA')
    elif sla.status == "WARNING":
        txt = getSLAJUnitText(test, group.lower(), sla, slaprofile, userpath)
        #tc.add_error_info("SLA failed",txt,'NeoLoad SLA')
    else:
        logging.warning("Unknown sla.status value: " + sla.status)

    return TestSuite(suitename, [tc])
コード例 #6
0
def map_yaml_to_junit(test):
    yaml = test.yaml or {}
    # Even though the name is `duration_ms` the value is in seconds.
    elapsed_sec = yaml.get('duration_ms', None)
    t = TestCase(test.description, classname=None, elapsed_sec=elapsed_sec)
    if test.result == 'ok':
        if test.directive in ['SKIP', 'TODO']:
            t.add_skipped_info(test.comment)
        else:
            t.stdout = test.comment

    elif test.result == 'not ok':
        err_code = yaml.get('exitcode', 0)
        err_severity = yaml.get('severity', '')
        err_output = yaml.get('stack', '')
        error_message = "{} ({})".format(err_severity, err_code)
        if err_severity == 'crashed' or err_code < 0:
            t.add_error_info(error_message, err_output, err_code)
        else:
            t.add_failure_info(error_message, err_output, err_code)

    return t
コード例 #7
0
def map_yaml_to_junit(test):
    yaml = test.yaml or {}
    # Even though the name is `duration_ms` the value is in seconds.
    elapsed_sec = yaml.get("duration_ms", None)
    t = TestCase(test.description, classname=None, elapsed_sec=elapsed_sec)
    if test.result == "ok":
        if test.directive in ("SKIP", "TODO"):
            t.add_skipped_info(test.comment)
        else:
            t.stdout = test.comment

    elif test.result == "not ok":
        err_code = yaml.get("exitcode", 0)
        err_severity = yaml.get("severity", "")
        err_output = yaml.get("stack", "")
        error_message = f"{err_severity} ({err_code})"
        if err_code < 0 or err_severity == "crashed":
            t.add_error_info(error_message, err_output, err_code)
        else:
            t.add_failure_info(error_message, err_output, err_code)
        t.stderr = test.diagnostics
    return t
コード例 #8
0
    def test(self):
        def Trim(string):
            if len(string) > 4096:
                return string[:4096] + " ..."
            else:
                return string

        varsdict = {}
        self.log("Assigning variables:")
        for var in self.variables:
            tmpdict = {}
            try:
                var.run(tmpdict)
            except:
                self.log("failure.")
                self.pass_status.append('F')
                return self.pass_status

            varsdict[var.name] = tmpdict[var.name]
            self.log("Assigning %s = %s" %
                     (str(var.name), Trim(str(varsdict[var.name]))))

        if len(self.pass_tests) != 0:
            self.log("Running failure tests: ")
            for test in self.pass_tests:
                self.log("Running %s:" % test.name)
                log = StringIO()
                original_stdout = sys.stdout
                sys.stdout = log
                status = test.run(varsdict)
                tc = TestCase(test.name,
                              '%s.%s' % (self.length, self.filename[:-4]))
                if status == True:
                    self.log("success.")
                    self.pass_status.append('P')
                elif status == False:
                    self.log("failure.")
                    self.pass_status.append('F')
                    tc.add_failure_info("Failure")
                else:
                    self.log("failure (info == %s)." % status)
                    self.pass_status.append('F')
                    tc.add_failure_info("Failure", status)
                self.xml_reports.append(tc)
                sys.stdout = original_stdout
                log.seek(0)
                tc.stdout = log.read()
                print(tc.stdout)

        if len(self.warn_tests) != 0:
            self.log("Running warning tests: ")
            for test in self.warn_tests:
                self.log("Running %s:" % test.name)
                status = test.run(varsdict)
                if status == True:
                    self.log("success.")
                    self.warn_status.append('P')
                elif status == False:
                    self.log("warning.")
                    self.warn_status.append('W')
                else:
                    self.log("warning (info == %s)." % status)
                    self.warn_status.append('W')

        self.log(''.join(self.pass_status + self.warn_status))
        return self.pass_status + self.warn_status
コード例 #9
0
ファイル: template.py プロジェクト: usharesoft/hammr
    def do_build(self, args):
        try:
            # add arguments
            doParser = self.arg_build()
            doArgs = doParser.parse_args(shlex.split(args))

            # if the help command is called, parse_args returns None object
            if not doArgs:
                return 2

            # --
            template = validate(doArgs.file)
            if template is None:
                return 2

            if doArgs.id:
                myAppliance = self.api.Users(self.login).Appliances().Getall(Query="dbId==" + doArgs.id)
                myAppliance = myAppliance.appliances.appliance
            else:
                # Get template which correpond to the template file
                myAppliance = (
                    self.api.Users(self.login)
                    .Appliances()
                    .Getall(
                        Query="name=='"
                        + template["stack"]["name"]
                        + "';version=='"
                        + template["stack"]["version"]
                        + "'"
                    )
                )
                myAppliance = myAppliance.appliances.appliance
            if myAppliance is None or len(myAppliance) != 1:
                printer.out("No template found on the plateform")
                return 0
            myAppliance = myAppliance[0]
            rInstallProfile = self.api.Users(self.login).Appliances(myAppliance.dbId).Installprofile("").Getdeprecated()
            if rInstallProfile is None:
                printer.out("No installation found on the template '" + template["stack"]["name"] + "'", printer.ERROR)
                return 0
            try:
                i = 1
                if doArgs.junit is not None:
                    test_results = []
                for builder in template["builders"]:
                    try:
                        printer.out(
                            "Generating '"
                            + builder["type"]
                            + "' image ("
                            + str(i)
                            + "/"
                            + str(len(template["builders"]))
                            + ")"
                        )
                        if doArgs.junit is not None:
                            test = TestCase("Generation " + builder["type"])
                            test_results.append(test)
                            start_time = time.time()

                        format_type = builder["type"]
                        targetFormat = generate_utils.get_target_format_object(self.api, self.login, format_type)
                        if targetFormat is None:
                            printer.out("Builder type unknown: " + format_type, printer.ERROR)
                            return 2

                        myimage = image()
                        myinstallProfile = installProfile()
                        if rInstallProfile.partitionAuto:
                            if "installation" in builder:
                                if "swapSize" in builder["installation"]:
                                    myinstallProfile.swapSize = builder["installation"]["swapSize"]
                                if "diskSize" in builder["installation"]:
                                    myinstallProfile.diskSize = builder["installation"]["diskSize"]
                            else:
                                myinstallProfile.swapSize = rInstallProfile.swapSize
                                myinstallProfile.diskSize = rInstallProfile.partitionTable.disks.disk[0].size

                        func = getattr(
                            generate_utils,
                            "generate_" + generics_utils.remove_special_chars(targetFormat.format.name),
                            None,
                        )
                        if func:
                            myimage, myinstallProfile = func(myimage, builder, myinstallProfile, self.api, self.login)
                        else:
                            printer.out("Builder type unknown: " + format_type, printer.ERROR)
                            return 2

                        if myimage is None:
                            return 2

                        myimage.targetFormat = targetFormat
                        myimage.installProfile = myinstallProfile
                        if doArgs.simulated is not None and doArgs.simulated:
                            myimage.simulated = True
                        if doArgs.forced is not None and doArgs.forced:
                            myimage.forceCheckingDeps = True

                        rImage = self.api.Users(self.login).Appliances(myAppliance.dbId).Images().Generate(myimage)

                        status = rImage.status
                        statusWidget = progressbar_widget.Status()
                        statusWidget.status = status
                        widgets = [Bar(">"), " ", statusWidget, " ", ReverseBar("<")]
                        progress = ProgressBar(widgets=widgets, maxval=100).start()
                        while not (status.complete or status.error or status.cancelled):
                            statusWidget.status = status
                            progress.update(status.percentage)
                            status = (
                                self.api.Users(self.login).Appliances(myAppliance.dbId).Images(rImage.dbId).Status.Get()
                            )
                            time.sleep(2)
                        statusWidget.status = status
                        progress.finish()
                        if status.error:
                            printer.out(
                                "Generation '"
                                + builder["type"]
                                + "' error: "
                                + status.message
                                + "\n"
                                + status.errorMessage,
                                printer.ERROR,
                            )
                            if status.detailedError:
                                printer.out(status.detailedErrorMsg)
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                test.add_error_info("Error", status.message + "\n" + status.errorMessage)
                        elif status.cancelled:
                            printer.out(
                                "Generation '" + builder["type"] + "' canceled: " + status.message, printer.WARNING
                            )
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                test.add_failure_info("Canceled", status.message)
                        else:
                            printer.out("Generation '" + builder["type"] + "' ok", printer.OK)
                            printer.out("Image URI: " + rImage.uri)
                            printer.out("Image Id : " + generics_utils.extract_id(rImage.uri))
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                # the downloadUri already contains downloadKey at the end
                                if rImage.downloadUri is not None:
                                    test.stdout = self.api._url + "/" + rImage.downloadUri
                        i += 1
                    except Exception as e:
                        if is_uforge_exception(e):
                            print_uforge_exception(e)
                            if doArgs.junit is not None and "test_results" in locals() and len(test_results) > 0:
                                test = test_results[len(test_results) - 1]
                                test.elapsed_sec = time.time() - start_time
                                test.add_error_info("Error", get_uforge_exception(e))
                        else:
                            raise
                if doArgs.junit is not None:
                    testName = myAppliance.distributionName + " " + myAppliance.archName
                    ts = TestSuite("Generation " + testName, test_results)
                    with open(doArgs.junit, "w") as f:
                        TestSuite.to_file(f, [ts], prettyprint=False)
                return 0
            except KeyError as e:
                printer.out("unknown error in template file", printer.ERROR)

        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
            self.help_build()
        except KeyboardInterrupt:
            printer.out("\n")
            if generics_utils.query_yes_no("Do you want to cancel the job ?"):
                if (
                    "myAppliance" in locals()
                    and "rImage" in locals()
                    and hasattr(myAppliance, "dbId")
                    and hasattr(rImage, "dbId")
                ):
                    self.api.Users(self.login).Appliances(myAppliance.dbId).Images(rImage.dbId).Status.Cancel()
                else:
                    printer.out("Impossible to cancel", printer.WARNING)
            else:
                printer.out("Exiting command")
        except Exception as e:
            print_uforge_exception(e)
            if doArgs.junit is not None and "test_results" in locals() and len(test_results) > 0:
                test = test_results[len(test_results) - 1]
                if "start_time" in locals():
                    elapse = time.time() - start_time
                else:
                    elapse = 0
                test.elapsed_sec = elapse
                test.add_error_info("Error", get_uforge_exception(e))
            else:
                return 2
        finally:
            if (
                "doArgs" in locals()
                and doArgs.junit is not None
                and "test_results" in locals()
                and len(test_results) > 0
            ):
                if "myAppliance" in locals():
                    testName = myAppliance.distributionName + " " + myAppliance.archName
                else:
                    testName = ""
                ts = TestSuite("Generation " + testName, test_results)
                with open(doArgs.junit, "w") as f:
                    TestSuite.to_file(f, [ts], prettyprint=False)
コード例 #10
0
ファイル: template.py プロジェクト: sferot/hammr
    def do_build(self, args):
        try:
            #add arguments
            doParser = self.arg_build()
            doArgs = doParser.parse_args(shlex.split(args))

            #if the help command is called, parse_args returns None object
            if not doArgs:
                return 2

            #--
            template = validate(doArgs.file)
            if template is None:
                return 2

            if doArgs.id:
                myAppliance = self.api.Users(
                    self.login).Appliances().Getall(Query="dbId==" + doArgs.id)
                myAppliance = myAppliance.appliances.appliance
            else:
                #Get template which correpond to the template file
                myAppliance = self.api.Users(self.login).Appliances().Getall(
                    Query="name=='" + template["stack"]["name"] +
                    "';version=='" + template["stack"]["version"] + "'")
                myAppliance = myAppliance.appliances.appliance
            if myAppliance is None or len(myAppliance) != 1:
                printer.out("No template found on the plateform")
                return 0
            myAppliance = myAppliance[0]
            rInstallProfile = self.api.Users(self.login).Appliances(
                myAppliance.dbId).Installprofile("").Getdeprecated()
            if rInstallProfile is None:
                printer.out(
                    "No installation found on the template '" +
                    template["stack"]["name"] + "'", printer.ERROR)
                return 0
            try:
                i = 1
                if doArgs.junit is not None:
                    test_results = []
                for builder in template["builders"]:
                    try:
                        printer.out("Generating '" + builder["type"] +
                                    "' image (" + str(i) + "/" +
                                    str(len(template["builders"])) + ")")
                        if doArgs.junit is not None:
                            test = TestCase('Generation ' + builder["type"])
                            test_results.append(test)
                            start_time = time.time()

                        format_type = builder["type"]
                        targetFormat = generate_utils.get_target_format_object(
                            self.api, self.login, format_type)
                        if targetFormat is None:
                            printer.out("Builder type unknown: " + format_type,
                                        printer.ERROR)
                            return 2

                        myimage = image()
                        myinstallProfile = installProfile()
                        if rInstallProfile.partitionAuto:
                            if "installation" in builder:
                                if "swapSize" in builder["installation"]:
                                    myinstallProfile.swapSize = builder[
                                        "installation"]["swapSize"]
                                if "diskSize" in builder["installation"]:
                                    myinstallProfile.diskSize = builder[
                                        "installation"]["diskSize"]
                            else:
                                myinstallProfile.swapSize = rInstallProfile.swapSize
                                myinstallProfile.diskSize = rInstallProfile.partitionTable.disks.disk[
                                    0].size

                        func = getattr(
                            generate_utils,
                            "generate_" + generics_utils.remove_special_chars(
                                targetFormat.format.name), None)
                        if func:
                            myimage, myinstallProfile = func(
                                myimage, builder, myinstallProfile, self.api,
                                self.login)
                        else:
                            printer.out("Builder type unknown: " + format_type,
                                        printer.ERROR)
                            return 2

                        if myimage is None:
                            return 2

                        myimage.targetFormat = targetFormat
                        myimage.installProfile = myinstallProfile
                        if doArgs.simulated is not None and doArgs.simulated:
                            myimage.simulated = True
                        if doArgs.forced is not None and doArgs.forced:
                            myimage.forceCheckingDeps = True

                        rImage = self.api.Users(self.login).Appliances(
                            myAppliance.dbId).Images().Generate(myimage)

                        status = rImage.status
                        statusWidget = progressbar_widget.Status()
                        statusWidget.status = status
                        widgets = [
                            Bar('>'), ' ', statusWidget, ' ',
                            ReverseBar('<')
                        ]
                        progress = ProgressBar(widgets=widgets,
                                               maxval=100).start()
                        while not (status.complete or status.error
                                   or status.cancelled):
                            statusWidget.status = status
                            progress.update(status.percentage)
                            status = self.api.Users(self.login).Appliances(
                                myAppliance.dbId).Images(
                                    rImage.dbId).Status.Get()
                            time.sleep(2)
                        statusWidget.status = status
                        progress.finish()
                        if status.error:
                            printer.out(
                                "Generation '" + builder["type"] +
                                "' error: " + status.message + "\n" +
                                status.errorMessage, printer.ERROR)
                            if status.detailedError:
                                printer.out(status.detailedErrorMsg)
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                test.add_error_info(
                                    "Error", status.message + "\n" +
                                    status.errorMessage)
                        elif status.cancelled:
                            printer.out(
                                "Generation '" + builder["type"] +
                                "' canceled: " + status.message,
                                printer.WARNING)
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                test.add_failure_info("Canceled",
                                                      status.message)
                        else:
                            printer.out(
                                "Generation '" + builder["type"] + "' ok",
                                printer.OK)
                            printer.out("Image URI: " + rImage.uri)
                            printer.out("Image Id : " +
                                        generics_utils.extract_id(rImage.uri))
                            if doArgs.junit is not None:
                                test.elapsed_sec = time.time() - start_time
                                #the downloadUri already contains downloadKey at the end
                                if rImage.downloadUri is not None:
                                    test.stdout = self.api.getUrl(
                                    ) + "/" + rImage.downloadUri
                        i += 1
                    except Exception as e:
                        if is_uforge_exception(e):
                            print_uforge_exception(e)
                            if doArgs.junit is not None and "test_results" in locals(
                            ) and len(test_results) > 0:
                                test = test_results[len(test_results) - 1]
                                test.elapsed_sec = time.time() - start_time
                                test.add_error_info("Error",
                                                    get_uforge_exception(e))
                        else:
                            raise
                if doArgs.junit is not None:
                    testName = myAppliance.distributionName + " " + myAppliance.archName
                    ts = TestSuite("Generation " + testName, test_results)
                    with open(doArgs.junit, 'w') as f:
                        TestSuite.to_file(f, [ts], prettyprint=False)
                return 0
            except KeyError as e:
                printer.out("unknown error in template file", printer.ERROR)

        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
            self.help_build()
        except KeyboardInterrupt:
            printer.out("\n")
            if generics_utils.query_yes_no("Do you want to cancel the job ?"):
                if 'myAppliance' in locals() and 'rImage' in locals(
                ) and hasattr(myAppliance, 'dbId') and hasattr(rImage, 'dbId'):
                    self.api.Users(self.login).Appliances(
                        myAppliance.dbId).Images(rImage.dbId).Status.Cancel()
                else:
                    printer.out("Impossible to cancel", printer.WARNING)
            else:
                printer.out("Exiting command")
        except Exception as e:
            print_uforge_exception(e)
            if doArgs.junit is not None and "test_results" in locals(
            ) and len(test_results) > 0:
                test = test_results[len(test_results) - 1]
                if "start_time" in locals():
                    elapse = time.time() - start_time
                else:
                    elapse = 0
                test.elapsed_sec = elapse
                test.add_error_info("Error", get_uforge_exception(e))
            else:
                return 2
        finally:
            if "doArgs" in locals(
            ) and doArgs.junit is not None and "test_results" in locals(
            ) and len(test_results) > 0:
                if "myAppliance" in locals():
                    testName = myAppliance.distributionName + " " + myAppliance.archName
                else:
                    testName = ""
                ts = TestSuite("Generation " + testName, test_results)
                with open(doArgs.junit, 'w') as f:
                    TestSuite.to_file(f, [ts], prettyprint=False)
コード例 #11
0
def test_availible_endpoints(output):

    s = Settings([
        'PLATFORM', 'ENVIRONMENT', 'SERVICEURL', 'WSDLURL', "CONSUMERHSAID",
        "CERTFILE"
    ])
    test_cases = []

    cache = SqliteCache(path='/tmp/_gcdrunner_sqlite.db', timeout=60 * 24 * 7)

    session = requests.Session()
    #session.verify = False
    #session.cert=s.CERTFILE

    transport = Transport(session=session, cache=cache)
    client = Client(s.WSDLURL, transport=transport)
    service = client.create_service(client.service._binding.name.text,
                                    s.SERVICEURL)

    session.verify = False
    session.cert = s.CERTFILE

    pid_fact = client.type_factory('ns2')
    adr_fact = client.type_factory('ns5')
    pid_t = pid_fact.PersonIdType('191212121212', '1.2.752.129.2.1.3.1')
    connectionPointId = get_connection_point_id(s.PLATFORM, s.ENVIRONMENT)

    requests.packages.urllib3.disable_warnings()
    endpoints = get_tak_la_for_tk(connectionPointId, s.CONSUMERHSAID)
    endpoints = list(
        filter(lambda e: e["logicalAddress"] not in IGNORE_LA_LIST, endpoints))
    endpoints.sort(key=lambda e: e["description"])
    for endpoint in endpoints:
        testname = "{} ({})".format(endpoint["description"],
                                    endpoint["logicalAddress"])

        print("Running test: {}".format(testname))
        logicalAddress_t = adr_fact.LogicalAddressType(
            endpoint['logicalAddress'])

        tc = TestCase(name=testname)
        tc.stdout = "Testing Logical address: {},  with id: {},  description: {}".format(
            endpoint['logicalAddress'], endpoint['id'],
            endpoint['description'])

        try:
            start = time.time()
            response = service.GetCareDocumentation(
                patientId=pid_t,
                _soapheaders={'LogicalAddress': logicalAddress_t})
            tc.elapsed_sec = time.time() - start
            tc.stdout = repr(response['result'])
        except Exception as e:
            tc.stderr = str(e)
            failtype = None
            if tc.stderr.startswith("VP"):
                failtype = tc.stderr.split()[0]
            tc.add_failure_info(output=str(e), failure_type=failtype)
        test_cases.append(tc)

    ts = TestSuite("Spider TK tests for TK: " + TKNS, test_cases)
    with open(output, 'w') as f:
        TestSuite.to_file(f, [ts])
コード例 #12
0
    def test(self):
        def Trim(string):
          if len(string) > 4096:
            return string[:4096] + " ..."
          else:
            return string
    
        varsdict = {}
        self.log("Assigning variables:")
        for var in self.variables:
            tmpdict  = {}
            try:
              var.run(tmpdict)
            except:
              self.log("failure.")
              self.pass_status.append('F')
              tc=TestCase(self.name,
                          '%s.%s'%(self.length,
                                   self.filename[:-4]))
              tc.add_failure_info("Failure" )
              self.xml_reports.append(tc)
              return self.pass_status

            varsdict[var.name] = tmpdict[var.name]
            self.log("Assigning %s = %s" % (str(var.name), Trim(str(varsdict[var.name]))))

        if len(self.pass_tests) != 0:
            self.log("Running failure tests: ")
            for test in self.pass_tests:
                self.log("Running %s:" % test.name)
                log = StringIO()
                original_stdout = sys.stdout
                sys.stdout = log
                status = test.run(varsdict)
                tc=TestCase(test.name,
                            '%s.%s'%(self.length,
                                     self.filename[:-4]))
                if status == True:
                    self.log("success.")
                    self.pass_status.append('P')
                elif status == False:
                    self.log("failure.")
                    self.pass_status.append('F')
                    tc.add_failure_info(  "Failure" )
                else:
                    self.log("failure (info == %s)." % status)
                    self.pass_status.append('F')
                    tc.add_failure_info(  "Failure", status )
                self.xml_reports.append(tc)
                sys.stdout = original_stdout
                log.seek(0)
                tc.stdout = log.read()
                print(tc.stdout)

        if len(self.warn_tests) != 0:
            self.log("Running warning tests: ")
            for test in self.warn_tests:
                self.log("Running %s:" % test.name)
                status = test.run(varsdict)
                if status == True:
                    self.log("success.")
                    self.warn_status.append('P')
                elif status == False:
                    self.log("warning.")
                    self.warn_status.append('W')
                else:
                    self.log("warning (info == %s)." % status)
                    self.warn_status.append('W')

        self.log(''.join(self.pass_status + self.warn_status))
        return self.pass_status + self.warn_status
コード例 #13
0
def unittest_harness(tests, xml_outfile):
    xml_parser = TestSuite('unittest_harness')
    tests_results = {'Pass': Counter(), 'Warn': Counter(), 'Fail': Counter()}
    error_list, skip_list = [], []

    for test in tests:
        print(f'\t-> New test: {test.name}')

        if (tests_dir / test.name).is_file() is False:
            print(f'WARNING: {test.name} not found')
            skip_list.append(test.name)
            xml_entry = TestCase('',
                                 classname=test.name,
                                 elapsed_sec='None',
                                 status='Skipped')
            xml_entry.add_skipped_info(message='Not found')
            xml_parser.test_cases.append(xml_entry)
            continue

        test_id = f'unittest.{test.resolve().parts[-3]}.{test.name}'

        try:
            begin = process_time()
            test_proc = subprocess.run('./' + test.name,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=True,
                                       cwd=test.parent,
                                       check=True,
                                       encoding='utf-8')
            wall_time = process_time() - begin
        except subprocess.CalledProcessError as test_error:
            print(f'ERROR: {test.name} exited with a non-zero exit code.')
            print(f'Exit status: {test_error.returncode}')
            print(f'Output: {test_error.output}')
            print(f'Stderr output: {test_error.stderr}')
            error_list.append(test.name)
            xml_entry = TestCase('',
                                 classname=test_id,
                                 elapsed_sec=process_time() - begin,
                                 status='Error')
            xml_entry.add_error_info(message=test_error.stderr)
            xml_parser.test_cases.append(xml_entry)
            continue

        other_out = ''
        for test_output in test_proc.stdout.splitlines():
            try:
                tests_results[test_output[:4]][test.name] += 1
            except KeyError:
                print(f'\t\t\t{test_output.lstrip()}')
                other_out += test_output.lstrip() + '\n'
                continue

            print(f'\t\t{test_output}')

            try:
                # Look for the test output message enclosed between brackets
                test_msg = re.search(r'(?<=\[).+(?=\])', test_output).group()
            except AttributeError:
                # If brackets are missing, extract output message
                # independently of an eventual error message
                test_msg = test_output[6:].split('; error:')[0]

            xml_entry = TestCase(test_msg,
                                 classname=test_id,
                                 elapsed_sec=wall_time,
                                 status=test_output[:4])

            try:
                fail_msg = re.search('(?<=error:).+', test_output).group()
                if not fail_msg.lstrip():
                    fail_msg += 'Empty message'
                if test_output[:4] == 'Warn':
                    xml_entry.add_failure_info(message=fail_msg.lstrip(),
                                               failure_type='warning')
                else:
                    xml_entry.add_failure_info(message=fail_msg.lstrip())
            except AttributeError:
                pass

            if test_proc.stderr:
                xml_entry.stderr = test_proc.stderr

            if other_out:
                xml_entry.stdout = other_out[:-1]
                other_out = ''

            xml_parser.test_cases.append(xml_entry)

    display_results(tests_results, error_list, skip_list)

    with open(xml_outfile, 'w') as fid:
        xml_parser.to_file(fid, [xml_parser])