Commits

trampgeek committed bad4cae

Change Pycode validator to strip trailing whitespace before equality test.

Comments (0)

Files changed (1)

pypy/translator/sandbox/pycodeClasses.py

             self.studentCode = code
         else:
             self.studentCode = code + '\n'
+            
+            
+    def stripTrailingWs(self, s):
+        '''Return s with trailing whitespace stripped'''
+        while s.endswith(('\n', ' ')):
+            s = s[0:-1]
+        return s
+        
         
     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
+           not removed.
            '''
         results = []
         i = 0
                 outcome = 'Syntax Error'
             elif pc.exception:
                 outcome = 'Runtime Error'
-            elif output == expected:
+            elif self.stripTrailingWs(output) == self.stripTrailingWs(expected):
                 outcome = 'Yes'
-            elif output.endswith('\n') and not expected.endswith('\n') \
-                  and (expected + '\n' == output):
-                outcome = 'Yes'
-                output = output[:-1]
             else:
                 outcome = 'No'  # debug: + ' ' + comparison(output, expected)
             results.append( (outcome, output) )