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 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
Exemple #3
0
    def test_if_cases(self):
        self.assertTrue(make_if(exp=True,then=True)[0](None))
        self.assertTrue(make_if(True,True)[0](None))

        self.assertTrue(make_if(exp=True,then=True,els=False)[0](None))
        self.assertTrue(make_if(True,True,False)[0](None))

        self.assertFalse(make_if(exp=True,then=False)[0](None))
        self.assertFalse(make_if(exp=True,then=False,els=True)[0](None))

        self.assertTrue(make_if(exp=False,then=False)[0](None))
        self.assertTrue(make_if(exp=False,then=False,els=True)[0](None))
        self.assertFalse(make_if(exp=False,then=True,els=False)[0](None))
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
Exemple #5
0
 def test_if_required_attributes(self):
     with self.assertRaises(AssertionError):
         make_if()
     with self.assertRaises(AssertionError):
         make_if(True)
     with self.assertRaises(AssertionError):
         make_if(exp=False)
     with self.assertRaises(AssertionError):
         make_if(then=False)
     with self.assertRaises(AssertionError):
         make_if(els=False)
     with self.assertRaises(AssertionError):
         make_if(then=False,els=False)
     with self.assertRaises(AssertionError):
         make_if(exp=False,els=False)
Exemple #6
0
 def spec():
     return make_if(lambda e: e.fn.m.inputs[1] == 0,
             make_assert((False,"heisenberg0")),
             make_assert((False,"heisenberg1")))
Exemple #7
0
 def spec():
     return make_if(True, make_assert(False))