self.studentCode = code + '\n'
+ def stripTrailingWs(self, s):
+ '''Return s with trailing whitespace stripped'''
+ while s.endswith(('\n', ' ')):
def runTests(self, tests):
'''Run the given set of tests with the code provided to the
constructor. Returns a list of result pairs, each consisting
of the string 'Yes', 'No', 'Syntax Error' or 'Runtime Error'
and the actual output received. 'Yes' indicates that the
- output matches the expected value. The strings are deemed
- to match if either they're equal or (the expected string
- does not end with a newline and the actual output does and
- expected + '\n == output).
+ output matches the expected value. Trailing whitespace is
+ removed prior to the equality test. Leading whitespace,
+ or trailing whitespace on lines other than the first, is
outcome = 'Runtime Error'
- elif output == expected:
+ elif output == expected:
- elif output.endswith('\n') and not expected.endswith('\n') \
- and (expected + '\n' == output):
outcome = 'No' # debug: + ' ' + comparison(output, expected)
results.append( (outcome, output) )