Exemplo n.º 1
0
class Test(object):
    def __init__(self, tests=None, desc=""):
        if not tests: tests = [["", ""]] # Stupid evaluate-once arguments
        self.desc = desc
        self.tests = tests
        
        self.intp = Interpreter()

    def trim(self):
        self.desc = self.desc.strip()
        
        if self.tests[0] == ["", ""]: del self.tests[0]
        
        for i in self.tests:
            i[0] = i[0].strip()
            i[1] = i[1].strip()

    def run(self, quiet=False):
        if not self.tests: return 0
        failed = []

        for i in self.tests:
            try:
                out = repr(self.intp.run_code(i[0]))
            except Exception, e:
                failed.append((i[0], i[1], "", traceback.format_exc()))
            else:
                if out != i[1]:
                    failed.append((i[0], i[1], out.strip(), ""))

        if quiet:
            return len(failed)
        
        if not failed:
            print ".", self.desc
            return 0
        else:
            print "F", self.desc, "(" + str(len(failed)) + "/" + str(len(self.tests)) + ")"
            for i in failed:
                print "===== Input: ======"
                print i[0]
                print "===== Expected: ==="
                print i[1]
                if i[2]:
                    print "===== Output: ====="
                    print i[2]
                if i[3]:
                    print "===== Error: ======"
                    print i[3]
                print "==================="
                
            return len(failed)
Exemplo n.º 2
0
 def __init__(self, tests=None, desc=""):
     if not tests: tests = [["", ""]] # Stupid evaluate-once arguments
     self.desc = desc
     self.tests = tests
     
     self.intp = Interpreter()