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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-08-20 12:09:11 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1035
Tutorial: Added in stdin support for exercises (sets them up in console)

Show diffs side-by-side

added added

removed removed

Lines of Context:
326
326
        self._list_args = []
327
327
        self._keyword_args = {}
328
328
        
329
 
        # stdin must have a newline at the end for raw_input to work properly
330
 
        if stdin[-1:] != '\n': stdin += '\n'
331
 
        
332
 
        self._stdin = stdin
 
329
        self.set_stdin(stdin)
333
330
        self._filespace = testfilespace.TestFilespace(filespace)
334
331
        self._global_space = global_space
335
332
        self._parts = []
337
334
 
338
335
    def set_stdin(self, stdin):
339
336
        """ Set the given string as the stdin for this test case"""
340
 
        # TODO: Set stdin of console
341
 
        self._stdin = stdin
 
337
        # stdin must have a newline at the end for raw_input to work properly
 
338
        if stdin[-1:] != '\n':
 
339
            stdin += '\n'
 
340
        self.stdin = stdin
342
341
 
343
342
    def add_file(self, filename, data):
344
343
        """ Insert the given filename-data pair into the filespace for this test case"""
397
396
        try:
398
397
            global_space_copy = copy.deepcopy(self._global_space)
399
398
            solution_data = self._execstring(solution, global_space_copy)
 
399
            self._console.stdin.truncate(0)
 
400
            self._console.stdin.write(self._stdin)
400
401
            
401
402
            # if we are just testing a function
402
403
            if not self._function == None:
412
413
        try:
413
414
            global_space_copy = copy.deepcopy(self._global_space)
414
415
            attempt_data = self._execstring(attempt_code, global_space_copy)
 
416
            self._console.stdin.truncate(0)
 
417
            self._console.stdin.write(self._stdin)
415
418
            
416
419
            # if we are just testing a function
417
420
            if not self._function == None: