Exemplo n.º 1
0
    def validateTimingsForSubprocessCall(
                self,
                testName,
                subprocessArgs,
                meta,
                timeout = 600.0
                ):
        resultCode, out, err = SubprocessRunner.callAndReturnResultAndOutput(
            subprocessArgs,
            timeout = timeout
            )


        if resultCode != 0:
            meta.update({"failure": "subprocess call returned error"})

            if PerformanceTestReporter.isCurrentlyTesting():
                PerformanceTestReporter.recordTest(
                    testName,
                    None,
                    meta
                    )

        assert resultCode == 0, err

        logging.info("Actual time was %s for %s", out[0], subprocessArgs)

        measuredTiming = float(out[0]) / self.baseTiming

        if PerformanceTestReporter.isCurrentlyTesting():
            PerformanceTestReporter.recordTest(
                "fora_lang." + testName,
                float(out[0]),
                meta
                )
Exemplo n.º 2
0
    def test_tracebacks(self):
        traceback_test_notebook_path = \
            os.path.join(self.cur_dir, "traceback_test.ipynb")

        returnCode, output, _ = SubprocessRunner.callAndReturnResultAndOutput(
            ['jupyter', 'nbconvert', '--stdout', '--to=markdown',
             '--ExecutePreprocessor.enabled=True', '--allow-errors',
             traceback_test_notebook_path])

        outputString = "".join(output)

        self.assertEqual(returnCode, 0)

        pattern = ".*ValueError\\s*Traceback \\(most recent call last\\)" \
                  ".*<ipython-input-4-[a-f0-9]{12}> in inner\\(\\)" \
                  "\\s*1 with e\\.remotely\\.downloadAll\\(\\):" \
                  "\\s*2\\s* 1\\+2\\+3" \
                  "\\s*----> 3\\s*res = f\\(0\\)" \
                  "\\s*<ipython-input-3-[a-f0-9]{12}> in f\\(\\)" \
                  "\\s*1 def f\\(x\\):" \
                  "\\s*----> 2\\s*return g\\(x\\) \\+ 1" \
                  "\\s*<ipython-input-2-[a-f0-9]{12}> in g\\(\\)" \
                  "\\s*1 def g\\(x\\):" \
                  "\\s*----> 2\\s* return 1 / math\\.sqrt\\(x - 1\\)" \
                  "\\s*/volumes/src/packages/python/pyfora/pure_modules/pure_math.py" \
                  " in __call__\\(\\)" \
                  "\\s*21\\s*def __call__\\(self, val\\):" \
                  "\\s*22\\s*if val < 0\\.0:" \
                  "\\s*---> 23\\s*raise ValueError\\(\"math domain error\"\\)" \
                  "\\s*24" \
                  "\\s*25\\s* return val \\*\\* 0.5" \
                  "\\s*ValueError: math domain error"        
        
        match = re.match(pattern, outputString, re.DOTALL)
        self.assertIsNotNone(match)
Exemplo n.º 3
0
def runSomeFora():
    args = [
        "/usr/local/bin/python", ufora.rootPythonPath + "/test.py", "-lang",
        "-langfilter=classTests.fora"
    ]
    returnCode, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(
        args)
    assert returnCode == 0
Exemplo n.º 4
0
def assertPrints(expression, expectedResult):
    returnCode, output, err = SubprocessRunner.callAndReturnResultAndOutput(
        ["fora", "-e", expression])

    output = [l.strip() for l in output if l.strip()]

    assert returnCode == 0
    assert output == [expectedResult], \
        "Evaluating:\n\t%s\n\nExpected %s, got %s" % (expression, [expectedResult], output)
Exemplo n.º 5
0
def assertPrints(expression, expectedResult):
    returnCode, output, err = SubprocessRunner.callAndReturnResultAndOutput(
        ["fora", "-e", expression ]
        )

    output = [l.strip() for l in output if l.strip()]

    assert returnCode == 0
    assert output == [expectedResult], \
        "Evaluating:\n\t%s\n\nExpected %s, got %s" % (expression, [expectedResult], output)
Exemplo n.º 6
0
    def setUpClass(cls):
        cls.shrinkwrapPath = tempfile.mkdtemp()

        result, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(
            ["ufora/scripts/shrinkwrap.py", "--source", rootPythonPath, 
             "--dest", cls.shrinkwrapPath],
            timeout = 240.0,
            env=None
            )

        assert result == 0, (result, stdOut, stdErr)
Exemplo n.º 7
0
    def setUpClass(cls):
        cls.shrinkwrapPath = tempfile.mkdtemp()

        result, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(
            [
                "ufora/scripts/shrinkwrap.py", "--source", rootPythonPath,
                "--dest", cls.shrinkwrapPath
            ],
            timeout=240.0,
            env=None)

        assert result == 0, (result, stdOut, stdErr)
Exemplo n.º 8
0
    def runCommandAndLogOutput(path, command, argument=None, env=None):
        toRun = [os.path.join(path, command)]
        if argument:
            toRun.append(argument)

        logging.info("Running command: %s", toRun)
        exitCode, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(
            toRun, env=env)
        logging.info("Exit code: %s", exitCode)
        logging.info("%s STDOUT> %s", command, stdOut)
        logging.info("%s STDERR> %s", command, stdErr)
        return exitCode
Exemplo n.º 9
0
    def runCommandAndLogOutput(path, command, argument=None, env=None):
        toRun = [os.path.join(path, command)]
        if argument:
            toRun.append(argument)

        logging.info("Running command: %s", toRun)
        exitCode, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(
            toRun,
            env=env
            )
        logging.info("Exit code: %s", exitCode)
        logging.info("%s STDOUT> %s", command, stdOut)
        logging.info("%s STDERR> %s", command, stdErr)
        return exitCode
Exemplo n.º 10
0
    def executeInDocker(self, dockerTag, args):
        standardPath = "/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin"

        shrinkwrappedPathVariable = ":".join([os.path.abspath(self.shrinkwrapPath + "/dependencies/" + p) for p in standardPath.split(":")])

        return SubprocessRunner.callAndReturnResultAndOutput(
            ["docker","run"] + 
                ["-e","PATH=" + shrinkwrappedPathVariable + ":" + standardPath] +
                #so that we get 'ufora'
                ["-e","PYTHONPATH=" + self.shrinkwrapPath] +
                ["-w",self.shrinkwrapPath] +
                ["-v",self.shrinkwrapPath + ":" + self.shrinkwrapPath] + 
                [dockerTag] + 
                args    
            )
Exemplo n.º 11
0
    def executeInDocker(self, dockerTag, args):
        standardPath = "/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin"

        shrinkwrappedPathVariable = ":".join([
            os.path.abspath(self.shrinkwrapPath + "/dependencies/" + p)
            for p in standardPath.split(":")
        ])

        return SubprocessRunner.callAndReturnResultAndOutput(
            ["docker", "run"] +
            ["-e", "PATH=" + shrinkwrappedPathVariable + ":" + standardPath] +
            #so that we get 'ufora'
            ["-e", "PYTHONPATH=" + self.shrinkwrapPath] +
            ["-w", self.shrinkwrapPath] +
            ["-v", self.shrinkwrapPath + ":" + self.shrinkwrapPath] +
            [dockerTag] + args)
Exemplo n.º 12
0
    def validateTimingsForSubprocessCall(self,
                                         testName,
                                         subprocessArgs,
                                         meta,
                                         timeout=600.0):
        resultCode, out, err = SubprocessRunner.callAndReturnResultAndOutput(
            subprocessArgs, timeout=timeout)

        if resultCode != 0:
            meta.update({"failure": "subprocess call returned error"})

            if PerformanceTestReporter.isCurrentlyTesting():
                PerformanceTestReporter.recordTest(testName, None, meta)

        assert resultCode == 0, err

        logging.info("Actual time was %s for %s", out[0], subprocessArgs)

        measuredTiming = float(out[0]) / self.baseTiming

        if PerformanceTestReporter.isCurrentlyTesting():
            PerformanceTestReporter.recordTest("fora_lang." + testName,
                                               float(out[0]), meta)
Exemplo n.º 13
0
def runSomeFora():
    args = ["/usr/local/bin/python", ufora.rootPythonPath + "/test.py", "-lang", "-langfilter=classTests.fora"]
    returnCode, stdOut, stdErr = SubprocessRunner.callAndReturnResultAndOutput(args)
    assert returnCode == 0
Exemplo n.º 14
0
 def evaluateNotebookInSubprocess(self, notebookPath):
     return SubprocessRunner.callAndReturnResultAndOutput([
         'jupyter', 'nbconvert', '--stdout',
         '--ExecutePreprocessor.enabled=True', notebookPath
     ])
Exemplo n.º 15
0
 def evaluateNotebookInSubprocess(self, notebookPath):
     return SubprocessRunner.callAndReturnResultAndOutput(
         ['jupyter', 'nbconvert', '--stdout', 
          '--ExecutePreprocessor.enabled=True', notebookPath]
         )