def test_eq(self): v = ast.Variable('V') n = ast.NumConstant(3) self.assertIs( True, ast.Operation('+', [v, n]) == ast.Operation('+', [v, n])) self.assertIs( False, ast.Operation('+', [v, n]) == ast.Operation('+', [n, n]))
def mk_o(): v1 = ast.Variable('V1') v2 = ast.Variable('V2') v3 = ast.Variable('V3') n = ast.NumConstant(1) o1 = ast.Operation('+', [v1, n]) o2 = ast.Operation('+', [v1, v2]) o = ast.Operation('+', [o1, o2, v3]) return o, v1, v2, v3
def p_eexpr_not(t): 'eexpr : TILDE eexpr' t[0] = ast.Operation('~', [t[2]])
def p_eexpr_or(t): 'eexpr : eexpr BAR eexpr' t[0] = ast.Operation('|', [t[1], t[3]])
def p_eexpr_and(t): 'eexpr : eexpr AMPERSAND eexpr' t[0] = ast.Operation('&', [t[1], t[3]])
def test_operation(self): v = ast.Variable('V') n = ast.NumConstant(3) o = ast.Operation('+', [v, n]) self.assertEqual('+', o.operation) self.assertEqual([v, n], o.args)