pytestconf.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Mar 2010 13:59:47 +0100
branchstable
changeset 5013 ad91f93bbb93
parent 4804 daa71eaf11e8
child 5158 5e9055b8c10a
child 5421 8167de96c523
permissions -rw-r--r--
[source storage] refactor source sql generation and results handling to allow repository side callbacks for instance with the BytesFileSystemStorage, before this change: * fspath, _fsopen function were stored procedures executed on the database -> files had to be available both on the repository *and* the database host * we needed implementation for each handled database Now, those function are python callbacks executed when necessary on the repository side, on data comming from the database. The litle cons are: * you can't do anymore restriction on mapped attributes * you can't write queries which will return in the same rset column some mapped attributes (or not mapped the same way) / some not This seems much acceptable since: * it's much more easy to handle when you start having the db on another host than the repo * BFSS works seemlessly on any backend now * you don't bother that much about the cons (at least in the bfss case): you usually don't do any restriction on Bytes... Bonus points: BFSS is more efficient (no queries under the cover as it was done in the registered procedure) and we have a much nicer/efficient fspath implementation. IMO, that rocks :D
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
"""pytest configuration file: we need this to properly remove ressources
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
cached on test classes, at least until we've proper support for teardown_class
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
"""
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
import sys
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
from os.path import split, splitext
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
from logilab.common.pytest import PyTester
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
from cubicweb.etwist.server import _gc_debug
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
class CustomPyTester(PyTester):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    def testfile(self, filename, batchmode=False):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
        try:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
            return super(CustomPyTester, self).testfile(filename, batchmode)
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
        finally:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
            modname = splitext(split(filename)[1])[0]
4804
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    16
            try:
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    17
                module = sys.modules[modname]
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    18
            except KeyError:
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    19
                # error during test module import
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    20
                return
daa71eaf11e8 no key error subsequent to test module import error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4796
diff changeset
    21
            for cls in vars(module).values():
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
                if getattr(cls, '__module__', None) != modname:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
                    continue
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
                clean_repo_test_cls(cls)
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
            #_gc_debug()
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
def clean_repo_test_cls(cls):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    if 'repo' in cls.__dict__:
4796
a20edc0f8b30 oops, 'not' missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4777
diff changeset
    29
        if not cls.repo._shutting_down:
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
            cls.repo.shutdown()
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
        del cls.repo
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
    for clsattr in ('cnx', '_orig_cnx', 'config', '_config', 'vreg', 'schema'):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
        if clsattr in cls.__dict__:
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
            delattr(cls, clsattr)