Exemplo n.º 1
0
def CreateSessionTmpDir(config):
    '''
    :see: session_tmp_dir
    '''
    from py.path import local

    root_dir = config.rootdir.join('tmp')
    root_dir.ensure(dir=1)

    def SetTmpDir(tmp_dir):
        # Just in case there is no cache plugin
        if hasattr(config, 'cache'):
            config.cache.set("session_tmp_dir/last_session_tmp_dir", str(tmp_dir))
        config.session_tmp_dir = str(tmp_dir)

    # Use specified directory
    tmp_dir = config.getoption('session_tmp_dir', None)
    if tmp_dir is not None:
        if not os.path.isabs(tmp_dir):
            tmp_dir = root_dir.join(tmp_dir)
        return SetTmpDir(tmp_dir)

    # Use last session directory
    if config.getoption('last_session_tmp_dir', False):
        last_session_tmp_dir = config.cache.get("session_tmp_dir/last_session_tmp_dir", None)
        if last_session_tmp_dir and os.path.exists(last_session_tmp_dir):
            return SetTmpDir(last_session_tmp_dir)

    # Create new tmp directory
    tmp_dir = local.make_numbered_dir(prefix='session-tmp-dir-', rootdir=root_dir)
    return SetTmpDir(tmp_dir)
Exemplo n.º 2
0
    def test_make_numbered_dir_case(self, tmpdir):
        """make_numbered_dir does not make assumptions on the underlying
        filesystem based on the platform and will assume it _could_ be case
        insensitive.

        See issues:
        - https://github.com/pytest-dev/pytest/issues/708
        - https://github.com/pytest-dev/pytest/issues/3451
        """
        d1 = local.make_numbered_dir(
            prefix='CAse.', rootdir=tmpdir, keep=2, lock_timeout=0,
        )
        d2 = local.make_numbered_dir(
            prefix='caSE.', rootdir=tmpdir, keep=2, lock_timeout=0,
        )
        assert str(d1).lower() != str(d2).lower()
        assert str(d2).endswith('.1')
Exemplo n.º 3
0
 def test_locked_make_numbered_dir(self, tmpdir):
     for i in range(10):
         numdir = local.make_numbered_dir(prefix='base2.', rootdir=tmpdir,
                                          keep=2)
         assert numdir.check()
         assert numdir.basename == 'base2.%d' %i
         for j in range(i):
             assert numdir.new(ext=str(j)).check()
Exemplo n.º 4
0
 def test_locked_make_numbered_dir(self, tmpdir):
     for i in range(10):
         numdir = local.make_numbered_dir(prefix='base2.', rootdir=tmpdir,
                                          keep=2)
         assert numdir.check()
         assert numdir.basename == 'base2.%d' %i
         for j in range(i):
             assert numdir.new(ext=str(j)).check()
Exemplo n.º 5
0
 def test_make_numbered_dir_case_sensitive(self, tmpdir, monkeypatch):
     # https://github.com/pytest-dev/pytest/issues/708
     monkeypatch.setattr(py._path.local, 'normcase', lambda path: path)
     monkeypatch.setattr(tmpdir, 'listdir',
                         lambda: [tmpdir._fastjoin('case.0')])
     numdir = local.make_numbered_dir(prefix='CAse.', rootdir=tmpdir,
                                      keep=2, lock_timeout=0)
     assert numdir.basename.endswith('.0')
Exemplo n.º 6
0
def gittmpdir():
    """Return a "numbered" temporary Git repository

    :return: the path to the temporary Git repository, usually something like
             local('/tmp/pytest-of-toms/gitrepo-X') whereas X is an integer
     :rtype: :class:`py.path.local`
    """
    rootdir = get_pytest_roottmpdir()
    return local.make_numbered_dir(prefix='gitrepo-', rootdir=rootdir)
Exemplo n.º 7
0
 def test_locked_make_numbered_dir(self):
     if py.test.config.option.boxed: 
         py.test.skip("Fails when run as boxed tests")
     root = self.tmpdir
     for i in range(10):
         numdir = local.make_numbered_dir(prefix='base2.', rootdir=root,
                                          keep=2)
         assert numdir.check()
         assert numdir.basename == 'base2.%d' %i
         for j in range(i):
             assert numdir.new(ext=str(j)).check()
Exemplo n.º 8
0
 def test_make_numbered_dir(self, tmpdir):
     tmpdir.ensure('base.not_an_int', dir=1)
     for i in range(10):
         numdir = local.make_numbered_dir(prefix='base.', rootdir=tmpdir,
                                          keep=2, lock_timeout=0)
         assert numdir.check()
         assert numdir.basename == 'base.%d' %i
         if i>=1:
             assert numdir.new(ext=str(i-1)).check()
         if i>=2:
             assert numdir.new(ext=str(i-2)).check()
         if i>=3:
             assert not numdir.new(ext=str(i-3)).check()
Exemplo n.º 9
0
 def test_make_numbered_dir(self, tmpdir):
     tmpdir.ensure('base.not_an_int', dir=1)
     for i in range(10):
         numdir = local.make_numbered_dir(prefix='base.', rootdir=tmpdir,
                                          keep=2, lock_timeout=0)
         assert numdir.check()
         assert numdir.basename == 'base.%d' %i
         if i>=1:
             assert numdir.new(ext=str(i-1)).check()
         if i>=2:
             assert numdir.new(ext=str(i-2)).check()
         if i>=3:
             assert not numdir.new(ext=str(i-3)).check()
Exemplo n.º 10
0
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        try:
            p = py.magic.autopath().dirpath()
            basename = svn_info(py.path.svnwc(p).info().url)
        except:
            basename = ''
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir = dir,
                                   prefix = 'usession' + basename,
                                   keep = 3)
Exemplo n.º 11
0
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        try:
            p = py.magic.autopath().dirpath()
            basename = svn_info(py.path.svnwc(p).info().url)
        except:
            basename = ''
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir=dir,
                                   prefix='usession' + basename,
                                   keep=3)
Exemplo n.º 12
0
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        try:
            p = py.path.local(__file__).dirpath()
            basename = svn_info(py.path.svnwc(p).info().url)
            if isinstance(basename, unicode):
                basename = basename.encode(sys.getdefaultencoding())
        except:
            basename = ''
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir = dir,
                                   prefix = 'usession' + basename,
                                   keep = PYPY_KEEP)
Exemplo n.º 13
0
Arquivo: udir.py Projeto: Mu-L/pypy
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        info = get_repo_version_info()
        if info:
            hgtag, hgid = info
            basename = hgtag
            if basename == '?':
                basename = 'unknown'  # directories with ? are not fun
                # especially on windows
        else:
            basename = ''
    basename = basename.replace('/', '--')
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir=dir,
                                   prefix='usession' + basename,
                                   keep=PYPY_KEEP)
Exemplo n.º 14
0
Arquivo: udir.py Projeto: ieure/pypy
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        info = get_repo_version_info()
        if info:
            project, hgtag, hgid = info
            basename = hgtag
            if basename == '?':
                basename = 'unknown' # directories with ? are not fun
                # especially on windows
            if isinstance(basename, unicode):
                basename = basename.encode(sys.getdefaultencoding())
        else:
            basename = ''
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir = dir,
                                   prefix = 'usession' + basename,
                                   keep = PYPY_KEEP)
Exemplo n.º 15
0
def make_udir(dir=None, basename=None):
    if dir is not None:
        dir = local(dir)
    if basename is None:
        info = get_repo_version_info()
        if info:
            project, hgtag, hgid = info
            basename = hgtag
            if basename == '?':
                basename = 'unknown'  # directories with ? are not fun
                # especially on windows
            if isinstance(basename, unicode):
                basename = basename.encode(sys.getdefaultencoding())
        else:
            basename = ''
    if not basename.startswith('-'):
        basename = '-' + basename
    if not basename.endswith('-'):
        basename = basename + '-'
    return local.make_numbered_dir(rootdir=dir,
                                   prefix='usession' + basename,
                                   keep=PYPY_KEEP)
Exemplo n.º 16
0
#
# Common entry point to access a temporary directory (for testing, etc.)
# This uses the py lib's logic to create numbered directories.  The last
# three temporary directories are kept.
#

import autopath
import os

from py.path import local 

udir = local.make_numbered_dir(prefix='usession-', keep=3)
Exemplo n.º 17
0
# test_complex assumes you have 'avmshell' on your PATH.

import subprocess

from py.path import local
from fusion.avm2.loadable import Local
from fusion.avm2.abc_ import AbcFile

tmpdir = local.make_numbered_dir("fusion-session-")


def interpret(gen, tmpfile):
    # Epilogue
    gen.call_function("print", [Local("result")])
    gen.finish()

    tmpfile.write(gen.abc.serialize(), mode='wb')

    procargs = ['avmshell', '-Dinterp', str(tmpfile)]
    testproc = subprocess.Popen(procargs, stdout=subprocess.PIPE)
    result = testproc.stdout.read()
    result = result.rstrip("\n")
    return result


def pytest_funcarg__gen(request):
    abcfile = AbcFile()
    gen = abcfile.create_generator()
    script = gen.begin_script()
    init = script.make_init()
    gen.enter_rib(init)
Exemplo n.º 18
0
#
# Common entry point to access a temporary directory (for testing, etc.)
# This uses the py lib's logic to create numbered directories.  The last
# three temporary directories are kept.
#

import autopath
import os

from py.path import local

udir = local.make_numbered_dir(prefix='usession-', keep=3)
Exemplo n.º 19
0
# test_complex assumes you have 'avmshell' on your PATH.

import subprocess

from py.path import local
from fusion.avm2.loadable import Local
from fusion.avm2.abc_ import AbcFile

tmpdir = local.make_numbered_dir("fusion-session-")

def interpret(gen, tmpfile):
    # Epilogue
    gen.call_function("print", [Local("result")])
    gen.finish()

    tmpfile.write(gen.abc.serialize(), mode='wb')

    procargs = ['avmshell', '-Dinterp', str(tmpfile)]
    testproc = subprocess.Popen(procargs, stdout=subprocess.PIPE)
    result = testproc.stdout.read()
    result = result.rstrip("\n")
    return result

def pytest_funcarg__gen(request):
    abcfile = AbcFile()
    gen = abcfile.create_generator()
    script = gen.begin_script()
    init = script.make_init()
    gen.enter_rib(init)
    return gen
Exemplo n.º 20
0
#
# Common entry point to access a temporary directory (for testing, etc.)
# This uses the py lib's logic to create numbered directories.  The last
# three temporary directories are kept.
#

import autopath
import os
import py

from py.path import local 

def svn_info(url):
    basename = url[:-len('pypy/tool')]
    if basename.endswith('dist/'):
        return 'dist'
    else:
        return basename.split('/')[-2]

basename = os.environ.get('PYPY_USESSION_BASENAME')
if not basename:
    try:
        basename = '-' + svn_info(py.path.svnwc(py.magic.autopath().dirpath()).info().url) + '-'
    except:
        basename = '-'

udir = local.make_numbered_dir(prefix='usession' + basename, keep=3)