Beispiel #1
0
    def __init__(self, index, testcase):
        self.index = index
        self.test = testcase[1].strip()
        self.result = None
        self.outs = []
        self.private = testcase[0] == '#'
        self.key = None
        outs = testcase[2].splitlines()
        for line in outs:
            line = line.strip()
            if line:
                if line.startswith('.'):
                    text = line[1:]
                    if text.startswith(' '):
                        text = text[1:]
                    text = '\n' + text
                    if self.result is not None:
                        self.result += text
                    elif self.outs:
                        self.outs[-1] += text
                    continue

                match = TESTCASE_OUT_RE.match(line)
                symbol, text = match.group(1), match.group(2)
                text = text.strip()
                if symbol == '=':
                    self.result = text
                elif text:
                    if symbol == ':':
                        out = Message('', '', text)
                    elif symbol == '|':
                        out = Print(text)
                    self.outs.append(out)
Beispiel #2
0
    def __init__(self, index, testcase):
        self.index = index
        self.result = None
        self.outs = []

        # Private test cases are executed, but NOT shown as part of the docs
        self.private = testcase[0] == '#'

        # Ignored test cases are NOT executed, but shown as part of the docs
        # Sandboxed test cases are NOT executed if environtment SANDBOX is set
        if testcase[0] == 'X' or (testcase[0] == 'S'
                                  and getenv("SANDBOX", False)):
            self.ignore = True
            # substitute '>' again so we get the correct formatting
            testcase[0] = '>'
        else:
            self.ignore = False

        self.test = testcase[1].strip()

        # This allows a trailing blank at the end of the line for those ofus use use editors that like
        # to strip trailing blanks at the ends of lines.
        self.test = self.test.rstrip("#<--#")

        self.key = None
        outs = testcase[2].splitlines()
        for line in outs:
            line = line.strip()
            if line:
                if line.startswith('.'):
                    text = line[1:]
                    if text.startswith(' '):
                        text = text[1:]
                    text = '\n' + text
                    if self.result is not None:
                        self.result += text
                    elif self.outs:
                        self.outs[-1] += text
                    continue

                match = TESTCASE_OUT_RE.match(line)
                symbol, text = match.group(1), match.group(2)
                text = text.strip()
                if symbol == '=':
                    self.result = text
                elif text:
                    if symbol == ':':
                        out = Message('', '', text)
                    elif symbol == '|':
                        out = Print(text)
                    self.outs.append(out)
Beispiel #3
0
    def do_execute(self,
                   code,
                   silent,
                   store_history=True,
                   user_expressions=None,
                   allow_stdin=False):
        # TODO update user definitions

        response = {
            'payload': [],
            'user_expressions': {},
        }

        formats = {
            'text/plain': 'text',
            'text/html': 'xml',
            'text/latex': 'tex',
        }

        try:
            self.init_web_engine()

            evaluation = Evaluation(self.definitions,
                                    output=KernelOutput(self),
                                    format=formats)

            result = evaluation.parse_evaluate(code, timeout=settings.TIMEOUT)

            if result:
                self.result_callback(result)
        except Exception as exc:
            stack = traceback.format_exception(*sys.exc_info())

            self.out_callback(
                Print('An error occured: ' + str(exc) + '\n\n' +
                      '\n'.join(stack)))

            # internal error
            response['status'] = 'error'
            response['ename'] = 'System:exception'
            response['traceback'] = stack
        else:
            response['status'] = 'ok'

        response['execution_count'] = self.definitions.get_line_no()

        return response
Beispiel #4
0
    def __init__(self, index, testcase):
        self.index = index
        self.result = None
        self.outs = []
        # Private test cases are executed, but NOT shown as part of the docs
        self.private = testcase[0] == '#'
        # Ignored test cases are NOT executed, but shown as part of the docs
        if testcase[0] == 'X':
            self.ignore = True
            # substitute '>' again so we get the correct formatting
            testcase[0] = '>'
        else:
            self.ignore = False

        self.test = testcase[1].strip()

        self.key = None
        outs = testcase[2].splitlines()
        for line in outs:
            line = line.strip()
            if line:
                if line.startswith('.'):
                    text = line[1:]
                    if text.startswith(' '):
                        text = text[1:]
                    text = '\n' + text
                    if self.result is not None:
                        self.result += text
                    elif self.outs:
                        self.outs[-1] += text
                    continue

                match = TESTCASE_OUT_RE.match(line)
                symbol, text = match.group(1), match.group(2)
                text = text.strip()
                if symbol == '=':
                    self.result = text
                elif text:
                    if symbol == ':':
                        out = Message('', '', text)
                    elif symbol == '|':
                        out = Print(text)
                    self.outs.append(out)
Beispiel #5
0
    def __init__(self, index, testcase):
        def strip_sentinal(line):
            """Remove END_LINE_SENTINAL from the end of a line if it appears.

            Some editors like to strip blanks at the end of a line.
            Since the line ends in END_LINE_SENTINAL which isn't blank,
            any blanks that appear before will be preserved.

            Some tests require some lines to be blank or entry because
            Mathics output can be that way
            """
            if line.endswith(END_LINE_SENTINAL):
                line = line[:-len(END_LINE_SENTINAL)]

            # Also remove any remaining trailing blanks since that
            # seems *also* what we want to do.
            return line.strip()

        self.index = index
        self.result = None
        self.outs = []

        # Private test cases are executed, but NOT shown as part of the docs
        self.private = testcase[0] == '#'

        # Ignored test cases are NOT executed, but shown as part of the docs
        # Sandboxed test cases are NOT executed if environtment SANDBOX is set
        if testcase[0] == 'X' or (testcase[0] == 'S'
                                  and getenv("SANDBOX", False)):
            self.ignore = True
            # substitute '>' again so we get the correct formatting
            testcase[0] = '>'
        else:
            self.ignore = False

        self.test = strip_sentinal(testcase[1])

        self.key = None
        outs = testcase[2].splitlines()
        for line in outs:
            line = strip_sentinal(line)
            if line:
                if line.startswith('.'):
                    text = line[1:]
                    if text.startswith(' '):
                        text = text[1:]
                    text = '\n' + text
                    if self.result is not None:
                        self.result += text
                    elif self.outs:
                        self.outs[-1].text += text
                    continue

                match = TESTCASE_OUT_RE.match(line)
                symbol, text = match.group(1), match.group(2)
                text = text.strip()
                if symbol == '=':
                    self.result = text
                elif symbol == ':':
                    out = Message('', '', text)
                    self.outs.append(out)
                elif symbol == '|':
                    out = Print(text)
                    self.outs.append(out)