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

« back to all changes in this revision

Viewing changes to test/aaa_profiling/test_resultset.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2012-06-17 23:25:01 UTC
  • mfrom: (1.4.21)
  • Revision ID: package-import@ubuntu.com-20120617232501-1ey18snu5pv5ivfv
Tags: 0.7.8-1
* New upstream release
* Add hardening flags (via /usr/share/dpkg/buildflags.mk)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from sqlalchemy import *
2
2
from test.lib import *
 
3
from test.lib.testing import eq_
3
4
NUM_FIELDS = 10
4
5
NUM_RECORDS = 1000
5
6
 
93
94
            e.execute("select 1")
94
95
        go()
95
96
 
 
97
 
 
98
class RowProxyTest(fixtures.TestBase):
 
99
    def _rowproxy_fixture(self, keys, processors, row):
 
100
        from sqlalchemy.engine.base import RowProxy
 
101
        class MockMeta(object):
 
102
            def __init__(self):
 
103
                pass
 
104
 
 
105
        metadata = MockMeta()
 
106
 
 
107
        keymap = {}
 
108
        for index, (keyobjs, processor, values) in \
 
109
            enumerate(zip(keys, processors, row)):
 
110
            for key in keyobjs:
 
111
                keymap[key] = (processor, key, index)
 
112
            keymap[index] = (processor, key, index)
 
113
        return RowProxy(metadata, row, processors, keymap)
 
114
 
 
115
    def _test_getitem_value_refcounts(self, seq_factory):
 
116
        import sys
 
117
        col1, col2 = object(), object()
 
118
        def proc1(value):
 
119
            return value
 
120
        value1, value2 = "x", "y"
 
121
        row = self._rowproxy_fixture(
 
122
            [(col1, "a"),(col2, "b")],
 
123
            [proc1, None],
 
124
            seq_factory([value1, value2])
 
125
        )
 
126
 
 
127
        v1_refcount = sys.getrefcount(value1)
 
128
        v2_refcount = sys.getrefcount(value2)
 
129
        for i in range(10):
 
130
            row[col1]
 
131
            row["a"]
 
132
            row[col2]
 
133
            row["b"]
 
134
            row[0]
 
135
            row[1]
 
136
            row[0:2]
 
137
        eq_(sys.getrefcount(value1), v1_refcount)
 
138
        eq_(sys.getrefcount(value2), v2_refcount)
 
139
 
 
140
    def test_value_refcounts_pure_tuple(self):
 
141
        self._test_getitem_value_refcounts(tuple)
 
142
 
 
143
    def test_value_refcounts_custom_seq(self):
 
144
        class CustomSeq(object):
 
145
            def __init__(self, data):
 
146
                self.data = data
 
147
 
 
148
            def __getitem__(self, item):
 
149
                return self.data[item]
 
150
 
 
151
            def __iter__(self):
 
152
                return iter(self.data)
 
153
        self._test_getitem_value_refcounts(CustomSeq)