Example #1
0
 def test_runs_cleanups(self):
     """Cleanup functions are run (in the given order)."""
     cleanup_func_1 = (self.call_log.append, ('cleanup 1',), {})
     cleanup_func_2 = (self.call_log.append, ('cleanup 2',), {})
     _do_with_cleanups([cleanup_func_1, cleanup_func_2], self.trivial_func)
     self.assertEqual(
         ['trivial_func', 'cleanup 1', 'cleanup 2'], self.call_log)
 def test_runs_cleanups(self):
     """Cleanup functions are run (in the given order)."""
     cleanup_func_1 = (self.call_log.append, ('cleanup 1', ), {})
     cleanup_func_2 = (self.call_log.append, ('cleanup 2', ), {})
     _do_with_cleanups([cleanup_func_1, cleanup_func_2], self.trivial_func)
     self.assertEqual(['trivial_func', 'cleanup 1', 'cleanup 2'],
                      self.call_log)
Example #3
0
 def test_func_may_mutate_cleanups(self):
     """The main func may mutate the cleanups before it returns.
     
     This allows a function to gradually add cleanups as it acquires
     resources, rather than planning all the cleanups up-front.  The
     OperationWithCleanups helper relies on this working.
     """
     cleanups_list = []
     def func_that_adds_cleanups():
         self.call_log.append('func_that_adds_cleanups')
         cleanups_list.append((self.no_op_cleanup, (), {}))
         return 'result'
     result = _do_with_cleanups(cleanups_list, func_that_adds_cleanups)
     self.assertEqual('result', result)
     self.assertEqual(
         ['func_that_adds_cleanups', 'no_op_cleanup'], self.call_log)
    def test_func_may_mutate_cleanups(self):
        """The main func may mutate the cleanups before it returns.
        
        This allows a function to gradually add cleanups as it acquires
        resources, rather than planning all the cleanups up-front.  The
        OperationWithCleanups helper relies on this working.
        """
        cleanups_list = []

        def func_that_adds_cleanups():
            self.call_log.append('func_that_adds_cleanups')
            cleanups_list.append((self.no_op_cleanup, (), {}))
            return 'result'

        result = _do_with_cleanups(cleanups_list, func_that_adds_cleanups)
        self.assertEqual('result', result)
        self.assertEqual(['func_that_adds_cleanups', 'no_op_cleanup'],
                         self.call_log)
Example #5
0
 def test_runs_func(self):
     """_do_with_cleanups runs the function it is given, and returns the
     result.
     """
     result = _do_with_cleanups([], self.trivial_func)
     self.assertEqual('trivial result', result)
 def test_runs_func(self):
     """_do_with_cleanups runs the function it is given, and returns the
     result.
     """
     result = _do_with_cleanups([], self.trivial_func)
     self.assertEqual('trivial result', result)