Exemplo n.º 1
0
    def test_unless_sqla(self):
        from sqlalchemy import (MetaData, Table, Column, Integer, String)
        from sqlalchemy.orm import create_session, mapper

        metadata = MetaData('sqlite:///:memory:')
        testtable = Table('test1', metadata,
            Column('id', Integer, primary_key=True),
            Column('val', String(8)))
        metadata.create_all()

        class Test(object):
            pass
        mapper(Test, testtable)

        testtable.insert().execute({'id': 1, 'val': 'bob'})
        testtable.insert().execute({'id': 2, 'val': 'bobby'})
        testtable.insert().execute({'id': 3, 'val': 'alberto'})

        sess = create_session()
        getunless = unless(sess.query(Test).get)

        x = getunless(1)
        assert x.val == 'bob', x

        x = getunless(2)
        assert x.val == 'bobby', x

        assert_raises(ValueError, getunless, 5)
        assert_raises(TGValidationError, Convert(getunless).to_python, '5')

        x = Convert(getunless).to_python('1')
        assert x.val == 'bob', x
Exemplo n.º 2
0
    def test_unless_sqla(self):
        from sqlalchemy import (MetaData, Table, Column, Integer, String)
        from sqlalchemy.orm import create_session, mapper

        metadata = MetaData('sqlite:///:memory:')
        testtable = Table('test1', metadata,
                          Column('id', Integer, primary_key=True),
                          Column('val', String(8)))
        metadata.create_all()

        class Test(object):
            pass

        mapper(Test, testtable)

        testtable.insert().execute({'id': 1, 'val': 'bob'})
        testtable.insert().execute({'id': 2, 'val': 'bobby'})
        testtable.insert().execute({'id': 3, 'val': 'alberto'})

        sess = create_session()
        getunless = unless(sess.query(Test).get)

        x = getunless(1)
        assert x.val == 'bob', x

        x = getunless(2)
        assert x.val == 'bobby', x

        assert_raises(ValueError, getunless, 5)
        assert_raises(TGValidationError, Convert(getunless).to_python, '5')

        x = Convert(getunless).to_python('1')
        assert x.val == 'bob', x
Exemplo n.º 3
0
    def test_unless(self):
        not5 = unless(lambda x: x % 5, 0)
        assert not5(6) == 1

        assert_raises(ValueError, not5, 10)
Exemplo n.º 4
0
    def test_unless(self):
        not5 = unless(lambda x: x % 5, 0)
        assert not5(6) == 1

        assert_raises(ValueError, not5, 10)