Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pymox should support a context handler for verification #49

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 0 comments
Open

pymox should support a context handler for verification #49

GoogleCodeExporter opened this issue Mar 19, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

[this is a feature request]

I recently wrote a small helper class to allow a context handlers to provide 
verification.  e.g.

  def testFoo(self):
    # set expectations
    with Verification(self.mox):
      # call code, assert results.

The implementation is simple:

class Verification(object):
  def __init__(self, m):
    self.m = m

  def __enter__(self):
    self.m.ReplayAll()

  def __exit__(self, exc_type, exc_value, traceback):
    if exc_type is None and exc_value is None and traceback is None:
      self.m.VerifyAll()

I think that this should probably be a core part of mox, allowing one to say:

  def testFoo(self):
    with self.mox.Verification():
      # …

To my eye, this nicely delineates the code under test from the setup code.

I've attached a sample implementation for discussion.  Some points from that:

- I'm not sure what the minimum Python version of pymox is.  Context handlers 
are a 2.6ism.
- I placed a function on the Mox class, which uses another class, Verification. 
 This seemed more flexible than just saying "with self.mox" as it allows for 
other context handlers if necessary.

Original issue reported on code.google.com by h...@google.com on 30 Jul 2012 at 8:46

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant