# -*- coding: utf-8 -*-
# $Id:PyUnit.py 1199 2009-08-12 12:53:59Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of backend 'pyunit'.
import logging
# local imports
WRAPPER_MODULE = \
"""# -*- coding: utf-8 -*-
from unittest import TestSuite, makeSuite
from Student import *
${imports}
${unitTests}
def test_suite():
suite = TestSuite()
suite.addTest(makeSuite(${testClass}))
return suite
if __name__ == '__main__':
TestRunner = unittest.TextTestRunner
suite = test_suite()
TestRunner().run(suite)
"""
# input schema
'imports',
description = 'Enter additional imports, like Python '\
'libraries.',
),
'unitTests',
),
))
# test environments
'default',
),
))
#RE_INDENT = re.compile('^', re.M)
#RE_SELF = re.compile('def test.+?\(')
#RE_FAILED = re.compile('^Ran\s\d+.*FAILED', re.M | re.DOTALL)
"""
Backend for testing Python programs using PyUnit.
"""
"""
This constructor is needed to reset the logging environment.
"""
"""
@see: AbtractSimpleBackend._postProcessCheckSyntax
"""
# replace path and filename
"""
Checks semantic of a Python program.
@return: a BackendResult object with result code and value
"""
# test for available test specs
msg = 'No test specification selected.'
# get additional imports
# get all unit tests
# get student's submission
"Semantic check requires valid 'model solution' (%s)" % \
"Semantic check requires valid 'student solution' (%s)" % \
# define return values
# run selected test specifications
# get the interpreter
# write module Student
# get unit test's class name
assert className, "Internal error: Could not extract class name from test class."
# get wrapper code
# add imports
# add unit tests
# replace test class's name
# execute wrapper code in interpreter
try:
#print os.path.dirname(wrapperModule['file'])
except Exception, e:
msg = 'Internal error during semantic check: %s: %s' % \
# an error occured
result = "\nYour submission failed. \n\n" \
"Received result: %s" % result
# has the students' solution passed this tests?
else:
if matcher:
else:
#end for
if solved:
# TODO: i18n
feedback = '\nYour submission passed all tests.'