Permalink
Browse files

add before and after at spy

  • Loading branch information...
1 parent 5a3249b commit a6be931181886e3826476e9967ced2d864c40036 @BecaMotta BecaMotta committed Aug 12, 2010
Showing with 68 additions and 5 deletions.
  1. +3 −3 ludibrio/specification/unit/spy.dt
  2. +63 −1 ludibrio/spy.py
  3. +1 −1 setup.cfg
  4. +1 −0 setup.py
@@ -46,11 +46,11 @@ Spy provides indirect output verification::
True
- >>> verify(grettings) .welcome() .after .hi(name='beca')
+ >>> verify(greetings) .welcome() .before .hi(name='beca')
True
- >>> verify(grettings) .goodbye() .before .hi(name='beca')
- True
+ >>> verify(greetings) .welcome() .after .hi(name='beca')
+ False
View
@@ -45,7 +45,13 @@ def called(self, times):
self.spy.called_count([self._attr_called,
self.args,
self.kargs]))
+ @property
+ def before(self):
+ return Before(self)
+ @property
+ def after(self):
+ return After(self)
class Times(object):
@@ -79,6 +85,62 @@ def verify(self, value):
times = Times()
+class Before(object):
+ def __init__(self, verify_object):
+ self.verify_object = verify_object
+
+ def __getattr__(self, attr):
+ self.attr_called = [attr]
+ return self
-
+ def __call__(self, *args, **kargs):
+ self.attr_called += [args, kargs]
+
+ attr = self.verify_object._attr_called
+ args = self.verify_object.args
+ kargs = self.verify_object.kargs
+
+ before = [attr, args, kargs]
+ after = self.attr_called
+ calls = self.verify_object.spy.__calls__
+ try:
+ return calls.index(before) < calls.index(after)
+ except ValueError:
+ return False
+
+class After(object):
+ def __init__(self, verify_object):
+ self.verify_object = verify_object
+ def __getattr__(self, attr):
+ self.attr_called = [attr]
+ return self
+
+ def __call__(self, *args, **kargs):
+ self.attr_called += [args, kargs]
+
+ attr = self.verify_object._attr_called
+ args = self.verify_object.args
+ kargs = self.verify_object.kargs
+
+ before = [attr, args, kargs]
+ after = self.attr_called
+ calls = self.verify_object.spy.__calls__
+ try:
+ return calls.index(before) > calls.index(after)
+ except ValueError:
+ return False
+
+
+#class After(TimeCalled):
+# def compare(self):
+# try:..except
+
+#class Before(TimeCalled):
+# def compare(self):
+# try..except
+
+#class TimeCalled(object):
+# ...
+# def __call__(...)
+# return self.compare(...)
View
@@ -1,4 +1,4 @@
[nosetests]
with-doctest = 1
-doctest-extension =
+doctest-extension =
verbosity = 2
View
@@ -33,5 +33,6 @@ def read(rname):
# -*- Entry points: -*-
""",
setup_requires=['nose'],
+ test_suite='nose.collector',
)

0 comments on commit a6be931

Please sign in to comment.