Ejemplo n.º 1
0
    def session(cls):
        """
        Call :attr:`BaseModel.sessionmaker` and returns a new session.

        Don't forget to call  :attr:`BaseModel.sessionmaker_maker` in application's initialization.
        """
        return call_if_callable(cls.sessionmaker)
Ejemplo n.º 2
0
def test_simple_callable():
    def simple():
        return u'test'

    assert u'test' == call_if_callable(simple)
Ejemplo n.º 3
0
def test_callable_multiple_kwargs():
    def add_all(x, bonii=2, other=4):
        return x + bonii + other

    kwargs = {'bonii': 4, 'other': 8}
    assert 14 == call_if_callable(add_all, [2], kwargs)
Ejemplo n.º 4
0
def test_callable_else():
    def concat_plop(x):
        return u'{0}.plop'.format(x)

    assert u'test.plop' == call_if_callable(u'test', else_=concat_plop)
Ejemplo n.º 5
0
def test_simple_callable_kwargs():
    def add_something(x, something=2):
        return x + something 

    assert 4 == call_if_callable(add_something, [2])
    assert 6 == call_if_callable(add_something, [2], {'something': 4})
Ejemplo n.º 6
0
def test_callable_multiple_args():
    def add_all(x, y, z):
        return x + y + z

    assert 6 == call_if_callable(add_all, [1, 2, 3])
Ejemplo n.º 7
0
def test_simple_callable_args():
    def add2(x):
        return x + 2

    assert 4 == call_if_callable(add2, [2])
Ejemplo n.º 8
0
def test_simple_nocallable():
    assert u'test' == call_if_callable(u'test')
Ejemplo n.º 9
0
def test_callable_else():
    def concat_plop(x):
        return u'{0}.plop'.format(x)

    assert u'test.plop' == call_if_callable(u'test', else_=concat_plop)
Ejemplo n.º 10
0
def test_simple_callable():
    def simple():
        return u'test'

    assert u'test' == call_if_callable(simple)
Ejemplo n.º 11
0
def test_callable_multiple_kwargs():
    def add_all(x, bonii=2, other=4):
        return x + bonii + other

    kwargs = {'bonii': 4, 'other': 8}
    assert 14 == call_if_callable(add_all, [2], kwargs)
Ejemplo n.º 12
0
def test_simple_nocallable():
    assert u'test' == call_if_callable(u'test')
Ejemplo n.º 13
0
def test_callable_multiple_args():
    def add_all(x, y, z):
        return x + y + z

    assert 6 == call_if_callable(add_all, [1, 2, 3])
Ejemplo n.º 14
0
def test_simple_callable_kwargs():
    def add_something(x, something=2):
        return x + something

    assert 4 == call_if_callable(add_something, [2])
    assert 6 == call_if_callable(add_something, [2], {'something': 4})
Ejemplo n.º 15
0
def test_simple_callable_args():
    def add2(x):
        return x + 2

    assert 4 == call_if_callable(add2, [2])