Esempio 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)
Esempio n. 2
0
def test_simple_callable():
    def simple():
        return u'test'

    assert u'test' == call_if_callable(simple)
Esempio 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)
Esempio 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)
Esempio 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})
Esempio 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])
Esempio n. 7
0
def test_simple_callable_args():
    def add2(x):
        return x + 2

    assert 4 == call_if_callable(add2, [2])
Esempio n. 8
0
def test_simple_nocallable():
    assert u'test' == call_if_callable(u'test')
Esempio 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)
Esempio n. 10
0
def test_simple_callable():
    def simple():
        return u'test'

    assert u'test' == call_if_callable(simple)
Esempio 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)
Esempio n. 12
0
def test_simple_nocallable():
    assert u'test' == call_if_callable(u'test')
Esempio 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])
Esempio 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})
Esempio n. 15
0
def test_simple_callable_args():
    def add2(x):
        return x + 2

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