~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/apps/tutorialservice/test/TestFramework.py

  • Committer: stevenbird
  • Date: 2008-02-20 00:43:13 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:519
Fixed bug in test framework.  Code given in the <include> section was
not being executed for the tests on code strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
225
225
        else:
226
226
            return f(solution_output, attempt_output)
227
227
 
228
 
    def _check_code(self, solution, attempt, test_type, f):
 
228
    def _check_code(self, solution, attempt, test_type, f, include_space):
229
229
        """Compare solution code and attempt code using the
230
230
        specified comparison function.
231
231
        """
232
232
        if type(f) in types.StringTypes:  # kludge
233
 
            f = eval(str(f))
 
233
            f = eval(str(f), include_space)
234
234
        if test_type == 'norm':
235
235
            return f(solution) == f(attempt)
236
236
        else:
237
237
            return f(solution, attempt)
238
238
 
239
 
    def run(self, solution_data, attempt_data):
 
239
    def run(self, solution_data, attempt_data, include_space):
240
240
        """Run the tests to compare the solution and attempt data
241
241
        Returns the empty string if the test passes, or else an error message.
242
242
        """
243
243
 
244
244
        # check source code itself
245
245
        (test_type, f) = self._code_test
246
 
        if not self._check_code(solution_data['code'], attempt_data['code'], test_type, f):       
 
246
        if not self._check_code(solution_data['code'], attempt_data['code'], test_type, f, include_space):       
247
247
            return 'Unexpected code'
248
248
 
249
249
        # check function return value (None for scripts)
374
374
        """ Get the name of the test case """
375
375
        return self._name
376
376
 
377
 
    def run(self, solution, attempt_code, stop_on_fail=True):
 
377
    def run(self, solution, attempt_code, include_space, stop_on_fail=True):
378
378
        """ Run the solution and the attempt with the inputs specified for this test case.
379
379
        Then pass the outputs to each test part and collate the results.
380
380
        """
416
416
        # generate results
417
417
        for test_part in self._parts:
418
418
            try:
419
 
                result = test_part.run(solution_data, attempt_data)
 
419
                result = test_part.run(solution_data, attempt_data, include_space)
420
420
            except:
421
421
                raise TestError(sys.exc_info())
422
422
            
554
554
        test_case_results = []
555
555
        passed = True
556
556
        for test in self._tests:
557
 
            result_dict = test.run(self._solution, attempt_code)
 
557
            result_dict = test.run(self._solution, attempt_code, self._include_space)
558
558
            if 'exception' in result_dict and result_dict['exception']['critical']:
559
559
                # critical error occured, running more cases is useless
560
560
                # FunctionNotFound, Syntax, Indentation