Skip to content

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

@GoogleCodeExporter

Description

@GoogleCodeExporter
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 [email protected] on 12 Nov 2012 at 4:55

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions