Source

pypy / pypy / conftest.py

Full commit
Amaury Forgeot d… 5797cd7 

Armin Rigo 6a00154 
Maciej Fijalkows… 2eb1efc 
Benjamin Peterso… 836e7a0 
Maciej Fijalkows… 2eb1efc 
Samuele Pedroni 3353f63 
Alex Gaynor 563412e 

Armin Rigo 6a00154 
holger krekel a2faa1e 

Ronny Pfannschmi… 463589f 




Armin Rigo ffd617d 


Ronny Pfannschmi… 463589f 


holger krekel 05555a5 


Amaury Forgeot d… 0d4cf3d 





holger krekel 0a60a21 


holger krekel 61a185b 
Maciej Fijalkows… 75307d4 





holger krekel 61a185b 
Samuele Pedroni 3353f63 
holger krekel aad17f5 
Samuele Pedroni 3353f63 










Maciej Fijalkows… 5de5a9d 



holger krekel 2336b93 
Benjamin Peterso… 487ce4b 






Samuele Pedroni 3353f63 
Amaury Forgeot d… 607b9ab 
holger krekel c055021 

holger krekel ae7a328 
Armin Rigo c51057c 
Alex Gaynor 563412e 

Armin Rigo 6a00154 
holger krekel ecddc10 
Samuele Pedroni 15de6a5 
holger krekel ecddc10 

Alex Gaynor 563412e 
holger krekel ecddc10 
Alex Gaynor 563412e 

holger krekel ecddc10 
Alex Gaynor 563412e 
holger krekel ecddc10 

Armin Rigo 6a00154 
Amaury Forgeot d… 39c30ae 




holger krekel c055021 


Alex Gaynor 563412e 




Armin Rigo 592e684 
holger krekel 0a60a21 
Benjamin Peterso… 836e7a0 



Armin Rigo 592e684 



Armin Rigo c51057c 
Armin Rigo 592e684 
Armin Rigo c51057c 



Benjamin Peterso… 836e7a0 
Armin Rigo c51057c 
Armin Rigo 592e684 
Armin Rigo c51057c 

Maciej Fijalkows… dd8bf2a 




Armin Rigo c51057c 
holger krekel 61a185b 
Alex Gaynor 563412e 


Amaury Forgeot d… 5797cd7 
Maciej Fijalkows… dd8bf2a 

holger krekel 05555a5 
Maciej Fijalkows… dd8bf2a 
Amaury Forgeot d… 5797cd7 
Maciej Fijalkows… dd8bf2a 






Amaury Forgeot d… 5797cd7 
Maciej Fijalkows… dd8bf2a 
Alex Gaynor 563412e 


holger krekel 61a185b 
Alex Gaynor 563412e 
Amaury Forgeot d… 5797cd7 
Alex Gaynor 563412e 

holger krekel 183ecfd 
Alex Gaynor 563412e 
Amaury Forgeot d… 5797cd7 
Alex Gaynor 563412e 
Armin Rigo 6a00154 
Alex Gaynor 563412e 
holger krekel 80bb528 






Alex Gaynor 563412e 

holger krekel 80bb528 


Alex Gaynor 563412e 
holger krekel 80bb528 

Armin Rigo b249b23 

Amaury Forgeot d… 607b9ab 
Armin Rigo b249b23 




Armin Rigo 6a00154 
Amaury Forgeot d… ef5bb4e 
Amaury Forgeot d… 39c30ae 
Amaury Forgeot d… fe7b3ee 

Amaury Forgeot d… a03792c 
Amaury Forgeot d… fe7b3ee 
Amaury Forgeot d… 9fa214a 
Amaury Forgeot d… 607b9ab 
Amaury Forgeot d… fe7b3ee 
Amaury Forgeot d… a03792c 
Amaury Forgeot d… fe7b3ee 
Amaury Forgeot d… ef5bb4e 
Amaury Forgeot d… fe7b3ee 
Amaury Forgeot d… ef5bb4e 






Armin Rigo 6a00154 
holger krekel 6a71563 
Amaury Forgeot d… 5797cd7 
Maciej Fijalkows… dd8bf2a 
Alex Gaynor 563412e 
holger krekel c055021 
Alex Gaynor 563412e 
holger krekel c055021 

Alex Gaynor 563412e 
holger krekel c055021 
Armin Rigo 3f9ec85 
holger krekel c055021 
import py, pytest, sys, os, textwrap
from inspect import isclass

# pytest settings
rsyncdirs = ['.', '../lib-python', '../lib_pypy', '../demo']
rsyncignore = ['_cache']

# PyPy's command line extra options (these are added
# to py.test's standard options)
#
option = None


def braindead_deindent(self):
    """monkeypatch that wont end up doing stupid in the python tokenizer"""
    text = '\n'.join(self.lines)
    short = py.std.textwrap.dedent(text)
    newsource = py.code.Source()
    newsource.lines[:] = short.splitlines()
    return newsource

py.code.Source.deindent = braindead_deindent

def pytest_report_header():
    return "pytest-%s from %s" %(pytest.__version__, pytest.__file__)


def pytest_addhooks(pluginmanager):
    from pypy.tool.pytest.plugins import LeakFinder
    pluginmanager.register(LeakFinder())


def pytest_configure(config):
    global option
    option = config.option

def _set_platform(opt, opt_str, value, parser):
    from pypy.config.translationoption import PLATFORMS
    from pypy.translator.platform import set_platform
    if value not in PLATFORMS:
        raise ValueError("%s not in %s" % (value, PLATFORMS))
    set_platform(value, None)

def pytest_addoption(parser):
    group = parser.getgroup("pypy options")
    group.addoption('--view', action="store_true", dest="view", default=False,
           help="view translation tests' flow graphs with Pygame")
    group.addoption('-A', '--runappdirect', action="store_true",
           default=False, dest="runappdirect",
           help="run applevel tests directly on python interpreter (not through PyPy)")
    group.addoption('--direct', action="store_true",
           default=False, dest="rundirect",
           help="run pexpect tests directly")
    group.addoption('-P', '--platform', action="callback", type="string",
           default="host", callback=_set_platform,
           help="set up tests to use specified platform as compile/run target")
    group = parser.getgroup("JIT options")
    group.addoption('--viewloops', action="store_true",
           default=False, dest="viewloops",
           help="show only the compiled loops")

def pytest_sessionstart():
    # have python subprocesses avoid startup customizations by default
    try:
        del os.environ['PYTHONSTARTUP']
    except KeyError:
        pass

def pytest_funcarg__space(request):
    from pypy.tool.pytest.objspace import gettestobjspace
    spaceconfig = getattr(request.cls, 'spaceconfig', {})
    return gettestobjspace(**spaceconfig)


#
# Interfacing/Integrating with py.test's collection process
#
#

def ensure_pytest_builtin_helpers(helpers='skip raises'.split()):
    """ hack (py.test.) raises and skip into builtins, needed
        for applevel tests to run directly on cpython but
        apparently earlier on "raises" was already added
        to module's globals.
    """
    import __builtin__
    for helper in helpers:
        if not hasattr(__builtin__, helper):
            setattr(__builtin__, helper, getattr(py.test, helper))

def pytest_sessionstart(session):
    """ before session.main() is called. """
    # stick py.test raise in module globals -- carefully
    ensure_pytest_builtin_helpers()

def pytest_pycollect_makemodule(path, parent):
    return PyPyModule(path, parent)

class PyPyModule(py.test.collect.Module):
    """ we take care of collecting classes both at app level
        and at interp-level (because we need to stick a space
        at the class) ourselves.
    """
    def accept_regular_test(self):
        if self.config.option.runappdirect:
            # only collect regular tests if we are in an 'app_test' directory,
            # or in test_lib_pypy
            names = self.listnames()
            return "app_test" in names or "test_lib_pypy" in names
        else:
            return True

    def funcnamefilter(self, name):
        if name.startswith('test_'):
            return self.accept_regular_test()
        if name.startswith('app_test_'):
            return True
        return False

    def classnamefilter(self, name):
        if name.startswith('Test'):
            return self.accept_regular_test()
        if name.startswith('AppTest'):
            return True
        if name.startswith('ExpectTest'):
            return True
        #XXX todo
        #if name.startswith('AppExpectTest'):
        #    return True
        return False

    def makeitem(self, name, obj):
        if isclass(obj) and self.classnamefilter(name):
            if name.startswith('AppTest'):
                from pypy.tool.pytest.apptest import AppClassCollector
                return AppClassCollector(name, parent=self)
            elif name.startswith('ExpectTest'):
                if self.config.option.rundirect:
                    return py.test.collect.Class(name, parent=self)
                from pypy.tool.pytest.expecttest import ExpectClassCollector
                return ExpectClassCollector(name, parent=self)
            # XXX todo
            #elif name.startswith('AppExpectTest'):
            #    if option.rundirect:
            #        return AppClassCollector(name, parent=self)
            #    return AppExpectClassCollector(name, parent=self)
            else:
                from pypy.tool.pytest.inttest import IntClassCollector
                return IntClassCollector(name, parent=self)

        elif hasattr(obj, 'func_code') and self.funcnamefilter(name):
            if name.startswith('app_test_'):
                assert not obj.func_code.co_flags & 32, \
                    "generator app level functions? you must be joking"
                from pypy.tool.pytest.apptest import AppTestFunction
                return AppTestFunction(name, parent=self)
            elif obj.func_code.co_flags & 32: # generator function
                return pytest.Generator(name, parent=self)
            else:
                from pypy.tool.pytest.inttest import IntTestFunction
                return IntTestFunction(name, parent=self)

def skip_on_missing_buildoption(**ropts):
    __tracebackhide__ = True
    import sys
    options = getattr(sys, 'pypy_translation_info', None)
    if options is None:
        py.test.skip("not running on translated pypy "
                     "(btw, i would need options: %s)" %
                     (ropts,))
    for opt in ropts:
        if not options.has_key(opt) or options[opt] != ropts[opt]:
            break
    else:
        return
    py.test.skip("need translated pypy with: %s, got %s"
                 %(ropts,options))

class LazyObjSpaceGetter(object):
    def __get__(self, obj, cls=None):
        from pypy.tool.pytest.objspace import gettestobjspace
        space = gettestobjspace()
        if cls:
            cls.space = space
        return space


def pytest_runtest_setup(__multicall__, item):
    if isinstance(item, py.test.collect.Function):
        appclass = item.getparent(PyPyClassCollector)
        if appclass is not None:
            # Make cls.space and cls.runappdirect available in tests.
            spaceconfig = getattr(appclass.obj, 'spaceconfig', None)
            if spaceconfig is not None:
                from pypy.tool.pytest.objspace import gettestobjspace
                appclass.obj.space = gettestobjspace(**spaceconfig)
            appclass.obj.runappdirect = option.runappdirect

    __multicall__.execute()

def pytest_runtest_teardown(__multicall__, item):
    __multicall__.execute()

    if 'pygame' in sys.modules:
        assert option.view, ("should not invoke Pygame "
                             "if conftest.option.view is False")


class PyPyClassCollector(py.test.collect.Class):
    # All pypy Test classes have a "space" member.
    def setup(self):
        cls = self.obj
        if not hasattr(cls, 'spaceconfig'):
            cls.space = LazyObjSpaceGetter()
        else:
            assert hasattr(cls, 'space') # set by pytest_runtest_setup
        super(PyPyClassCollector, self).setup()


def pytest_ignore_collect(path):
    return path.check(link=1)