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)
Example #2
0
        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
Example #7
0
    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))
Example #8
0
 def spec():
     return make_assert((False, "buffy"))
Example #9
0
 def spec():
     return make_assert(True, False, 5 == 3)
Example #10
0
 def spec():
     s = make_assert(lambda e: (len(e.history) == 1,"Too much history"),
             make_next(lambda: s))
     return s
Example #11
0
 def spec():
     return make_if(lambda e: e.fn.m.inputs[1] == 0,
             make_assert((False,"heisenberg0")),
             make_assert((False,"heisenberg1")))
Example #12
0
 def spec():
     return make_if(True, make_assert(False))
Example #13
0
 def spec():
     a = make_assert(False)
     return make_next(a)
Example #14
0
 def spec2():
     return make_assert(lambda e: e.fn.m.inputs[1] != 2)