def test_deepcopy_expression(): deepcopy(parse_expression('1')) deepcopy(parse_expression('1 > 2')) deepcopy(parse_expression('1 & 2')) deepcopy(parse_expression('1 or 2')) deepcopy(parse_expression('not 1')) deepcopy(parse_expression('~x')) deepcopy(parse_expression('2 if x else 3'))
def test_iter_names(): expr = 'a if b in c else d > e' a = parse_expression(expr) b = Expr.parse(expr) # alias assert sorted(_iter_names(a)) == ['a', 'b', 'c', 'd', 'e'] assert sorted(_iter_names(b)) == ['a', 'b', 'c', 'd', 'e'] with pytest.raises(RuntimeError): # don't directly instantiate Expr()
def test_action_menu(qapp): ACTIONS = { 'add_one': { 'description': 'Add one', 'action': lambda x: x.append(1), 'enable_when': parse_expression('count == 0'), } } menu = QtActionContextMenu(ACTIONS) menu.update_from_context({'count': 0, 'is_ready': True}) assert menu._get_action('add_one').isEnabled() assert menu._get_action('add_one').isVisible() CONTEXT_KEYS = { 'count': lambda x: len(x), 'is_ready': lambda x: True, } some_object = [42] ctx = {k: v(some_object) for k, v in CONTEXT_KEYS.items()} menu.update_from_context(ctx) assert not menu._get_action('add_one').isEnabled()
def test_bad_serdes(expr): with pytest.raises(SyntaxError): parse_expression(expr)
def test_serdes(expr): assert str(parse_expression(expr)) == expr