def test_nested_prerequisite(self): """Prerequisite can be nested.""" def prerequisite1(): l[0] = 1 def prerequisite2(): l[1] = 1 l = [0, 0] pre1 = gui.CompoundPrerequisite(lambda: gui.MAYBE, prerequisite1) pre2 = gui.CompoundPrerequisite(lambda: gui.YES, prerequisite2) pre = gui.CompoundPrerequisite(pre1, pre2) self.assertTrue(pre()) self.assertEqual(l, [1, 0])
def test_prerequisite(self): """ A prerequisite return YES, NO or MAYBE. YES and MAYBE are considered both true in the ultimate stage. """ for b, ret in (True, gui.YES), (False, gui.NO), (True, gui.MAYBE): pre = gui.CompoundPrerequisite(lambda: ret) if b: self.assertTrue(pre()) else: self.assertFalse(pre())
def test_yes_prerequisite(self): """ Prerequisite can be more than one, if YES or NO is returned then the other prerequisites are not checked. """ def prerequisite(): l.append(True) for check, ret in (False, gui.NO), (True, gui.YES): l = [] pre = gui.CompoundPrerequisite(lambda: ret, prerequisite) if check: self.assertTrue(pre()) else: self.assertFalse(pre()) self.assertEqual(l, [])