Ejemplo n.º 1
0
    def __call__(self, owner, name):
        """ Evaluate and return the expression value.

        """
        func = self.func
        f_globals = func.__globals__
        f_builtins = f_globals['__builtins__']
        f_locals = self.get_locals(owner)
        tr = TraitsTracer(owner, name)
        scope = DynamicScope(owner, f_locals, f_globals, f_builtins, None, tr)
        return call_func(func, (tr,), {}, scope)
Ejemplo n.º 2
0
    def __call__(self, owner, name):
        """ Evaluate and return the expression value.

        """
        func = self.func
        f_globals = func.__globals__
        f_builtins = f_globals['__builtins__']
        f_locals = self.get_locals(owner)
        tr = TraitsTracer(owner, name)
        scope = DynamicScope(owner, f_locals, f_globals, f_builtins, None, tr)
        return call_func(func, (tr, ), {}, scope)
Ejemplo n.º 3
0
def test_handling_wrong_arguments():
    """Test handling incorrect arguments.

    """
    with pytest.raises(TypeError) as excinfo:
        call_func(None, None, None, None)
    assert 'Python function' in excinfo.exconly()

    with pytest.raises(TypeError) as excinfo:
        call_func(func, None, None, None)
    assert 'tuple' in excinfo.exconly()

    with pytest.raises(TypeError) as excinfo:
        call_func(func, (), None, None)
    assert 'dict' in excinfo.exconly()

    with pytest.raises(TypeError) as excinfo:
        call_func(func, (), {}, 1)
    assert 'mapping' in excinfo.exconly()
Ejemplo n.º 4
0
def test_handling_none_as_locals():
    """Test passing None as locals.

    """
    assert call_func(func, (), {'a': 1}, None) == 1
Ejemplo n.º 5
0
def test_calling_function_kwarg():
    """Test calling a function with kwargs.

    """
    assert call_func(func, (), {'b': 2}, {'a': 1}) == 1
Ejemplo n.º 6
0
def test_calling_function():
    """Test calling a function with locals.

    """
    assert call_func(func, (), {}, {'a': 1}) == 1
    assert call_func(func, (1,), {}, {'a': 1}) == 1