def compilestudent(self): EEE=None import py_compile try: x= py_compile.compile("student",doraise=True) except Exception as EE: self.fb.addCompilationError("") #self.fb.addFeedback(self.fb.generate_feedback_compilation(self.fb.flags,"error",str(EE))) #errcompil=generate_feedback_compilation2(str(EE),self.fb.flags) ici self.fb.adddiv("errcompil",self.generate_feedback_compilation(self.fb.flags,"error")) self.fb.adddiv("errcompilfin",subnlbybr(str(EE))) if "compilehelp" in self.pld: self.fb.adddiv("compilehelp",self.pld['compilehelp']) #self.fb.addFeedback(self.pld['compilehelp']) self.fb.success=False self.fb.compilation=False return False else: #self.fb.addFeedback(self.fb.generate_feedback_compilation(self.fb.flags,"","")) self.fb.adddiv("compil",self.generate_feedback_compilation(self.fb.flags,"")) return True # compilation ok
def compareExpectedOutput(self,expected,i,stdinput=None): """ Compare the output from student to expected argument update feedback in consequence return True if sucessfull """ tmp=0 r,t = self.getStudentOutput(stdinput) c=compare(expected,t) # si egal ou contient ce qui est attendu if r and c < 3 : if self.fb.showinput and stdinput : self.fb.addOutput("input:\n"+stdinput) #self.fb.addOutput(expected) self.fb.adddiv("ventree output"+str(i),"Entrée :"+self.fb.resultat(subnlbybr(stdinput))+"Attendue:"+self.fb.resultat(subnlbybr(expected))+"Obtenue:"+self.fb.resultat(subnlbybr(expected))) self.fb.success = True elif r : if "nohint" in self.pld: # don't tel the answer self.fb.addOutput(expected) else: self.fb.adddiv("entree expected obtenu"+str(i),"Entrée: "+self.fb.resultat(subnlbybr(stdinput))+"\n Attendue: "+self.fb.resultat(subnlbybr(expected))+"Obtenue:"+ self.fb.resultat(subnlbybr(t))) self.fb.addExpectedOptained(t, expected) #self.fb.addFeedback("\nDifférence ="+str(c)+"\n") self.fb.success = False else: # erreur d'execution r = False #self.fb.addCompilationError(t) for x,y in self.fb.div: if y=="errcompil": tmp=1 if tmp!=1: self.fb.addCompilationError("") self.fb.adddiv("errcompil",self.generate_feedback_compilation(self.fb.flags,"error")) self.fb.adddiv("errcompilfin",subnlbybr(str(t))) if "compilehelp" in self.pld: self.fb.addFeedback(self.pld['compilehelp']) self.fb.success = False return self.fb.success
def dopltest(self): if not "pltest" in self.pld: return False try: with open("pltest.py", "w") as pltf: with open("student", "r") as f: print("", end="\n", file=pltf) print('\"\"\"\n' + self.pld["pltest"] + '>>> \n\"\"\"', file=pltf) print(f.read(), file=pltf) except Exception as e: return False import os os.environ[ 'TERM'] = "linux" # bug in readlinehttps://bugs.python.org/msg191824 if 'mode' in self.pld and self.pld['mode'] == 2: r, out = self.execute( ['python3', '-B', '-m', 'pldoctest', '-f', 'pltest.py'], instr=None) else: r, out = self.execute( ['python3', '-B', '-m', 'pldoctest', 'pltest.py'], instr=None) if catch_except(out): self.fb.addCompilationError("") self.fb.adddiv( "errcompil", self.generate_feedback_compilation(self.fb.flags, "error")) out = out.split("debut") new = "" for x in out: if "NameError" in x: self.fb.adddiv("errcompilfin", subnlbybr(str(x) + "\n")) elif "TypeError" in x: self.fb.adddiv("errcompilfin", subnlbybr(str(x) + "\n")) elif "ImportError" in x: self.fb.adddiv("errcompilfin", subnlbybr(str(x) + "\n")) else: new += x return False self.fb.success = r if r: res = 0 i = 0 liste = out.split('debut') for n in liste: if n != "" and n[1] == "T": self.fb.addsymbole(n, 'resume', True) elif n != "" and i != (len(liste) - 2): self.fb.addsymbole(n, i, True) i += 1 else: res = 0 i = 0 liste = out.split('debut') for n in liste: if n != "" and i != (len(liste) - 2): if n != "" and n[1] == "T": self.fb.addsymbole(n, 'resume', False) elif n.find('False') != -1: self.fb.addsymbole(n, i, False) else: self.fb.addsymbole(n, i, True) i += 1 self.fb.addOutput(out) return True