def test_constants_unknown(self): rules = pp(PROG1.format('a', 'b', 'd')) constants = { 'a': ast.StringConstant('n'), 'b': ast.NumConstant(2), 'c': ast.NumConstant(0)} comp = compiler.Z3Compiler(rules, constants, None) self.assertRaises(obase.Z3NotWellFormed, comp.substitute_constants)
def test_string(self): c = ast.StringConstant('foo') self.assertEqual('foo', c.val) self.assertEqual('string', c.type) self.assertEqual(0, len(c.variables())) c = ast.NumConstant('aaa-bbb', dtype='id') self.assertEqual('aaa-bbb', c.val) self.assertEqual('id', c.type)
def test_constants(self): ast.Rule.rule_counter = 0 rules = pp(PROG1.format('a', 'b', 'c')) constants = { 'a': ast.StringConstant('n'), 'b': ast.NumConstant(2), 'c': ast.NumConstant(0)} comp = compiler.Z3Compiler(rules, constants, None) comp.substitute_constants() ast.Rule.rule_counter = 0 expected = pp(PROG1.format('"n"', '2', '0')) self.assertEqual(expected, rules)
def test_string_eq(self): self.assertIs(True, ast.StringConstant('a') == ast.StringConstant('a')) self.assertIs( False, ast.StringConstant('b') == ast.StringConstant('a')) self.assertIs( False, ast.StringConstant('a') == ast.StringConstant('a', dtype='id'))
def p_sexpr_string(t): 'sexpr : STRING' t[0] = ast.StringConstant(t[1])
u'0.0.0.0' if cidr is None else ipaddress.ip_interface(six.text_type(cidr)).ip.compressed) def dump_translations(fd): """Dumps the contents of translation tables as SMT2 comments""" for typ in TYPES.values(): iterator = typ.dump() if iterator is not None: fd.write("; *** {} ***\n".format(typ.name)) for line in iterator: fd.write(line) CONSTANTS = { "none": ast.StringConstant(None, dtype='id'), "ingress": ast.StringConstant('ingress', dtype='direction'), "egress": ast.StringConstant('egress', dtype='direction'), "ipv4": ast.StringConstant('ipv4', dtype='ip_version'), "ipv6": ast.StringConstant('ipv6', dtype='ip_version'), "active": ast.StringConstant('active', dtype='status'), "down": ast.StringConstant('down', dtype='status'), "build": ast.StringConstant('build', dtype='status'), "error": ast.StringConstant('error', dtype='status'), "other": ast.StringConstant('other', dtype='status'), "allow": ast.StringConstant('allow', dtype='fw_action'), "reject": ast.StringConstant('reject', dtype='fw_action'), "deny": ast.StringConstant('deny', dtype='fw_action'), "true": ast.BoolConstant(True), "false": ast.BoolConstant(False) }