Skip to content

Instantly share code, notes, and snippets.

@daltonmatos
Created August 7, 2012 02:36
Show Gist options
  • Save daltonmatos/3280885 to your computer and use it in GitHub Desktop.
Save daltonmatos/3280885 to your computer and use it in GitHub Desktop.

Revisions

  1. daltonmatos created this gist Aug 7, 2012.
    18 changes: 18 additions & 0 deletions mocktrue.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import mock

    class AlmostAlwaysTrue(object):

    def __init__(self, total_iterations=1):
    self.total_iterations = total_iterations
    self.current_iteration = 0

    def __nonzero__(self):
    if self.current_iteration < self.total_iterations:
    self.current_iteration += 1
    return bool(1)
    return bool(0)


    with mock.patch('__builtin__.True', AlmostAlwaysTrue(4)):
    while True:
    print "Loop!"
    6 changes: 6 additions & 0 deletions output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    daltonmatos@jetta wsgid % python mocktrue.py
    Loop!
    Loop!
    Loop!
    Loop!
    daltonmatos@jetta wsgid %