当前位置: 首页>>代码示例>>Python>>正文


Python dbtest.setupClass函数代码示例

本文整理汇总了Python中sqlobject.tests.dbtest.setupClass函数的典型用法代码示例。如果您正苦于以下问题:Python setupClass函数的具体用法?Python setupClass怎么用?Python setupClass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setupClass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mxDateTime

    def test_mxDateTime():
        setupClass(DateTime2)
        _now = now()
        dt2 = DateTime2(col1=_now, col2=_now,
                        col3=Time(_now.hour, _now.minute, _now.second))

        assert isinstance(dt2.col1, col.DateTimeType)
        assert dt2.col1.year == _now.year
        assert dt2.col1.month == _now.month
        assert dt2.col1.day == _now.day
        assert dt2.col1.hour == _now.hour
        assert dt2.col1.minute == _now.minute
        assert dt2.col1.second == int(_now.second)

        assert isinstance(dt2.col2, col.DateTimeType)
        assert dt2.col2.year == _now.year
        assert dt2.col2.month == _now.month
        assert dt2.col2.day == _now.day
        if getConnection().dbName == "sqlite":
            assert dt2.col2.hour == _now.hour
            assert dt2.col2.minute == _now.minute
            assert dt2.col2.second == int(_now.second)
        else:
            assert dt2.col2.hour == 0
            assert dt2.col2.minute == 0
            assert dt2.col2.second == 0

        assert isinstance(dt2.col3, (col.DateTimeType, col.TimeType))
        assert dt2.col3.hour == _now.hour
        assert dt2.col3.minute == _now.minute
        assert dt2.col3.second == int(_now.second)
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:31,代码来源:test_datetime.py

示例2: test_foreignKey

def test_foreignKey():
    setupClass([SOTestSO4, SOTestSO3])
    test3_order = [col.name for col in SOTestSO3.sqlmeta.columnList]
    assert test3_order == ['name', 'otherID', 'other2ID']
    tc3 = SOTestSO3(name='a')
    assert tc3.other is None
    assert tc3.other2 is None
    assert tc3.otherID is None
    assert tc3.other2ID is None
    tc4a = SOTestSO4(me='1')
    tc3.other = tc4a
    assert tc3.other == tc4a
    assert tc3.otherID == tc4a.id
    tc4b = SOTestSO4(me='2')
    tc3.other = tc4b.id
    assert tc3.other == tc4b
    assert tc3.otherID == tc4b.id
    tc4c = SOTestSO4(me='3')
    tc3.other2 = tc4c
    assert tc3.other2 == tc4c
    assert tc3.other2ID == tc4c.id
    tc4d = SOTestSO4(me='4')
    tc3.other2 = tc4d.id
    assert tc3.other2 == tc4d
    assert tc3.other2ID == tc4d.id
    tcc = SOTestSO3(name='b', other=tc4a)
    assert tcc.other == tc4a
    tcc2 = SOTestSO3(name='c', other=tc4a.id)
    assert tcc2.other == tc4a
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:29,代码来源:test_basic.py

示例3: test_sqlite_factory_str

def test_sqlite_factory_str():
    setupClass(SQLiteFactoryTest)

    if SQLiteFactoryTest._connection.dbName != "sqlite":
        pytest.skip("These tests require SQLite")
    if not SQLiteFactoryTest._connection.using_sqlite2:
        pytest.skip("These tests require SQLite v2+")

    factory = [None]

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            pass
        factory[0] = MyConnection
        return MyConnection

    from sqlobject.sqlite import sqliteconnection
    sqliteconnection.SQLiteConnectionFactory = SQLiteConnectionFactory

    setSQLiteConnectionFactory(SQLiteFactoryTest, "SQLiteConnectionFactory")

    conn = SQLiteFactoryTest._connection.makeConnection()
    assert factory[0]
    assert isinstance(conn, factory[0])
    del sqliteconnection.SQLiteConnectionFactory
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:25,代码来源:test_sqlite.py

示例4: test_creation_fail2

def test_creation_fail2():
    """
    Try to create two Managers with the same position.
    This should fail without leaving any partial records in
    the database.

    """
    setupClass([DIManager, DIEmployee, DIPerson])

    kwargs = {'firstName': 'John', 'lastName': 'Doe',
              'position': 'Project Manager'}
    DIManager(**kwargs)
    persons = DIEmployee.select(DIPerson.q.firstName == 'John')
    assert persons.count() == 1

    kwargs = {'firstName': 'John', 'lastName': 'Doe II',
              'position': 'Project Manager'}
    raises(Exception, DIManager, **kwargs)
    persons = DIPerson.select(DIPerson.q.firstName == 'John')
    assert persons.count() == 1

    if not supports('transactions'):
        skip("Transactions aren't supported")
    transaction = DIPerson._connection.transaction()
    kwargs = {'firstName': 'John', 'lastName': 'Doe III',
              'position': 'Project Manager'}
    raises(Exception, DIManager, connection=transaction, **kwargs)
    transaction.rollback()
    transaction.begin()
    persons = DIPerson.select(DIPerson.q.firstName == 'John',
                              connection=transaction)
    assert persons.count() == 1
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:32,代码来源:test_deep_inheritance.py

示例5: setup

def setup():
    setupClass(InheritablePerson)
    setupClass(Employee)

    Employee(firstName='Project', lastName='Leader',
             so_position='Project leader')
    InheritablePerson(firstName='Oneof', lastName='Authors')
开发者ID:sqlobject,项目名称:sqlobject,代码行数:7,代码来源:test_inheritance.py

示例6: test_mxDateTime

    def test_mxDateTime():
        setupClass(DateTime2)
        _now = now()
        dt2 = DateTime2(col1=_now, col2=_now.pydate(),
                        col3=Time(_now.hour, _now.minute, _now.second))

        assert isinstance(dt2.col1, col.DateTimeType)
        assert dt2.col1.year == _now.year
        assert dt2.col1.month == _now.month
        assert dt2.col1.day == _now.day
        assert dt2.col1.hour == _now.hour
        assert dt2.col1.minute == _now.minute
        assert dt2.col1.second == int(_now.second)

        assert isinstance(dt2.col2, col.DateTimeType)
        assert dt2.col2.year == _now.year
        assert dt2.col2.month == _now.month
        assert dt2.col2.day == _now.day
        assert dt2.col2.hour == 0
        assert dt2.col2.minute == 0
        assert dt2.col2.second == 0

        assert isinstance(dt2.col3, (col.DateTimeType, col.TimeType))
        assert dt2.col3.hour == _now.hour
        assert dt2.col3.minute == _now.minute
        assert dt2.col3.second == int(_now.second)
开发者ID:sqlobject,项目名称:sqlobject,代码行数:26,代码来源:test_datetime.py

示例7: setup_method

 def setup_method(self, meth):
     setupClass([PersonJNew2, AddressJNew2])
     p1 = PersonJNew2(name='bob')
     p2 = PersonJNew2(name='sally')
     for z in ['11111', '22222', '33333']:
         AddressJNew2(zip=z, personJNew2=p1)
     AddressJNew2(zip='00000', personJNew2=p2)
开发者ID:sqlobject,项目名称:sqlobject,代码行数:7,代码来源:test_new_joins.py

示例8: testDestroySelf

def testDestroySelf():
    setupClass(NoCache)
    old = NoCache._connection.cache
    NoCache._connection.cache = cache.CacheSet(cache=False)
    value = NoCache(name='test')
    value.destroySelf()
    NoCache._connection.cache = old
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_delete.py

示例9: setup_method

 def setup_method(self, meth):
     setupClass([PersonJoinerNew3, AddressJoinerNew3])
     p1 = PersonJoinerNew3(name='bob')
     p2 = PersonJoinerNew3(name='sally')
     for z in ['11111', '22222', '33333']:
         AddressJoinerNew3(zip=z, personJoinerNew3=p1)
     AddressJoinerNew3(zip='00000', personJoinerNew3=p2)
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_new_joins.py

示例10: test_style

def test_style():
    setupClass([SOStyleTest2, SOStyleTest1])
    st1 = SOStyleTest1(a='something', st2=None)
    st2 = SOStyleTest2(b='whatever')
    st1.st2 = st2
    assert st1.sqlmeta.columns['st2ID'].dbName == 'idst2'
    assert st1.st2 == st2
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_style.py

示例11: test_sub

def test_sub():
    setupClass(Super)
    setupClass(Sub)
    s1 = Sub(name='one', name2='1')
    Sub(name='two', name2='2')  # s2
    s3 = Sub.get(s1.id)
    assert s1 == s3
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_inheritance.py

示例12: test_super

def test_super():
    setupClass(Super)
    setupClass(Sub)
    s1 = Super(name='one')
    Super(name='two')  # s2
    s3 = Super.get(s1.id)
    assert s1 == s3
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_inheritance.py

示例13: test_sqlite_aggregate

def test_sqlite_aggregate():
    setupClass(SQLiteFactoryTest)

    if not SQLiteFactoryTest._connection.using_sqlite2:
        pytest.skip("These tests require SQLite v2+")

    def SQLiteConnectionFactory(sqlite):
        class MyConnection(sqlite.Connection):
            def __init__(self, *args, **kwargs):
                super(MyConnection, self).__init__(*args, **kwargs)
                self.create_aggregate("group_concat", 1, self.group_concat)

            class group_concat:
                def __init__(self):
                    self.acc = []

                def step(self, value):
                    if isinstance(value, string_type):
                        self.acc.append(value)
                    else:
                        self.acc.append(str(value))

                def finalize(self):
                    self.acc.sort()
                    return ", ".join(self.acc)

        return MyConnection

    setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)

    SQLiteFactoryTest(name='sqlobject')
    SQLiteFactoryTest(name='sqlbuilder')
    assert SQLiteFactoryTest.select(orderBy="name").\
        accumulateOne("group_concat", "name") == \
        "sqlbuilder, sqlobject"
开发者ID:sqlobject,项目名称:sqlobject,代码行数:35,代码来源:test_sqlite.py

示例14: testUnicode

def testUnicode():
    setupClass(EnumUnicode)

    EnumUnicode(n=u'a', l='a')
    EnumUnicode(n=u'b', l=u'b')
    EnumUnicode(n=u'\u201c', l='a')
    EnumUnicode(n=u'\u201c', l=u'b')
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:7,代码来源:test_enum.py

示例15: testDeleteRelatedJoins

def testDeleteRelatedJoins():
    setupClass([Service, ServiceGroup])
    service = Service()
    service_group = ServiceGroup()
    service.addServiceGroup(service_group)
    service.destroySelf()
    service_group = ServiceGroup.get(service_group.id)
    assert len(service_group.services) == 0
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:8,代码来源:test_delete.py


注:本文中的sqlobject.tests.dbtest.setupClass函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。