[svn r62993] * moving ensuretemp to config object
* adding --basetemp option * added/rewrote some tests --HG-- branch : trunk
This commit is contained in:
parent
6f1eca5e4a
commit
7ed26c2929
|
@ -4,16 +4,11 @@ from conftesthandle import Conftest
|
|||
from py.__.test import parseopt
|
||||
from py.__.misc.warn import APIWARN
|
||||
|
||||
# XXX move to Config class
|
||||
basetemp = None
|
||||
def ensuretemp(string, dir=1):
|
||||
""" return temporary directory path with
|
||||
the given string as the trailing part.
|
||||
"""
|
||||
global basetemp
|
||||
if basetemp is None:
|
||||
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
|
||||
return basetemp.ensure(string, dir=dir)
|
||||
return py.test.config.ensuretemp(string, dir=dir)
|
||||
|
||||
class CmdOptions(object):
|
||||
""" pure container instance for holding cmdline options
|
||||
|
@ -29,6 +24,7 @@ class Config(object):
|
|||
""" central bus for dealing with configuration/initialization data. """
|
||||
Option = py.compat.optparse.Option # deprecated
|
||||
Error = Error
|
||||
basetemp = None
|
||||
_sessionclass = None
|
||||
|
||||
def __init__(self, pytestplugins=None, topdir=None):
|
||||
|
@ -123,6 +119,18 @@ class Config(object):
|
|||
self._preparse(args)
|
||||
self.args = args
|
||||
|
||||
def ensuretemp(self, string, dir=True):
|
||||
if self.basetemp is None:
|
||||
basetemp = self.option.basetemp
|
||||
if basetemp:
|
||||
basetemp = py.path.local(basetemp)
|
||||
if not basetemp.check(dir=1):
|
||||
basetemp.mkdir()
|
||||
else:
|
||||
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
|
||||
self.basetemp = basetemp
|
||||
return self.basetemp.ensure(string, dir=dir)
|
||||
|
||||
def getcolitems(self):
|
||||
return [self.getfsnode(arg) for arg in self.args]
|
||||
|
||||
|
|
|
@ -63,38 +63,21 @@ class TestAsyncFunctional:
|
|||
assert ev.host.address == "popen"
|
||||
ev, = eq.geteventargs("testrunfinish")
|
||||
|
||||
def test_distribution_rsync_roots_example(self, testdir):
|
||||
py.test.skip("testing for root rsync needs rework")
|
||||
destdir = py.test.ensuretemp("example_dist_destdir")
|
||||
subdir = "sub_example_dist"
|
||||
sourcedir = self.tmpdir.mkdir("source")
|
||||
sourcedir.ensure(subdir, "conftest.py").write(py.code.Source("""
|
||||
hosts = ["popen:%s"]
|
||||
rsyncdirs = ["%s", "../py"]
|
||||
""" % (destdir, tmpdir.join(subdir), )))
|
||||
tmpdir.ensure(subdir, "__init__.py")
|
||||
tmpdir.ensure(subdir, "test_one.py").write(py.code.Source("""
|
||||
def test_1():
|
||||
pass
|
||||
def test_2():
|
||||
assert 0
|
||||
def test_3():
|
||||
raise ValueError(23)
|
||||
def test_4(someargs):
|
||||
pass
|
||||
def test_5():
|
||||
assert __file__ != '%s'
|
||||
#def test_6():
|
||||
# import py
|
||||
# assert py.__file__ != '%s'
|
||||
""" % (tmpdir.join(subdir), py.__file__)))
|
||||
destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath())
|
||||
|
||||
sorter = testdir.inline_run(tmpdir.join(subdir))
|
||||
testevents = sorter.getnamed('itemtestreport')
|
||||
assert len([x for x in testevents if x.passed]) == 2
|
||||
assert len([x for x in testevents if x.failed]) == 3
|
||||
assert len([x for x in testevents if x.skipped]) == 0
|
||||
@py.test.mark.xfail("XXX")
|
||||
def test_distribution_rsyncdirs_example(self, testdir):
|
||||
source = testdir.mkdir("source")
|
||||
dest = testdir.mkdir("dest")
|
||||
subdir = source.mkdir("example_pkg")
|
||||
subdir.ensure("__init__.py")
|
||||
p = subdir.join("test_one.py")
|
||||
p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
|
||||
result = testdir.runpytest("-d", "--rsyncdirs=%(subdir)s" % locals(),
|
||||
"--hosts=popen:%(dest)s" % locals())
|
||||
assert result.ret == 0
|
||||
result.stdout.fnmatch_lines([
|
||||
"*1 passed*"
|
||||
])
|
||||
assert dest.join(subdir.basename).check(dir=1)
|
||||
|
||||
def test_nice_level(self, testdir):
|
||||
""" Tests if nice level behaviour is ok """
|
||||
|
|
|
@ -61,7 +61,9 @@ class DefaultPlugin:
|
|||
group._addoption('-s', '--nocapture',
|
||||
action="store_true", dest="nocapture", default=False,
|
||||
help="disable catching of sys.stdout/stderr output."),
|
||||
group._addoption('--boxed',
|
||||
group.addoption('--basetemp', dest="basetemp", default=None,
|
||||
help="directory to use for this test run.")
|
||||
group.addoption('--boxed',
|
||||
action="store_true", dest="boxed", default=False,
|
||||
help="box each test run in a separate process"),
|
||||
group._addoption('-f', '--looponfailing',
|
||||
|
|
|
@ -234,6 +234,9 @@ class TmpTestdir:
|
|||
return self.run(script, *args)
|
||||
|
||||
def runpytest(self, *args):
|
||||
p = py.path.local.make_numbered_dir(prefix="runpytest-",
|
||||
keep=None, rootdir=self.tmpdir)
|
||||
args = ('--basetemp=%s' % p, ) + args
|
||||
return self.runpybin("py.test", *args)
|
||||
|
||||
class Event:
|
||||
|
|
|
@ -16,6 +16,17 @@ class TestPyTest:
|
|||
assert result.stderr.fnmatch_lines([
|
||||
'config ERROR: hello'
|
||||
])
|
||||
|
||||
def test_basetemp(self, testdir):
|
||||
mytemp = testdir.tmpdir.mkdir("mytemp")
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
def test_1():
|
||||
py.test.ensuretemp('xyz')
|
||||
""")
|
||||
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
||||
assert result.ret == 0
|
||||
assert mytemp.join('xyz').check(dir=1)
|
||||
|
||||
def test_assertion_magic(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
|
|
|
@ -85,8 +85,9 @@ class TestConfigCmdlineParsing:
|
|||
yield check_conflict_option, opts
|
||||
|
||||
class TestConfigAPI:
|
||||
|
||||
@py.test.mark.issue("ensuretemp should call config.maketemp(basename)")
|
||||
def test_tmpdir(self):
|
||||
def test_ensuretemp(self):
|
||||
d1 = py.test.ensuretemp('hello')
|
||||
d2 = py.test.ensuretemp('hello')
|
||||
assert d1 == d2
|
||||
|
|
|
@ -214,6 +214,7 @@ class TestNewSession(SessionTests):
|
|||
assert len(colskipped) == 1
|
||||
|
||||
def test_minus_x_import_error(self, testdir):
|
||||
testdir.makepyfile(__init__="")
|
||||
testdir.makepyfile(test_one="xxxx", test_two="yyyy")
|
||||
sorter = testdir.inline_run("-x", testdir.tmpdir)
|
||||
finished = sorter.getnamed("collectionreport")
|
||||
|
|
Loading…
Reference in New Issue