def test_constraint_5(self): """ Skip a block """ # first, skip a normal block base = abs_path('./specs/') ps = Parser(base + 'script3-5.py', base) ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 8) # then, skip a decision block ps = Parser(base + 'script3-5.py', base) ps.spec['constraints'] = [{ "block": "B", "skippable": True, "condition": "a == if" }] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 6)
def test_constraint_4(self): """ Variable depends on variable """ base = abs_path('./specs/') ps = Parser(base + 'script3-4.py', base) ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # then, test index ps = Parser(base + 'script3-4.py', base) ps.spec['constraints'] = [{ "variable": "b", "index": 1, "condition": "a.index == 0" }, { "variable": "b", "index": 0, "condition": "a == else" }] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4)
def test_eval(self): """ Evaluation of various conditions """ # expr and expr base = abs_path('./specs/') ps = Parser(base + 'script3-6.py', base) ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 2) # expr or expr ps.spec['constraints'] = [{ "block": "D", "condition": "a == if or B == b1" }] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 6) # expr and (expr or expr) ps.spec['constraints'] = [{ "block": "D", "condition": "a == if and (B == b1 or B == b2)" }] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing != ps.spec['constraints'] = [{"block": "D", "condition": "a != if"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing >= ps.spec['constraints'] = [{"block": "D", "condition": "a.index >= 1"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing index ps.spec['constraints'] = [{"block": "D", "condition": "b.index == 1"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing option with integer type ps.spec['constraints'] = [{"block": "D", "condition": "b == 0"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing option with float type ps.spec['constraints'] = [{"block": "D", "condition": "b == 1.5"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 4) # testing unmade decision ps.spec['constraints'] = [{"block": "A", "condition": "b.index == 0"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 0) # testing if the decision is made when the block depends on a variable # inside the block ps.spec['constraints'] = [{"block": "B", "condition": "b.index == 0"}] ps._parse_constraints() ps.main(verbose=False) self.assertEqual(ps.wrangler.counter, 0)