# -*- coding: utf-8 -*-
# $Id: Python.py 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
import logging
# local imports
# load Haskell function to do a simple test
try:
# load Haskell function to do a test which allows permutation of list elems
try:
WRAPPER_TEMPLATE = \
"""import sys
import Model
import Student
${helpFunctions}
# must be named 'test'
${testFunction}
o1 = Model.${testData}
o2 = Student.${testData}
print >> sys.stdout, \"isEqual=\" + str(test(o1, o2)) + \";;expected=\" + str(o1) + \";;received=\" + str(o2)
"""
# input schema
'modelSolution',
),
'helpFunctions',
),
'testData',
#accessor = # must return a list; default is one element per line
'A function call consists of the ' +
'function name (given in the exercise directives) ' +
'and test data as parameters of this funtion. '+
'Each function call must be written in a single line.',
),
))
# testSchema
'simple',
),
'permutation',
),
))
"""
Backend for checking Python programs. This class is inherited
from AbstractFPBackend.
"""
"""
This constructor is needed to reset the logging environment.
"""
"""
@see: AbtractSimpleBackend._postProcessCheckSyntax
"""
# replace path and filename
"""
Checks semantic of a Python programs.
@return: a BackendResult object with result code and value
"""
# test for available test specs
msg = 'No test specification selected.'
# test for defined repeat fields in the schema definition
assert repeatFields, 'No RepeatField found.'
# test for available test data
msg = 'No test data defined.'
# get model solution and student's submission
"Semantic check requires valid 'model solution' (%s)" % \
"Semantic check requires valid 'student solution' (%s)" % \
# define return values
# run selected test specifications
if not solved: break
# get the interpreter
# 4.0 write model solution and answer files
# 4.1. get wrapper code
# 4.2. get values for all other input fields from schema which are
# available in the job data
# 4.3 set test function
# 4.4. run with all test data
for t in testdata:
# and now add repeatable data values
# remove all remaining placeholders
# execute wrapper code in interpreter
try:
except Exception, e:
msg = 'Internal error during semantic check: %s: %s' % \
# an error occured
result = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
"\n\n Received result: %s"\
# has the students' solution passed this tests?
else:
# TODO: i18n
feedback = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
feedback += '\n\n Expected result: %s\n ' \
'Received result: %s' \
break # means: end testing right now
# end inner for loop
#end out for loop
if solved:
# TODO: i18n
feedback = '\nYour submission passed all tests.'