Пример #1
0
 def curried(code, output, error):
     try:
         ast.parse(code)
         return True
     except Exception, e:
         return "This test failed because of a syntax error in your code: " + str(
             e).split(": ", 2)[1]
Пример #2
0
 def curried(code, output, error):
     tree = ast.parse(code)
     defs = ast.find(
         tree,
         lambda x: x["_astname"] == "FunctionDef" and x["name"] == func)
     if len(defs) > 0:
         return True
     else:
         return "There is no definition for the function <tt><b>" + func + "</b></tt> in your code"
Пример #3
0
 def curried(code, output, error):
     tree = ast.parse(code)
     defs = ast.find(
         tree,
         lambda x: x["_astname"] == "FunctionDef" and x["name"] == func)
     if len(defs) > 0:
         nArgs = len(defs[0]['args']['args'])
         if nArgs == arity:
             return True
         else:
             return "The function <tt><b>" + func + "</b></tt> should take <b>" + str(
                 arity) + "</b> arguments not <b>" + str(nArgs) + "</b>"
     else:
         return "There is no definition for the function <tt><b>" + func + "</b></tt> in your code"
Пример #4
0
 def hasSyntaxNode(code, output, error):
     tree = ast.parse(code)
     return len(ast.find(tree, lambda x: x["_astname"] == node)) > 0
Пример #5
0
 def checkImport(code, output, error):
     tree = ast.parse(code)
     result = ast.find(
         tree, lambda x: x['_astname'] == 'alias' and x['name'] == mod)
     return len(result) > 0
Пример #6
0
 def curried(code, output, error):
     tree = ast.parse(code)
     r = ast.find(tree, test)
     return len(r) > 0