Exemple #1
0
    def test_hash_agains_normal_tuple(self):
        normalspace = gettestobjspace(**{"objspace.std.withsmalltuple": False})
        w_tuple = normalspace.newtuple([self.space.wrap(1), self.space.wrap(2)])

        smallspace = gettestobjspace(**{"objspace.std.withsmalltuple": True})
        w_smalltuple = smallspace.newtuple([self.space.wrap(1), self.space.wrap(2)])

        assert isinstance(w_smalltuple, W_SmallTupleObject)
        assert isinstance(w_tuple, W_TupleObject)
        assert not normalspace.is_true(normalspace.eq(w_tuple, w_smalltuple))
        assert smallspace.is_true(smallspace.eq(w_tuple, w_smalltuple))
        assert smallspace.is_true(smallspace.eq(normalspace.hash(w_tuple), smallspace.hash(w_smalltuple)))
Exemple #2
0
    def collect(self):
        _, source = app_rewrite._prepare_source(self.fspath)
        spaceconfig = extract_spaceconfig_from_source(source)
        space = objspace.gettestobjspace(**spaceconfig)
        w_rootdir = space.newtext(
            os.path.join(pypydir, 'tool', 'pytest', 'ast-rewriter'))
        w_source = space.newtext(source)
        fname = str(self.fspath)
        w_name = space.newtext(str(self.fspath.purebasename))
        w_fname = space.newtext(fname)
        if self.rewrite_asserts:
            w_mod = space.appexec([w_rootdir, w_source, w_fname, w_name],
                                  """(rootdir, source, fname, name):
                import sys
                sys.path.insert(0, rootdir)
                from ast_rewrite import rewrite_asserts, create_module

                co = rewrite_asserts(source, fname)
                mod = create_module(name, co)
                return mod
            """)
        else:
            w_mod = create_module(space, w_name, fname, source)
        mod_dict = w_mod.getdict(space).unwrap(space)
        items = []
        for name, w_obj in mod_dict.items():
            if not name.startswith('test_'):
                continue
            if not isinstance(w_obj, pypy.interpreter.function.Function):
                continue
            items.append(AppTestFunction(name, self, w_obj))
        items.sort(key=lambda item: item.reportinfo()[:2])
        return items
Exemple #3
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=['_socket', 'array', 'struct'])
    global socket
    import socket
    mod.w_socket = space.appexec([], "(): import _socket as m; return m")
    mod.path = udir.join('fd')
    mod.path.write('fo')
    def test_hash_agains_normal_tuple(self):
        normalspace = gettestobjspace(**{"objspace.std.withsmalltuple": False})
        w_tuple = normalspace.newtuple(
            [self.space.wrap(1), self.space.wrap(2)])

        smallspace = gettestobjspace(**{"objspace.std.withsmalltuple": True})
        w_smalltuple = smallspace.newtuple(
            [self.space.wrap(1), self.space.wrap(2)])

        assert isinstance(w_smalltuple, W_SmallTupleObject)
        assert isinstance(w_tuple, W_TupleObject)
        assert not normalspace.is_true(normalspace.eq(w_tuple, w_smalltuple))
        assert smallspace.is_true(smallspace.eq(w_tuple, w_smalltuple))
        assert smallspace.is_true(
            smallspace.eq(normalspace.hash(w_tuple),
                          smallspace.hash(w_smalltuple)))
Exemple #5
0
def setup_module(mod):
    usemodules = ["binascii", "posix", "signal", "struct", "time"]
    # py3k os.open uses subprocess, requiring the following per platform
    if os.name != "nt":
        usemodules += ["fcntl", "select"]
    else:
        usemodules += ["_rawffi", "thread"]
    mod.space = gettestobjspace(usemodules=usemodules)
    mod.path = udir.join("posixtestfile.txt")
    mod.path.write("this is a test")
    mod.path2 = udir.join("test_posix2-")
    pdir = udir.ensure("posixtestdir", dir=True)
    pdir.join("file1").write("test1")
    os.chmod(str(pdir.join("file1")), 0o600)
    pdir.join("file2").write("test2")
    pdir.join("another_longer_file_name").write("test3")
    mod.pdir = pdir
    bytes_dir = udir.ensure("fi\xc5\x9fier.txt", dir=True)
    bytes_dir.join("somefile").write("who cares?")
    bytes_dir.join("caf\xe9").write("who knows?")
    mod.bytes_dir = bytes_dir
    # an escaped surrogate
    mod.esurrogate_dir = udir.ensure("foo\x80", dir=True)

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #6
0
def test_direct():
    space = gettestobjspace(**{"objspace.std.withsmalllong": True})
    w5 = space.wrap(r_longlong(5))
    assert isinstance(w5, W_SmallLongObject)
    wlarge = space.wrap(r_longlong(0x123456789ABCDEFL))
    #
    assert space.int_w(w5) == 5
    if sys.maxint < 0x123456789ABCDEFL:
        with pytest.raises(OperationError):
            space.int_w(wlarge)
    else:
        assert space.int_w(wlarge) == 0x123456789ABCDEF
    #
    assert space.pos(w5) is w5
    assert space.abs(w5) is w5
    wm5 = space.wrap(r_longlong(-5))
    assert space.int_w(space.abs(wm5)) == 5
    assert space.int_w(space.neg(w5)) == -5
    assert space.is_true(w5) is True
    assert space.is_true(wm5) is True
    w0 = space.wrap(r_longlong(0))
    assert space.is_true(w0) is False
    #
    w14000000000000 = space.wrap(r_longlong(0x14000000000000L))
    assert space.is_true(
        space.eq(space.lshift(w5, space.wrap(49)), w14000000000000)) is False
    assert space.is_true(
        space.eq(space.lshift(w5, space.wrap(50)), w14000000000000)) is True
    #
    w_huge = space.sub(space.lshift(w5, space.wrap(150)), space.wrap(1))
    wx = space.and_(w14000000000000, w_huge)
    assert space.is_true(space.eq(wx, w14000000000000))

    w_obj = W_SmallLongObject.fromint(42)
    assert space.unwrap(w_obj) == 42
Exemple #7
0
def test_direct():
    space = gettestobjspace(**{"objspace.std.withsmalllong": True})
    w5 = space.wrap(r_longlong(5))
    assert isinstance(w5, W_SmallLongObject)
    wlarge = space.wrap(r_longlong(0x123456789ABCDEFL))
    #
    assert space.int_w(w5) == 5
    if sys.maxint < 0x123456789ABCDEFL:
        py.test.raises(OperationError, space.int_w, wlarge)
    else:
        assert space.int_w(wlarge) == 0x123456789ABCDEF
    #
    assert space.pos(w5) is w5
    assert space.abs(w5) is w5
    wm5 = space.wrap(r_longlong(-5))
    assert space.int_w(space.abs(wm5)) == 5
    assert space.int_w(space.neg(w5)) == -5
    assert space.is_true(w5) is True
    assert space.is_true(wm5) is True
    w0 = space.wrap(r_longlong(0))
    assert space.is_true(w0) is False
    #
    w14000000000000 = space.wrap(r_longlong(0x14000000000000L))
    assert space.is_true(space.eq(
        space.lshift(w5, space.wrap(49)), w14000000000000)) is False
    assert space.is_true(space.eq(
        space.lshift(w5, space.wrap(50)), w14000000000000)) is True
    #
    w_huge = space.sub(space.lshift(w5, space.wrap(150)), space.wrap(1))
    wx = space.and_(w14000000000000, w_huge)
    assert space.is_true(space.eq(wx, w14000000000000))

    w_obj = W_SmallLongObject.fromint(42)
    assert space.unwrap(w_obj) == 42
Exemple #8
0
 def collect(self):
     _, source = app_rewrite._prepare_source(self.fspath)
     spaceconfig = extract_spaceconfig_from_source(source)
     space = objspace.gettestobjspace(**spaceconfig)
     w_rootdir = space.newtext(
         os.path.join(pypydir, 'tool', 'pytest', 'astrewriter'))
     w_source = space.newtext(source)
     fname = str(self.fspath)
     w_name = space.newtext(str(self.fspath.purebasename))
     w_fname = space.newtext(fname)
     if self.rewrite_asserts:
         # actually a w_code, but works fine with space.exec_
         source = space._cached_compile(fname,
                                        source,
                                        "exec",
                                        0,
                                        False,
                                        ast_transform=rewrite_asserts_ast)
     w_mod = create_module(space, w_name, fname, source)
     mod_dict = w_mod.getdict(space).unwrap(space)
     items = []
     for name, w_obj in mod_dict.items():
         if not name.startswith('test_'):
             continue
         if not isinstance(w_obj, pypy.interpreter.function.Function):
             continue
         items.append(AppTestFunction(name, self, w_obj))
     items.sort(key=lambda item: item.reportinfo()[:2])
     return items
Exemple #9
0
def setup_module(mod):
    usemodules = ['binascii', 'posix', 'struct', 'time']
    if os.name != 'nt':
        usemodules += ['fcntl']
    else:
        # On windows, os.popen uses the subprocess module
        usemodules += ['_rawffi', 'thread', 'signal']
    mod.space = gettestobjspace(usemodules=usemodules)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
    unicode_dir.join('somefile').write('who cares?')
    unicode_dir.join('caf\xe9').write('who knows?')
    mod.unicode_dir = unicode_dir

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #10
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=['_socket', 'array', 'struct'])
    global socket
    import socket
    mod.w_socket = space.appexec([], "(): import _socket as m; return m")
    mod.path = udir.join('fd')
    mod.path.write('fo')
Exemple #11
0
def setup_module(mod):
    usemodules = ['binascii', 'posix', 'signal', 'struct', 'time']
    # py3k os.open uses subprocess, requiring the following per platform
    if os.name != 'nt':
        usemodules += ['fcntl', 'select']
    else:
        usemodules += ['_rawffi', 'thread']
    mod.space = gettestobjspace(usemodules=usemodules)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0o600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    bytes_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
    bytes_dir.join('somefile').write('who cares?')
    bytes_dir.join('caf\xe9').write('who knows?')
    mod.bytes_dir = bytes_dir
    # an escaped surrogate
    mod.esurrogate_dir = udir.ensure('foo\x80', dir=True)

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #12
0
def setup_module(mod):
    usemodules = ['binascii', 'posix', 'struct', 'time']
    if os.name != 'nt':
        usemodules += ['fcntl']
    else:
        # On windows, os.popen uses the subprocess module
        usemodules += ['_rawffi', 'thread', 'signal']
    mod.space = gettestobjspace(usemodules=usemodules)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
    unicode_dir.join('somefile').write('who cares?')
    unicode_dir.join('caf\xe9').write('who knows?')
    mod.unicode_dir = unicode_dir

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #13
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=USEMODULES)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    if sys.platform == 'darwin':
        # see issue https://bugs.python.org/issue31380
        unicode_dir = udir.ensure('fixc5x9fier.txt', dir=True)
        file_name = 'cafxe9'
    else:
        unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
        file_name = 'caf\xe9'
    unicode_dir.join('somefile').write('who cares?')
    unicode_dir.join(file_name).write('who knows?')
    mod.unicode_dir = unicode_dir

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #14
0
def pytest_configure(config):
    from pypy.tool.pytest.objspace import gettestobjspace
    # For some reason (probably a ll2ctypes cache issue on linux64)
    # it's necessary to run "import time" at least once before any
    # other cpyext test, otherwise the same statement will fail in
    # test_datetime.py.
    space = gettestobjspace(usemodules=['rctime'])
    space.getbuiltinmodule("time")
Exemple #15
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.tmpfile = tempfile.NamedTemporaryFile()
     cls.w_tmpfileno = cls.space.wrap(cls.tmpfile.fileno())
     cls.w_tmpfilename = cls.space.wrap(cls.tmpfile.name)
     cls.tmpfile2 = tempfile.NamedTemporaryFile()
     cls.w_tmpfileno2 = cls.space.wrap(cls.tmpfile2.fileno())
     cls.w_tmpfilename2 = cls.space.wrap(cls.tmpfile2.name)
Exemple #16
0
def pytest_configure(config):
    from pypy.tool.pytest.objspace import gettestobjspace
    # For some reason (probably a ll2ctypes cache issue on linux64)
    # it's necessary to run "import time" at least once before any
    # other cpyext test, otherwise the same statement will fail in
    # test_datetime.py.
    space = gettestobjspace(usemodules=['time'])
    space.getbuiltinmodule("time")
Exemple #17
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.tmpfile = udir.join('test__vmprof.1').open('wb')
     cls.w_tmpfileno = cls.space.wrap(cls.tmpfile.fileno())
     cls.w_tmpfilename = cls.space.wrap(cls.tmpfile.name)
     cls.tmpfile2 = udir.join('test__vmprof.2').open('wb')
     cls.w_tmpfileno2 = cls.space.wrap(cls.tmpfile2.fileno())
     cls.w_tmpfilename2 = cls.space.wrap(cls.tmpfile2.name)
Exemple #18
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.tmpfile = tempfile.NamedTemporaryFile()
     cls.w_tmpfileno = cls.space.wrap(cls.tmpfile.fileno())
     cls.w_tmpfilename = cls.space.wrap(cls.tmpfile.name)
     cls.tmpfile2 = tempfile.NamedTemporaryFile()
     cls.w_tmpfileno2 = cls.space.wrap(cls.tmpfile2.fileno())
     cls.w_tmpfilename2 = cls.space.wrap(cls.tmpfile2.name)
Exemple #19
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.tmpfile = udir.join('test__vmprof.1').open('wb')
     cls.w_tmpfileno = cls.space.wrap(cls.tmpfile.fileno())
     cls.w_tmpfilename = cls.space.wrap(cls.tmpfile.name)
     cls.tmpfile2 = udir.join('test__vmprof.2').open('wb')
     cls.w_tmpfileno2 = cls.space.wrap(cls.tmpfile2.fileno())
     cls.w_tmpfilename2 = cls.space.wrap(cls.tmpfile2.name)
Exemple #20
0
 def runtest(self):
     target = self.obj
     if self.config.option.runappdirect:
         return target()
     space = gettestobjspace()
     filename = self._getdynfilename(target)
     func = app2interp_temp(target, filename=filename)
     print "executing", func
     self.execute_appex(space, func, space)
Exemple #21
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=['_socket', 'array', 'struct'])
    global socket
    import socket
    mod.w_socket = space.appexec([], "(): import _socket as m; return m")
    mod.path = udir.join('fd')
    mod.path.write('fo')
    mod.raises = py.test.raises  # make raises available from app-level tests
    mod.skip = py.test.skip
Exemple #22
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=['_socket', 'array', 'struct'])
    global socket
    import socket
    mod.w_socket = space.appexec([], "(): import _socket as m; return m")
    mod.path = udir.join('fd')
    mod.path.write('fo')
    mod.raises = py.test.raises # make raises available from app-level tests
    mod.skip = py.test.skip
Exemple #23
0
 def runtest(self):
     target = self.obj
     if self.config.option.runappdirect:
         return target()
     space = gettestobjspace()
     filename = self._getdynfilename(target)
     func = app2interp_temp(target, filename=filename)
     print "executing", func
     self.execute_appex(space, func, space)
Exemple #24
0
 def runtest(self):
     target = self.obj
     src = extract_docstring_if_empty_function(target)
     if self.config.option.runappdirect:
         return run_with_python(self.config.option.python, src, None)
     space = gettestobjspace()
     filename = self._getdynfilename(target)
     func = app2interp_temp(src, filename=filename)
     print "executing", func
     self.execute_appex(space, func, space)
Exemple #25
0
 def runtest(self):
     target = self.obj
     src = extract_docstring_if_empty_function(target)
     if self.config.option.runappdirect:
         return run_with_python(self.config.option.python, src, None)
     space = gettestobjspace()
     filename = self._getdynfilename(target)
     func = app2interp_temp(src, filename=filename)
     print "executing", func
     self.execute_appex(space, func, space)
Exemple #26
0
def pytest_runtest_setup(item):
    if isinstance(item, py.test.collect.Function):
        appclass = item.getparent(py.test.Class)
        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)
            else:
                appclass.obj.space = LazyObjSpaceGetter()
            appclass.obj.runappdirect = option.runappdirect
Exemple #27
0
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()
Exemple #28
0
def pytest_runtest_setup(item):
    if isinstance(item, py.test.collect.Function):
        appclass = item.getparent(py.test.Class)
        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)
            else:
                appclass.obj.space = LazyObjSpaceGetter()
            appclass.obj.runappdirect = option.runappdirect
Exemple #29
0
def pytest_runtest_setup(item):
    if isinstance(item, py.test.collect.Function):
        config = item.config
        if item.get_marker(name='pypy_only'):
            if config.applevel is not None and not config.applevel.is_pypy:
                pytest.skip('PyPy-specific test')
        appclass = item.getparent(py.test.Class)
        if appclass is not None:
            from pypy.tool.pytest.objspace import gettestobjspace
            # Make cls.space and cls.runappdirect available in tests.
            spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
            appclass.obj.space = gettestobjspace(**spaceconfig)
            appclass.obj.runappdirect = config.option.runappdirect
Exemple #30
0
def pytest_configure(config):
    if config.option.runappdirect:
        import sys
        import py
        from pypy import pypydir
        sys.path.append(str(py.path.local(pypydir) / 'tool' / 'cpyext'))
        return
    from pypy.tool.pytest.objspace import gettestobjspace
    # For some reason (probably a ll2ctypes cache issue on linux64)
    # it's necessary to run "import time" at least once before any
    # other cpyext test, otherwise the same statement will fail in
    # test_datetime.py.
    space = gettestobjspace(usemodules=['time'])
    space.getbuiltinmodule("time")
Exemple #31
0
def pytest_runtest_setup(item):
    if isinstance(item, py.test.collect.Function):
        config = item.config
        if (item.get_marker(name='pypy_only') and
                not '__pypy__' in sys.builtin_module_names):
            pytest.skip('PyPy-specific test')
        appclass = item.getparent(py.test.Class)
        if appclass is not None:
            from pypy.tool.pytest.objspace import gettestobjspace
            # Make cls.space and cls.runappdirect available in tests.
            spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
            if not (config.getoption('runappdirect') or config.getoption('direct_apptest')):
                spaceconfig.setdefault('objspace.std.reinterpretasserts', True)
            appclass.obj.space = gettestobjspace(**spaceconfig)
            appclass.obj.runappdirect = config.option.runappdirect
Exemple #32
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=USEMODULES)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
    unicode_dir.join('somefile').write('who cares?')
    unicode_dir.join('caf\xe9').write('who knows?')
    mod.unicode_dir = unicode_dir

    # in applevel tests, os.stat uses the CPython os.stat.
    # Be sure to return times with full precision
    # even when running on top of CPython 2.4.
    os.stat_float_times(True)
Exemple #33
0
def setup_module(mod):
    mod.space = gettestobjspace(usemodules=USEMODULES)
    mod.path = udir.join('posixtestfile.txt')
    mod.path.write("this is a test")
    mod.path2 = udir.join('test_posix2-')
    mod.path3 = udir.join('unlinktestfile.txt')
    mod.path3.write("delete me!")
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir = udir.ensure('posixtestdir', dir=True)
    pdir.join('file1').write("test1")
    os.chmod(str(pdir.join('file1')), 0o600)
    pdir.join('file2').write("test2")
    pdir.join('another_longer_file_name').write("test3")
    mod.pdir = pdir
    if sys.platform == 'darwin':
        # see issue https://bugs.python.org/issue31380
        unicode_dir = udir.ensure('fixc5x9fier.txt', dir=True)
        file_name = 'cafxe9'
    else:
        unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
        file_name = 'caf\xe9'
    unicode_dir.join('somefile').write('who cares?')
    unicode_dir.join(file_name).write('who knows?')
    mod.unicode_dir = unicode_dir
Exemple #34
0
def space(spaceconfig):
    from pypy.tool.pytest.objspace import gettestobjspace
    return gettestobjspace(**spaceconfig)
Exemple #35
0
pypydir = os.path.join(rootdir, "pypy")
f = open(os.path.join(str(udir), "pyconfig.h"), "w")
f.write("\n")
f.close()
sys.path.insert(0, os.getcwd())
from distutils import sysconfig

from pypy.tool.pytest.objspace import gettestobjspace
from pypy.module.cpyext.api import build_bridge
from pypy.module.imp.importing import get_so_extension

usemodules = ["cpyext", "thread"]
if sys.platform == "win32":
    usemodules.append("_winreg")  # necessary in distutils
space = gettestobjspace(usemodules=usemodules)

inc_paths = str(udir)


def get_python_inc(plat_specific=0, prefix=None):
    if plat_specific:
        return str(udir)
    return os.path.join(os.path.dirname(__file__), "include")


def patch_distutils():
    sysconfig.get_python_inc = get_python_inc
    sysconfig.get_config_vars()["SO"] = get_so_extension(space)

Exemple #36
0
def pytest_funcarg__space(request):
    from pypy.tool.pytest.objspace import gettestobjspace
    spaceconfig = getattr(request.cls, 'spaceconfig', {})
    return gettestobjspace(**spaceconfig)
Exemple #37
0
 def __get__(self, obj, cls=None):
     from pypy.tool.pytest.objspace import gettestobjspace
     space = gettestobjspace()
     if cls:
         cls.space = space
     return space
Exemple #38
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.w_tmpfilename = cls.space.wrap(str(udir.join('test__vmprof.1')))
     cls.w_tmpfilename2 = cls.space.wrap(str(udir.join('test__vmprof.2')))
Exemple #39
0
from rpython.tool.udir import udir
pypydir = os.path.join(rootdir, 'pypy')
f = open(os.path.join(str(udir), 'pyconfig.h'), "w")
f.write("\n")
f.close()
sys.path.insert(0, os.getcwd())
from distutils import sysconfig

from pypy.tool.pytest.objspace import gettestobjspace
from pypy.module.cpyext.api import build_bridge
from pypy.module.imp.importing import get_so_extension

usemodules = ['cpyext', 'thread']
if sys.platform == 'win32':
    usemodules.append('_winreg')  # necessary in distutils
space = gettestobjspace(usemodules=usemodules)

inc_paths = str(udir)


def get_python_inc(plat_specific=0, prefix=None):
    if plat_specific:
        return str(udir)
    return os.path.join(os.path.dirname(__file__), 'include')


def patch_distutils():
    sysconfig.get_python_inc = get_python_inc
    sysconfig.get_config_vars()['SO'] = get_so_extension(space)

Exemple #40
0
 def setup_class(cls):
     cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
     cls.w_tmpfilename = cls.space.wrap(str(udir.join('test__vmprof.1')))
     cls.w_tmpfilename2 = cls.space.wrap(str(udir.join('test__vmprof.2')))
Exemple #41
0
    def test_withstrbuf_fastpath_isinstance(self):
        from pypy.objspace.std.bytesobject import W_AbstractBytesObject

        space = gettestobjspace(withstrbuf=True)
        cls = space._get_interplevel_cls(space.w_bytes)
        assert cls is W_AbstractBytesObject
Exemple #42
0
    def test_withstrbuf_fastpath_isinstance(self):
        from pypy.objspace.std.bytesobject import W_AbstractBytesObject

        space = gettestobjspace(withstrbuf=True)
        cls = space._get_interplevel_cls(space.w_str)
        assert cls is W_AbstractBytesObject