google-code-export / pymox

Automatically exported from code.google.com/p/pymox
0 stars 0 forks source link

Patch for /trunk/mox.py - Bug fix for MultipleTimes().WithSideEffect() #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Bug situation using MultipleTimes() combined with WithSideEffects() but not 
AndReturn. The return value from the first call to the side effect method will 
become the return value for all subsequent calls to the MockMethod.

Unit test which illustrates the current bug:

  def testMultipleTimesWithSideEffects(self):
    """Test MultipleTimes with side effects."""
    mock_obj = self.mox.CreateMockAnything()
    mock_obj.Open()
    mock_obj.Method(mox.IsA(int)).MultipleTimes().WithSideEffects(
        lambda x: x + 1)
    mock_obj.Close()
    self.mox.ReplayAll() 

    mock_obj.Open() 
    actual_one = mock_obj.Method(1)
    actual_three = mock_obj.Method(3)
    mock_obj.Close()

    self.assertEquals(2, actual_one)
    self.assertEquals(4, actual_three)

    self.mox.VerifyAll()

Original issue reported on code.google.com by kma...@google.com on 12 Nov 2012 at 4:55

Attachments: