Пример #1
0
        def test_func(test_file):
            with open(test_file) as f:
                solution = re.findall(r"//(.*)", f.read())

            if len(solution) == 1 and solution[0].startswith("ERROR="):
                solution = solution[0].strip("ERROR=")
                try:
                    interpret(test_file, factory)
                except Exception as e:
                    assert solution in str(type(e))
            else:
                assert interpret(test_file, factory) == solution
Пример #2
0
    def calc_printed_output(self):
        try:
            os.remove('tempfile.basis')
        except:
            pass

        with open('tempfile.basis', 'w') as f:
            f.write(self.full_test)

        result = basis.interpret('tempfile.basis')[0]
        os.remove('tempfile.basis')
            
        self.printed_output = result
Пример #3
0
def main():
    parser = argparse.ArgumentParser(prog="basis")
    parser.add_argument("file",
                        help="file to execute")
    parser.add_argument("-v", "--verbose",
                        action="store_true",
                        help="print the code and the log")
    args = parser.parse_args()

    if args.verbose:
        with open(args.file) as f:
            print(f.read())
        logger.enable()

    output = basis.interpret(args.file)

    for line in output:
        print(line)
Пример #4
0
    def calc_evaluate(self):
        temp_test = ''
        temp_split = self.full_test.splitlines()
        for i, line in enumerate(temp_split):
            temp_test += 'print(' + line.strip() + ')'
            if i < len(temp_split) - 1:
                temp_test += '\n'

        try:
            os.remove('tempfile.basis')
        except:
            pass

        with open('tempfile.basis', 'w') as f:
            f.write(temp_test)

        result = basis.interpret('tempfile.basis')[0]
        os.remove('tempfile.basis')
            
        self.evaluate = result
Пример #5
0
    def calc_end_values(self):
        for variable in self.variables:
            line_add = 'print(' + self.variables[variable] + ')\n'
            temp_test = copy.deepcopy(self.full_test)
            temp_test += line_add

            try:
                os.remove('tempfile.basis')
            except:
                pass

            with open('tempfile.basis', 'w') as f:
                f.write(temp_test)

            result = basis.interpret('tempfile.basis')[0]

            os.remove('tempfile.basis')
            
            self.end_values[self.variables[variable]] = result

        return self
Пример #6
0
    def complete(self, choice_backlog = []):
        """
            Method complete
            Fills in the template in order to create a finished test, then validates it and stores the output

            Inputs: None

            Output: Template object
        """
        self.choice_backlog = choice_backlog
        # Repeat untill validation succeeds, or we have tried 3 times
        count = 0
        while True:
            # Check count
            if count >= 15:
                return self

            # Fill the template
            self.__fill_template()

            try:
                os.remove('tempfile.basis')
            except:
                pass

            with open('tempfile.basis', 'w') as f:
                f.write(self.full_test)

            try:
                output = basis.interpret('tempfile.basis', factory=basis.eval.factories.restricted)
            except:
                os.remove('tempfile.basis')
            else:
                os.remove('tempfile.basis')
                return self

            count += 1
Пример #7
0
def test_fib_rec_double():
    assert interpret("examples/fib_rec_double.code") == ["8"]
Пример #8
0
def test_fib_it():
    assert interpret("examples/fib_it.code") == ["8"]
Пример #9
0
def test_greedy():
    assert interpret("examples/greedy.code") == ["4"]
Пример #10
0
def test_fib_rec_tail():
    assert interpret("examples/fib_rec_tail.code") == ["8"]