当前位置: 首页>>代码示例>>Python>>正文


Python udir.ensure函数代码示例

本文整理汇总了Python中pypy.tool.udir.udir.ensure函数的典型用法代码示例。如果您正苦于以下问题:Python ensure函数的具体用法?Python ensure怎么用?Python ensure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ensure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_main_two

 def test_main_two(self):
     udir.ensure("js_two.py").write(py.code.Source("""
     def f():
         pass
     """))
     self._test_not_raises(udir.join("js_two.py"), ["f"])
     self._test_raises(udir.join("js_two.py"), [])
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_main.py

示例2: test_main_one

 def test_main_one(self):
     udir.ensure("js_one.py").write(py.code.Source("""
     def f():
         pass
     f._client = True
     """))
     self._test_not_raises(udir.join("js_one.py"))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_main.py

示例3: setup_module

def setup_module(mod):
    if os.name != 'nt':
        mod.space = gettestobjspace(usemodules=['posix', 'fcntl'])
    else:
        # On windows, os.popen uses the subprocess module
        mod.space = gettestobjspace(usemodules=['posix', '_rawffi', 'thread'])
    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?')
    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)

    # Initialize sys.filesystemencoding
    space.call_method(space.getbuiltinmodule('sys'), 'getfilesystemencoding')
开发者ID:ieure,项目名称:pypy,代码行数:26,代码来源:test_posix2.py

示例4: setup_class

 def setup_class(cls):
     testfn.write(testcode, 'w')
     udir.join(testmodule + '.py').write(testmodulecode, 'w')
     udir.ensure(testpackage, '__init__.py')
     udir.join(testpackage, testmodule + '.py').write(testmodulecode, 'w')
     space = cls.space
     cls.w_oldsyspath = space.appexec([space.wrap(str(udir))], """(udir):
         import sys
         old = sys.path[:]
         sys.path.insert(0, udir)
         return old
     """)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:12,代码来源:test_main.py

示例5: test_safe_filename

def test_safe_filename():
    source = py.code.Source("""
    class ExpectTestOne:
        def test_one(self):
            pass
    """)
    dest = udir.join("test_expect_safefilename.py")
    dest.write(source)
    from pypy import conftest
    col = conftest.Module(dest)
    methcol = col.join('ExpectTestOne').join('()').join('test_one')
    name = 'test_expect_safefilename_ExpectTestOne_paren_test_one.py'
    assert methcol.safe_filename() == name
    udir.ensure(name)
    assert methcol.safe_filename() == name[:-3] + '_1.py'
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:15,代码来源:test_pytestsupport.py

示例6: make_class

    def make_class(cls):
        # XXX: this is (mostly) wrong: .compile() compiles the code object
        # using the host python compiler, but then in the tests we load it
        # with py.py. It works (mostly by chance) because the two functions
        # are very simple and the bytecodes are compatible enough.
        co = py.code.Source(
            """
        def get_name():
            return __name__
        def get_file():
            return __file__
        """
        ).compile()

        if cls.compression == ZIP_DEFLATED:
            space = gettestobjspace(usemodules=["zipimport", "zlib", "rctime", "struct"])
        else:
            space = gettestobjspace(usemodules=["zipimport", "rctime", "struct"])

        cls.space = space
        tmpdir = udir.ensure("zipimport_%s" % cls.__name__, dir=1)
        now = time.time()
        cls.w_now = space.wrap(now)
        test_pyc = cls.make_pyc(space, co, now)
        cls.w_test_pyc = space.wrap(test_pyc)
        cls.w_compression = space.wrap(cls.compression)
        cls.w_pathsep = space.wrap(cls.pathsep)
        # ziptestmodule = tmpdir.ensure('ziptestmodule.zip').write(
        ziptestmodule = tmpdir.join("somezip.zip")
        cls.w_tmpzip = space.wrap(str(ziptestmodule))
        cls.w_co = space.wrap(co)
        cls.tmpdir = tmpdir
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:32,代码来源:test_zipimport.py

示例7: test_execfile_different_lineendings

    def test_execfile_different_lineendings(self): 
        space = self.space
        from pypy.tool.udir import udir
        d = udir.ensure('lineending', dir=1)
        dos = d.join('dos.py') 
        f = dos.open('wb') 
        f.write("x=3\r\n\r\ny=4\r\n")
        f.close() 
        space.appexec([space.wrap(str(dos))], """
            (filename): 
                d = {}
                execfile(filename, d)
                assert d['x'] == 3
                assert d['y'] == 4
        """)

        unix = d.join('unix.py')
        f = unix.open('wb') 
        f.write("x=5\n\ny=6\n")
        f.close() 

        space.appexec([space.wrap(str(unix))], """
            (filename): 
                d = {}
                execfile(filename, d)
                assert d['x'] == 5
                assert d['y'] == 6
        """)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:28,代码来源:test_builtin.py

示例8: test_gcc_options

    def test_gcc_options(self):
        # check that the env var CC is correctly interpreted, even if
        # it contains the compiler name followed by some options.
        if sys.platform == 'win32':
            py.test.skip("only for gcc")

        from pypy.rpython.lltypesystem import lltype, rffi
        dir = udir.ensure('test_gcc_options', dir=1)
        dir.join('someextraheader.h').write('#define someextrafunc() 42\n')
        eci = ExternalCompilationInfo(includes=['someextraheader.h'])
        someextrafunc = rffi.llexternal('someextrafunc', [], lltype.Signed,
                                        compilation_info=eci)

        def entry_point(argv):
            return someextrafunc()

        old_cc = os.environ.get('CC')
        try:
            os.environ['CC'] = 'gcc -I%s' % dir
            t, cbuilder = self.compile(entry_point)
        finally:
            if old_cc is None:
                del os.environ['CC']
            else:
                os.environ['CC'] = old_cc
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_standalone.py

示例9: prepare_c_example

    def prepare_c_example(cls):
        from pypy.tool.udir import udir
        from pypy.translator.tool.cbuild import ExternalCompilationInfo
        from pypy.translator.platform import platform

        c_file = udir.ensure("test__ffi", dir=1).join("foolib.c")
        # automatically collect the C source from the docstrings of the tests
        snippets = ["""
        #ifdef _WIN32
        #define DLLEXPORT __declspec(dllexport)
        #else
        #define DLLEXPORT
        #endif
        """]
        for name in dir(cls):
            if name.startswith('test_'):
                meth = getattr(cls, name)
                # the heuristic to determine it it's really C code could be
                # improved: so far we just check that there is a '{' :-)
                if meth.__doc__ is not None and '{' in meth.__doc__:
                    snippets.append(meth.__doc__)
        #
        c_file.write(py.code.Source('\n'.join(snippets)))
        eci = ExternalCompilationInfo(export_symbols=[])
        return str(platform.compile([c_file], eci, 'x', standalone=False))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_funcptr.py

示例10: setup_class

    def setup_class(cls):
        from pypy.tool.udir import udir
        from pypy.translator.tool.cbuild import ExternalCompilationInfo
        from pypy.translator.platform import platform

        BaseFfiTest.setup_class()
        # prepare C code as an example, so we can load it and call
        # it via rlib.libffi
        c_file = udir.ensure("test_libffi", dir=1).join("foolib.c")
        # automatically collect the C source from the docstrings of the tests
        snippets = []
        exports = []
        for name in dir(cls):
            if name.startswith('test_'):
                meth = getattr(cls, name)
                # the heuristic to determine it it's really C code could be
                # improved: so far we just check that there is a '{' :-)
                if meth.__doc__ is not None and '{' in meth.__doc__:
                    snippets.append(meth.__doc__)
                    import re
                    for match in re.finditer(" ([a-z_]+)\(", meth.__doc__):
                        exports.append(match.group(1))
        #
        c_file.write(py.code.Source('\n'.join(snippets)))
        eci = ExternalCompilationInfo(export_symbols=exports)
        cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
                                               standalone=False))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:27,代码来源:test_libffi.py

示例11: test_cdll_life_time

    def test_cdll_life_time(self):
        from pypy.translator.tool.cbuild import ExternalCompilationInfo
        from pypy.translator.platform import platform
        from pypy.tool.udir import udir

        c_file = udir.ensure("test_libffi", dir=1).join("xlib.c")
        c_file.write(
            py.code.Source(
                """
        long fun(long i) {
            return i + 42;
        }
        """
            )
        )
        eci = ExternalCompilationInfo(export_symbols=["fun"])
        lib_name = str(platform.compile([c_file], eci, "x", standalone=False))

        lib = CDLL(lib_name)
        slong = cast_type_to_ffitype(rffi.LONG)
        fun = lib.getrawpointer("fun", [slong], slong)
        del lib  # already delete here

        buffer = lltype.malloc(rffi.LONGP.TO, 2, flavor="raw")
        buffer[0] = 200
        buffer[1] = -1
        fun.call([rffi.cast(rffi.VOIDP, buffer)], rffi.cast(rffi.VOIDP, rffi.ptradd(buffer, 1)))
        assert buffer[1] == 242

        lltype.free(buffer, flavor="raw")
        del fun

        assert not ALLOCATED
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:33,代码来源:test_clibffi.py

示例12: setup_module

def setup_module(mod): 
    mod.space = gettestobjspace(usemodules=['posix'])
    mod.path = udir.join('posixtestfile.txt') 
    mod.path.write("this is a test")
    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
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:test_posix2.py

示例13: test_struct_by_val

    def test_struct_by_val(self):
        import platform
        if platform.machine() == 'x86_64':
            py.test.skip("Segfaults on x86_64 because small structures "
                         "may be passed in registers and "
                         "c_elements must not be null")
        from pypy.translator.tool.cbuild import ExternalCompilationInfo
        from pypy.translator.platform import platform
        from pypy.tool.udir import udir

        c_file = udir.ensure("test_libffi", dir=1).join("xlib.c")
        c_file.write(py.code.Source('''
        #include <stdlib.h>
        #include <stdio.h>

        struct x_y {
            long x;
            long y;
        };

        long sum_x_y(struct x_y s) {
            return s.x + s.y;
        }

        long sum_x_y_p(struct x_y *p) {
            return p->x + p->y;
        }
        
        '''))
        eci = ExternalCompilationInfo(export_symbols=['sum_x_y'])
        lib_name = str(platform.compile([c_file], eci, 'x', standalone=False))

        lib = CDLL(lib_name)

        slong = cast_type_to_ffitype(rffi.LONG)
        size = slong.c_size*2
        alignment = slong.c_alignment
        tp = make_struct_ffitype(size, alignment)

        sum_x_y = lib.getrawpointer('sum_x_y', [tp], slong)

        buffer = lltype.malloc(rffi.LONGP.TO, 3, flavor='raw')
        buffer[0] = 200
        buffer[1] = 220
        buffer[2] = 666
        sum_x_y.call([rffi.cast(rffi.VOIDP, buffer)],
                     rffi.cast(rffi.VOIDP, rffi.ptradd(buffer, 2)))
        assert buffer[2] == 420

        lltype.free(buffer, flavor='raw')
        del sum_x_y
        lltype.free(tp, flavor='raw')
        del lib

        assert not ALLOCATED
开发者ID:alkorzt,项目名称:pypy,代码行数:55,代码来源:test_libffi.py

示例14: test_load_html

def test_load_html():
    tmpdir = udir.ensure("docloader", dir=1)
    help = tmpdir.ensure("one.html").write("<a href='dupa'>%s</a>")
    code = tmpdir.ensure("test_snippets2.py").write(str(py.code.Source('''
    class AppTest_one(object):
        def test_snippet_1(self):
            x = 1
    ''')) + '\n')
    ld = DocLoader(docdir=tmpdir, consoles=['one'], testfile=tmpdir.join('test_snippets2.py'))
    assert ld.get_html('one') == "<a href='dupa'>x = 1</a>"
    assert ld.get_snippet('one', 0) == 'x = 1'
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:11,代码来源:test_docloader.py

示例15: test_extra_include_dirs

def test_extra_include_dirs():
    udir.ensure("incl", dir=True)
    udir.join("incl", "incl.h").write("#define C 3")
    c_file = udir.join("test_extra_include_dirs.c")
    c_source = """
    #include <incl.h>
    int fun ()
    {
        return (C);
    }
    """
    c_file.write(c_source)
    z = llexternal('fun', [], Signed, sources=[str(c_file)], include_dirs=
                   [str(udir.join("incl"))])

    def f():
        return z()

    res = compile(f, [])
    assert res() == 3
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:20,代码来源:test_rffi.py


注:本文中的pypy.tool.udir.udir.ensure函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。