~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/aaa_profiling/test_memusage.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-08-01 23:18:16 UTC
  • mfrom: (1.4.15 upstream) (16.1.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20110801231816-6lx797pi3q1fpqst
Tags: 0.7.2-1
* New upstream release
* Bump minimum required python-mako version to 0.4.1 (closes: 635898)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from sqlalchemy.test.testing import eq_
 
1
from test.lib.testing import eq_
2
2
from sqlalchemy.orm import mapper, relationship, create_session, \
3
3
    clear_mappers, sessionmaker, class_mapper
4
4
from sqlalchemy.orm.mapper import _mapper_registry
5
5
from sqlalchemy.orm.session import _sessions
6
 
from sqlalchemy.util import jython
7
6
import operator
8
 
from sqlalchemy.test import testing, engines
 
7
from test.lib import testing, engines
9
8
from sqlalchemy import MetaData, Integer, String, ForeignKey, \
10
9
    PickleType, create_engine, Unicode
11
 
from sqlalchemy.test.schema import Table, Column
 
10
from test.lib.schema import Table, Column
12
11
import sqlalchemy as sa
13
12
from sqlalchemy.sql import column
14
13
from sqlalchemy.processors import to_decimal_processor_factory, \
15
14
    to_unicode_processor_factory
16
 
from sqlalchemy.test.util import gc_collect
17
 
from decimal import Decimal as _python_Decimal
 
15
from test.lib.util import gc_collect
 
16
from sqlalchemy.util.compat import decimal
18
17
import gc
19
18
import weakref
20
 
from test.orm import _base
21
 
 
22
 
if jython:
23
 
    from nose import SkipTest
24
 
    raise SkipTest("Profiling not supported on this platform")
25
 
 
26
 
 
27
 
class A(_base.ComparableEntity):
 
19
from test.lib import fixtures
 
20
 
 
21
class A(fixtures.ComparableEntity):
28
22
    pass
29
 
class B(_base.ComparableEntity):
 
23
class B(fixtures.ComparableEntity):
30
24
    pass
31
25
 
32
26
def profile_memory(func):
68
62
    gc_collect()
69
63
    assert len(_mapper_registry) == 0
70
64
 
71
 
class EnsureZeroed(_base.ORMTest):
 
65
class EnsureZeroed(fixtures.ORMTest):
72
66
    def setup(self):
73
67
        _sessions.clear()
74
68
        _mapper_registry.clear()
75
69
 
76
70
class MemUsageTest(EnsureZeroed):
77
71
 
 
72
    __requires__ = 'cpython',
 
73
 
78
74
    # ensure a pure growing test trips the assertion
79
75
    @testing.fails_if(lambda: True)
80
76
    def test_fixture(self):
176
172
        def go():
177
173
            engine = engines.testing_engine(
178
174
                                options={'logging_name':'FOO',
179
 
                                        'pool_logging_name':'BAR'}
 
175
                                        'pool_logging_name':'BAR',
 
176
                                        'use_reaper':False}
180
177
                                    )
181
178
            sess = create_session(bind=engine)
182
179
 
211
208
        del m1, m2, m3
212
209
        assert_no_mappers()
213
210
 
 
211
    def test_ad_hoc_types(self):
 
212
        """test storage of bind processors, result processors
 
213
        in dialect-wide registry."""
 
214
 
 
215
        from sqlalchemy.dialects import mysql, postgresql, sqlite
 
216
        from sqlalchemy import types
 
217
 
 
218
        eng = engines.testing_engine()
 
219
        for args in (
 
220
            (types.Integer, ),
 
221
            (types.String, ),
 
222
            (types.PickleType, ),
 
223
            (types.Enum, 'a', 'b', 'c'),
 
224
            (sqlite.DATETIME, ),
 
225
            (postgresql.ENUM, 'a', 'b', 'c'),
 
226
            (types.Interval, ),
 
227
            (postgresql.INTERVAL, ),
 
228
            (mysql.VARCHAR, ),
 
229
        ):
 
230
            @profile_memory
 
231
            def go():
 
232
                type_ = args[0](*args[1:])
 
233
                bp = type_._cached_bind_processor(eng.dialect)
 
234
                rp = type_._cached_result_processor(eng.dialect, 0)
 
235
            go()
 
236
 
 
237
        assert not eng.dialect._type_memos
 
238
 
 
239
 
214
240
    def test_many_updates(self):
215
241
        metadata = MetaData(testing.db)
216
242
 
359
385
 
360
386
        @profile_memory
361
387
        def go():
362
 
            class A(_base.ComparableEntity):
 
388
            class A(fixtures.ComparableEntity):
363
389
                pass
364
390
            class B(A):
365
391
                pass
425
451
 
426
452
        @profile_memory
427
453
        def go():
428
 
            class A(_base.ComparableEntity):
 
454
            class A(fixtures.ComparableEntity):
429
455
                pass
430
 
            class B(_base.ComparableEntity):
 
456
            class B(fixtures.ComparableEntity):
431
457
                pass
432
458
 
433
459
            mapper(A, table1, properties={
517
543
        table1 = Table("mytable", metadata,
518
544
            Column('col1', Integer, primary_key=True,
519
545
                                test_needs_autoincrement=True),
520
 
            Column('col2', PickleType(comparator=operator.eq))
 
546
            Column('col2', PickleType(comparator=operator.eq, mutable=True))
521
547
            )
522
548
 
523
549
        class Foo(object):
580
606
    def test_DecimalResultProcessor_process(self):
581
607
        @profile_memory
582
608
        def go():
583
 
            to_decimal_processor_factory(_python_Decimal, 10)(1.2)
 
609
            to_decimal_processor_factory(decimal.Decimal, 10)(1.2)
584
610
        go()
585
611
 
586
612
    @testing.requires.cextensions