Skip to content
Snippets Groups Projects
in_progress.py 1.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • tuhe's avatar
    tuhe committed
            # example_in_progress/in_progress.py
    
            self.title = f"Checking if reverse_list({ls}) = {reverse}"  # Programmatically set the title 
    
        def ex_test_output_capture(self):
            with self.capture() as out:
                print("hello world 42")                     # Genereate some output (i.e. in a homework script)
            self.assertEqual(out.numbers[0], 42)            # out.numbers is a list of all numbers generated
            self.assertEqual(out.output, "hello world 42")  # you can also access the raw output.
    
    
    class Question2(UTestCase):
        @cache
        def my_reversal(self, ls):
            # The '@cache' decorator ensures the function is not run on the *students* computer
            # Instead the code is run on the teachers computer and the result is passed on with the
            # other pre-computed results -- i.e. this function will run regardless of how the student happens to have
            # implemented reverse_list.
            return reverse_list(ls)
    
        def test_reverse_tricky(self):
            ls = (2,4,8)
            ls2 = self.my_reversal(tuple(ls))                   # This will always produce the right result, [8, 4, 2]
            print("The correct answer is supposed to be", ls2)  # Show students the correct answer
            self.assertEqualC(reverse_list(ls))                 # This will actually test the students code.
            return "Buy world!"                                 # This value will be stored in the .token file