Exemplo n.º 1
0
    def test_correct_codes(self):
        for a_code in self.test_codes:
            print 'Checking "%s"(CORRECT SOURCE) on intaractive mode' % a_code
            self.cmd = Example(is_intaractive_run=True)
            self.cmd.visitor.is_test = True
            with open(a_code, 'r') as rf:
                for line in rf:
                    self.cmd.talk(line)
            print 'Checking "%s"(CORRECT SOURCE) on IO mode' % a_code
            self.cmd = Example(is_intaractive_run=False)
            self.cmd.visitor.is_test = True
            self.cmd.eat_code(a_code)

            print 'Checking "%s"(CORRECT SOURCE) on String mode for the web' % a_code
            self.cmd = Example(is_intaractive_run=False)
            self.cmd.visitor.is_test = True
            with open(a_code, 'r') as rf:
                self.cmd.eat_string(rf.read())
Exemplo n.º 2
0
# -*- coding: utf-8 -*-

import sys
import os
import os.path
from flask import Flask, request, url_for, redirect, render_template, send_from_directory
from unitx.example import Example
import threading
import uuid
import codecs

lock = threading.Lock()
app = Flask(__name__, template_folder='./static/template', static_url_path='')
#intaractive_unitx = Example(is_intaractive_run=True)
#io_unitx = Example(is_intaractive_run=False)
string_unitx = Example(is_intaractive_run=False)
tmp_folder = './tmp/'
decoding_code = 'utf-8'
default_sample_name = 'unit_converter'
index_template = 'unitx_template.html'


def __run_unitx(code):
    # TODO(Tasuku): stand in a line
    u = 'x_' + str(uuid.uuid4())
    stdout_path = tmp_folder + u + '_stdout_unitx.txt'
    stderr_path = tmp_folder + u + '_stderr_unitx.txt'
    code = code.replace('\r', '')
    #textarea_db = tmp_folder + u + '_textarea.txt'

    sys.stdout = codecs.open(stdout_path, 'w', decoding_code)
Exemplo n.º 3
0
class Tester(unittest.TestCase):
    """ """

    def __check_a_bug(self, exit_status):
        """Tag a bug.

        If exit_status is Constants.SUCCESS_FAILURE or Constants.EXIT_FAILURE_IN_UNITX,
        The UnitX system works normally. But if it's Constants.EXIT_FAILURE, it's going to be a bug.
        """
        if exit_status == Constants.EXIT_FAILURE:
            print '-' * 50
            print 'A BUG IN UnitX(ERR_CODE=%s)' % Constants.EXIT_FAILURE
            print '-' * 50
            sys.exit(Constants.EXIT_FAILURE)


    def test_error_codes(self):
        for a_code in self.err_codes:
            print 'Checking "%s"(ERROR SOURCE) on intaractive mode' % a_code
            p = subprocess.Popen(["python","unitx/example.py"], stdin=open(a_code, 'r'), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            exit_status = p.wait()
            self.__check_a_bug(exit_status)

            print 'Checking "%s"(ERROR SOURCE) on IO mode' % a_code
            p = subprocess.Popen(["python","unitx/example.py", a_code], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            exit_status = p.wait()
            self.__check_a_bug(exit_status)


    def test_correct_codes(self):
        for a_code in self.test_codes:
            print 'Checking "%s"(CORRECT SOURCE) on intaractive mode' % a_code
            self.cmd = Example(is_intaractive_run=True)
            self.cmd.visitor.is_test = True
            with open(a_code, 'r') as rf:
                for line in rf:
                    self.cmd.talk(line)
            print 'Checking "%s"(CORRECT SOURCE) on IO mode' % a_code
            self.cmd = Example(is_intaractive_run=False)
            self.cmd.visitor.is_test = True
            self.cmd.eat_code(a_code)

            print 'Checking "%s"(CORRECT SOURCE) on String mode for the web' % a_code
            self.cmd = Example(is_intaractive_run=False)
            self.cmd.visitor.is_test = True
            with open(a_code, 'r') as rf:
                self.cmd.eat_string(rf.read())
    
    def setUp(self):
        print
        self.test_codes = []
        self.err_codes = []
        self.err_ans_codes = []
        for filename in os.listdir('tests'):
            name, ext = os.path.splitext(filename)
            if ext == '.unit':
                if 'err' in name:
                    self.err_codes.append(os.path.join('tests', filename))
                else:
                    self.test_codes.append(os.path.join('tests', filename))

    def tearDown(self):
        pass