def ensure_auth(event): auth = make_assert(lambda e: e.called_function.inputs[1].user.is_authenticated()) active = make_assert(lambda e: e.called_function.inputs[1].user.is_active) return make_if(requires_auth, auth + active)
def spec(): asserts = make_assert(True, lambda e: e.fn.m.inputs[1] > 0, lambda e: e.fn.m.inputs[1] != 5, make_next(lambda: asserts)) return asserts
def must_view_status_update(): must_view = make_assert( lambda e: (e.fn.start.called, "Didn't view status update")) if_updated = make_if( lambda e: e.fn.status.called, make_next(must_view)) spec = if_updated + make_next(lambda: spec) return spec
def spec(): # create assert specification a = make_assert( lambda event: event.fn.foo.called) # create if-then specification, with guard expression # and an assert specification in the then clause if_guard = lambda event: event.fn.foo.inputs[0] == 0 if_then = make_assert( lambda event: event.fn.foo.inputs[1] == 0) i = make_if(if_guard, if_then) # create next specification n = make_next(spec_bar_called) # combine the three by tail composition return a + i + n
def spec(): # create assert specification a = make_assert( lambda event: event.fn.func.inputs[0] > 0) # create next specification n = make_next(lambda: spec) # combine by tail composition return a + n
def spec_bar_called(): # create assert specification a = make_assert( lambda event: event.fn.bar.called) # create next specification n = make_next(spec) # combine by tail composition return a + n
def test_assert_cases(self): self.assertEquals(len(make_assert()), 0) self.assertTrue(make_assert(True)[0](None)) self.assertFalse(make_assert(False)[0](None)) self.assertTrue(make_assert(lambda e: True)[0](None)) self.assertFalse(make_assert(lambda e: False)[0](None)) a = make_assert(True, False, lambda e: False, lambda e: e != 5) self.assertEquals(len(a), 4) self.assertTrue(a[0](None)) self.assertFalse(a[1](None)) self.assertFalse(a[2](None)) self.assertTrue(a[3](None)) self.assertTrue(a[3](4)) self.assertFalse(a[3](5))
def spec(): return make_assert((False, "buffy"))
def spec(): return make_assert(True, False, 5 == 3)
def spec(): s = make_assert(lambda e: (len(e.history) == 1,"Too much history"), make_next(lambda: s)) return s
def spec(): return make_if(lambda e: e.fn.m.inputs[1] == 0, make_assert((False,"heisenberg0")), make_assert((False,"heisenberg1")))
def spec(): return make_if(True, make_assert(False))
def spec(): a = make_assert(False) return make_next(a)
def spec2(): return make_assert(lambda e: e.fn.m.inputs[1] != 2)