예제 #1
0
    def __run_powershell(self,
                         replCmd,
                         workingDir=".",
                         variables={},
                         printer=Printer()):
        if self.inputfile:
            printer.error("inputfile not allowed when shell = ", self.shell)
            return false
        inputData = str.encode(replCmd)
        subProcessRes = subprocess.run(
            ["powershell", "-NonInteractive", "-NoLogo"],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            input=inputData,
            cwd=workingDir,
            shell=False)
        if self.outputfile:
            outputfileFullPath = str(
                pathlib.PurePath(workingDir).joinpath(
                    replaceVariables(self.outputfile, variables)))
            ensure_dir(outputfileFullPath)
            with open(outputfileFullPath, "wb") as fh:
                fh.write(subProcessRes.stdout)

        res = True
        if (self.exitcode != None):
            res = subProcessRes.returncode == self.exitcode
            if not res:
                printer.error("different exitcode received:",
                              subProcessRes.returncode, "!=", self.exitcode,
                              "for command '" + str(replCmd) + "'")
        return res
예제 #2
0
def main():
    SignalHandler.init()
    args = parseArguments()
    scriptFiles = getScriptFiles(args.start, args.scriptName)
    testSuits = createTestSuits(scriptFiles, args.start)
    markTestSkipedByPattern(testSuits, args.pattern)
    genTestExecuter = [TestExecuter(ts, tc, args.upgradeScriptFile) for ts in testSuits for tc in ts.test_cases if not tc.is_skipped()]
    if (args.jobs == None): 
        runner = Serial(genTestExecuter, failfast=args.failfast)
    else: 
        runner = Parallel(genTestExecuter, failfast=args.failfast, max_workers = args.jobs)
    startTime = time.time()
    processStartTime = time.process_time()
    res = runner.run(".", printer = Printer(args.verbose != None))
    processTime = time.process_time() - processStartTime
    executionTime = time.time() - startTime
    if (args.failfast and res == False) or SignalHandler.failFast(): 
        for ts in testSuits: 
            for tc in ts.test_cases:
                if tc.elapsed_sec == None:
                    if (SignalHandler.failFast()):
                        tc.add_skipped_info("skipped due to " + SignalHandler.signalName())
                    else:
                        tc.add_skipped_info("skipped due to --failfast argument")
    report = getReport(testSuits, processTime, executionTime)
    Printer(args.verbose != None).print(report["text"])
    if (args.reportfile):
        ensure_dir(args.reportfile)
        with open(args.reportfile, "w") as fw:
            fw.write(TestSuite.to_xml_string(testSuits))
    exit(report["error"] > 0)
예제 #3
0
    def run(self, workingDir=".", variables={}, printer=Printer()):

        printer.verbose("Run:", self.cmd)
        replCmd = replaceVariables(self.cmd, variables)
        printer.verbose("cwd:", os.getcwd())
        printer.verbose("call:", replCmd)
        cmdNArgs = shlex.split(replCmd)

        if self.shell == "powershell":
            return self.__run_powershell(replCmd, workingDir, variables,
                                         printer)
        if self.shell == "cmd":
            return self.__run_cmd(replCmd, workingDir, variables, printer)
        if self.shell == "sh":
            return self.__run_sh(replCmd, workingDir, variables, printer)
        elif self.shell != None:
            printer.error("unknown shell ", self.shell)
            return false

        inputfileData = None
        if self.inputfile:
            with open(
                    pathlib.PurePath(workingDir).joinpath(
                        replaceVariables(self.inputfile, variables)),
                    "rb") as fh:
                inputfileData = fh.read()
        shell = (sys.platform == "win32")
        subProcessRes = subprocess.run(cmdNArgs,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       input=inputfileData,
                                       cwd=workingDir,
                                       shell=shell)
        if self.outputfile:
            outputfileFullPath = str(
                pathlib.PurePath(workingDir).joinpath(
                    replaceVariables(self.outputfile, variables)))
            ensure_dir(outputfileFullPath)
            with open(outputfileFullPath, "wb") as fh:
                fh.write(subProcessRes.stdout)

        res = True
        if (self.exitcode != None):
            res = subProcessRes.returncode == self.exitcode
            if not res:
                printer.error("different exitcode received:",
                              subProcessRes.returncode, "!=", self.exitcode,
                              "for command '" + str(replCmd) + "'")
        return res
예제 #4
0
 def run(self, workingDir="", variables={}, printer=Printer()):
     printer.verbose("Makedirs:", self.dir)
     _dir = replaceVariables(self.dir, variables, printer)
     _dir = str(pathlib.PurePath(workingDir).joinpath(_dir)) + "/"
     ensure_dir(_dir)
     return True