[svn r37278] move files from branch to trunk (and thus complete
the merge of the config branch into the trunk) --HG-- branch : trunk
This commit is contained in:
@@ -12,18 +12,6 @@ def test_failing_import_execfile():
|
||||
py.test.raises(ImportError, col.run)
|
||||
py.test.raises(ImportError, col.run)
|
||||
|
||||
def XXXtest_finds_root():
|
||||
fn = datadir / 'filetest.py'
|
||||
col = py.test.collect.Module(fn)
|
||||
root, namelist = col.fromroot()
|
||||
assert isinstance(root, py.test.collect.Directory)
|
||||
cur = root
|
||||
for x in namelist:
|
||||
cur = cur.join(x)
|
||||
assert cur.name == col.name
|
||||
assert cur.parent == col.parent
|
||||
assert cur.fspath == cur.fspath
|
||||
|
||||
def test_collect_listnames_and_back():
|
||||
col1 = py.test.collect.Directory(datadir.dirpath())
|
||||
col2 = col1.join(datadir.basename)
|
||||
@@ -203,10 +191,10 @@ def test_custom_python_collection_from_conftest():
|
||||
assert 23 == 23
|
||||
""")
|
||||
|
||||
from py.__.test.collect import getfscollector
|
||||
for x in (o, checkfile, checkfile.dirpath()):
|
||||
config = py.test.config._reparse([x])
|
||||
#print "checking that %s returns custom items" % (x,)
|
||||
col = getfscollector(x)
|
||||
col = config._getcollector(x)
|
||||
assert len(list(col.tryiter(py.test.Item))) == 2
|
||||
#assert items[1].__class__.__name__ == 'MyFunction'
|
||||
|
||||
@@ -215,7 +203,7 @@ def test_custom_python_collection_from_conftest():
|
||||
try:
|
||||
config = py.test.config._reparse([])
|
||||
out = py.std.cStringIO.StringIO()
|
||||
session = config.getsessionclass()(config, out)
|
||||
session = config._getsessionclass()(config, out)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert len(l) == 2
|
||||
@@ -225,7 +213,7 @@ def test_custom_python_collection_from_conftest():
|
||||
# test that running the file directly works
|
||||
config = py.test.config._reparse([str(checkfile)])
|
||||
out = py.std.cStringIO.StringIO()
|
||||
session = config.getsessionclass()(config, out)
|
||||
session = config._getsessionclass()(config, out)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert len(l) == 2
|
||||
@@ -250,10 +238,10 @@ def test_custom_NONpython_collection_from_conftest():
|
||||
""")
|
||||
checkfile = o.ensure('somedir', 'moredir', 'check_something.txt')
|
||||
|
||||
from py.__.test.collect import getfscollector
|
||||
for x in (o, checkfile, checkfile.dirpath()):
|
||||
print "checking that %s returns custom items" % (x,)
|
||||
col = getfscollector(x)
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
assert len(list(col.tryiter(py.test.Item))) == 1
|
||||
#assert items[1].__class__.__name__ == 'MyFunction'
|
||||
|
||||
@@ -262,7 +250,7 @@ def test_custom_NONpython_collection_from_conftest():
|
||||
try:
|
||||
config = py.test.config._reparse([])
|
||||
out = py.std.cStringIO.StringIO()
|
||||
session = config.getsessionclass()(config, out)
|
||||
session = config._getsessionclass()(config, out)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert len(l) == 1
|
||||
@@ -272,12 +260,14 @@ def test_custom_NONpython_collection_from_conftest():
|
||||
# test that running the file directly works
|
||||
config = py.test.config._reparse([str(checkfile)])
|
||||
out = py.std.cStringIO.StringIO()
|
||||
session = config.getsessionclass()(config, out)
|
||||
session = config._getsessionclass()(config, out)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert len(l) == 1
|
||||
|
||||
def test_order_of_execution_generator_same_codeline():
|
||||
if py.test.config.is_boxed():
|
||||
py.test.skip("Does not work with boxing")
|
||||
test_list = []
|
||||
expected_list = range(6)
|
||||
|
||||
@@ -295,6 +285,8 @@ def test_order_of_execution_generator_same_codeline():
|
||||
|
||||
|
||||
def test_order_of_execution_generator_different_codeline():
|
||||
if py.test.config.is_boxed():
|
||||
py.test.skip("Does not work with boxing")
|
||||
test_list = []
|
||||
expected_list = range(3)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from __future__ import generators
|
||||
import py
|
||||
|
||||
from py.__.test.config import gettopdir
|
||||
|
||||
def test_tmpdir():
|
||||
d1 = py.test.ensuretemp('hello')
|
||||
d2 = py.test.ensuretemp('hello')
|
||||
@@ -72,3 +74,266 @@ def test_siblingconftest_fails_maybe():
|
||||
print py.process.cmdexec("py.test")
|
||||
finally:
|
||||
old.chdir()
|
||||
|
||||
def test_config_overwrite():
|
||||
o = py.test.ensuretemp('testconfigget')
|
||||
o.ensure("conftest.py").write("x=1")
|
||||
config = py.test.config._reparse([str(o)])
|
||||
assert config.getvalue('x') == 1
|
||||
config._overwrite('x', 2)
|
||||
assert config.getvalue('x') == 2
|
||||
config = py.test.config._reparse([str(o)])
|
||||
assert config.getvalue('x') == 1
|
||||
|
||||
def test_gettopdir():
|
||||
tmp = py.test.ensuretemp("topdir")
|
||||
assert gettopdir([tmp]) == tmp
|
||||
topdir =gettopdir([tmp.join("hello"), tmp.join("world")])
|
||||
assert topdir == tmp
|
||||
|
||||
def test_gettopdir_pypkg():
|
||||
tmp = py.test.ensuretemp("topdir2")
|
||||
a = tmp.ensure('a', dir=1)
|
||||
b = tmp.ensure('a', 'b', '__init__.py')
|
||||
c = tmp.ensure('a', 'b', 'c.py')
|
||||
Z = tmp.ensure('Z', dir=1)
|
||||
assert gettopdir([c]) == a
|
||||
assert gettopdir([c, Z]) == tmp
|
||||
|
||||
|
||||
def test_config_init_direct():
|
||||
tmp = py.test.ensuretemp("initdirect")
|
||||
tmp.ensure("__init__.py")
|
||||
tmp.ensure("conftest.py").write("x=1 ; y=2")
|
||||
hello = tmp.ensure("test_hello.py")
|
||||
config = py.test.config._reparse([hello])
|
||||
repr = config.make_repr(conftestnames=['x', 'y'])
|
||||
config2 = py.test.config._reparse([tmp.dirpath()])
|
||||
config2._initialized = False # we have to do that from tests
|
||||
config2.initdirect(topdir=tmp.dirpath(), repr=repr)
|
||||
for col1, col2 in zip(config.getcolitems(), config2.getcolitems()):
|
||||
assert col1.fspath == col2.fspath
|
||||
py.test.raises(AssertionError, "config2.initdirect(None, None)")
|
||||
from py.__.test.config import Config
|
||||
config3 = Config()
|
||||
config3.initdirect(topdir=tmp.dirpath(), repr=repr,
|
||||
coltrails=[(tmp.basename, (hello.basename,))])
|
||||
assert config3.getvalue('x') == 1
|
||||
assert config3.getvalue('y') == 2
|
||||
cols = config.getcolitems()
|
||||
assert len(cols) == 1
|
||||
col = cols[0]
|
||||
assert col.name == 'test_hello.py'
|
||||
assert col.parent.name == tmp.basename
|
||||
assert col.parent.parent is None
|
||||
|
||||
def test_config_make_and_merge_repr():
|
||||
tmp = py.test.ensuretemp("reprconfig1")
|
||||
tmp.ensure("__init__.py")
|
||||
tmp.ensure("conftest.py").write("x=1")
|
||||
config = py.test.config._reparse([tmp])
|
||||
repr = config.make_repr(conftestnames=['x'])
|
||||
config.option.verbose = 42
|
||||
repr2 = config.make_repr(conftestnames=[], optnames=['verbose'])
|
||||
config = py.test.config._reparse([tmp.dirpath()])
|
||||
py.test.raises(KeyError, "config.getvalue('x')")
|
||||
config.merge_repr(repr)
|
||||
assert config.getvalue('x') == 1
|
||||
config.merge_repr(repr2)
|
||||
assert config.option.verbose == 42
|
||||
|
||||
def test_config_marshability():
|
||||
tmp = py.test.ensuretemp("configmarshal")
|
||||
tmp.ensure("__init__.py")
|
||||
tmp.ensure("conftest.py").write("a = object()")
|
||||
config = py.test.config._reparse([tmp])
|
||||
py.test.raises(ValueError, "config.make_repr(conftestnames=['a'])")
|
||||
|
||||
config.option.hello = lambda x: None
|
||||
py.test.raises(ValueError, "config.make_repr(conftestnames=[])")
|
||||
config.make_repr(conftestnames=[], optnames=[])
|
||||
|
||||
def test_config_rconfig():
|
||||
tmp = py.test.ensuretemp("rconfigopt")
|
||||
tmp.ensure("__init__.py")
|
||||
tmp.ensure("conftest.py").write(py.code.Source("""
|
||||
import py
|
||||
Option = py.test.config.Option
|
||||
option = py.test.config.addoptions("testing group",
|
||||
Option('-g', '--glong', action="store", default=42,
|
||||
type="int", dest="gdest", help="g value."))
|
||||
"""))
|
||||
config = py.test.config._reparse([tmp, "-g", "11"])
|
||||
assert config.option.gdest == 11
|
||||
repr = config.make_repr(conftestnames=[])
|
||||
config = py.test.config._reparse([tmp.dirpath()])
|
||||
py.test.raises(AttributeError, "config.option.gdest")
|
||||
config.merge_repr(repr)
|
||||
assert config.option.gdest == 11
|
||||
|
||||
class TestSessionAndOptions:
|
||||
def setup_class(cls):
|
||||
cls.tmproot = py.test.ensuretemp(cls.__name__)
|
||||
|
||||
def setup_method(self, method):
|
||||
self.tmpdir = self.tmproot.ensure(method.__name__, dir=1)
|
||||
|
||||
def test_sessionname_default(self):
|
||||
config = py.test.config._reparse([self.tmpdir])
|
||||
assert config._getsessionname() == 'TerminalSession'
|
||||
|
||||
def test_sessionname_dist(self):
|
||||
config = py.test.config._reparse([self.tmpdir, '--dist'])
|
||||
assert config._getsessionname() == 'RSession'
|
||||
|
||||
def test_implied_lsession(self):
|
||||
optnames = 'startserver runbrowser apigen=x rest box'.split()
|
||||
for x in optnames:
|
||||
config = py.test.config._reparse([self.tmpdir, '--%s' % x])
|
||||
assert config._getsessionname() == 'LSession'
|
||||
|
||||
for x in 'startserver runbrowser rest'.split():
|
||||
config = py.test.config._reparse([self.tmpdir, '--dist', '--%s' % x])
|
||||
assert config._getsessionname() == 'RSession'
|
||||
|
||||
def test_implied_remote_terminal_session(self):
|
||||
config = py.test.config._reparse([self.tmpdir, '--looponfailing'])
|
||||
assert config._getsessionname() == 'RemoteTerminalSession'
|
||||
config = py.test.config._reparse([self.tmpdir, '--exec=x'])
|
||||
assert config._getsessionname() == 'RemoteTerminalSession'
|
||||
config = py.test.config._reparse([self.tmpdir, '--dist', '--exec=x'])
|
||||
assert config._getsessionname() == 'RSession'
|
||||
|
||||
def test_tkintersession(self):
|
||||
config = py.test.config._reparse([self.tmpdir, '--tkinter'])
|
||||
assert config._getsessionname() == 'TkinterSession'
|
||||
config = py.test.config._reparse([self.tmpdir, '--dist'])
|
||||
|
||||
def test_sessionname_lookup_custom(self):
|
||||
self.tmpdir.join("conftest.py").write(py.code.Source("""
|
||||
class MySession:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
"""))
|
||||
config = py.test.config._reparse(["--session=MySession", self.tmpdir])
|
||||
session = config.initsession()
|
||||
assert session.__class__.__name__ == 'MySession'
|
||||
|
||||
def test_initsession(self):
|
||||
config = py.test.config._reparse([self.tmpdir])
|
||||
session = config.initsession()
|
||||
assert session.config is config
|
||||
|
||||
def test_boxing_options(self):
|
||||
# XXX config.is_boxed() is probably not a good idea
|
||||
tmpdir = self.tmpdir
|
||||
config = py.test.config._reparse([tmpdir])
|
||||
assert not config.option.boxing
|
||||
assert not config.is_boxed()
|
||||
|
||||
#tmpdir.join("conftest.py").write("dist_boxing=True\n")
|
||||
#config = py.test.config._reparse([tmpdir])
|
||||
#assert config.is_boxed()
|
||||
|
||||
tmpdir.join("conftest.py").write("dist_boxing=False\n")
|
||||
config = py.test.config._reparse([tmpdir])
|
||||
assert not config.is_boxed()
|
||||
config = py.test.config._reparse([tmpdir, '--box'])
|
||||
assert config.is_boxed()
|
||||
|
||||
|
||||
class TestConfigColitems:
|
||||
def setup_class(cls):
|
||||
cls.tmproot = py.test.ensuretemp(cls.__name__)
|
||||
|
||||
def setup_method(self, method):
|
||||
self.tmpdir = self.tmproot.mkdir(method.__name__)
|
||||
|
||||
def test_getcolitems_onedir(self):
|
||||
config = py.test.config._reparse([self.tmpdir])
|
||||
colitems = config.getcolitems()
|
||||
assert len(colitems) == 1
|
||||
col = colitems[0]
|
||||
assert isinstance(col, py.test.collect.Directory)
|
||||
for col in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test_getcolitems_twodirs(self):
|
||||
config = py.test.config._reparse([self.tmpdir, self.tmpdir])
|
||||
colitems = config.getcolitems()
|
||||
assert len(colitems) == 2
|
||||
col1, col2 = colitems
|
||||
assert col1.name == col2.name
|
||||
assert col1.parent == col2.parent
|
||||
|
||||
def test_getcolitems_curdir_and_subdir(self):
|
||||
a = self.tmpdir.ensure("a", dir=1)
|
||||
config = py.test.config._reparse([self.tmpdir, a])
|
||||
colitems = config.getcolitems()
|
||||
assert len(colitems) == 2
|
||||
col1, col2 = colitems
|
||||
assert col1.name == self.tmpdir.basename
|
||||
assert col2.name == 'a'
|
||||
for col in colitems:
|
||||
for subcol in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_global_file(self):
|
||||
x = self.tmpdir.ensure("x.py")
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
assert isinstance(col, py.test.collect.Module)
|
||||
assert col.name == 'x.py'
|
||||
assert col.parent.name == self.tmpdir.basename
|
||||
assert col.parent.parent is None
|
||||
for col in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_global_dir(self):
|
||||
x = self.tmpdir.ensure("a", dir=1)
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
assert isinstance(col, py.test.collect.Directory)
|
||||
print col.listchain()
|
||||
assert col.name == 'a'
|
||||
assert col.parent is None
|
||||
assert col.config is config
|
||||
|
||||
def test__getcol_pkgfile(self):
|
||||
x = self.tmpdir.ensure("x.py")
|
||||
self.tmpdir.ensure("__init__.py")
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
assert isinstance(col, py.test.collect.Module)
|
||||
assert col.name == 'x.py'
|
||||
assert col.parent.name == x.dirpath().basename
|
||||
assert col.parent.parent is None
|
||||
for col in col.listchain():
|
||||
assert col.config is config
|
||||
|
||||
def test_get_collector_trail_and_back(self):
|
||||
a = self.tmpdir.ensure("a", dir=1)
|
||||
self.tmpdir.ensure("a", "__init__.py")
|
||||
x = self.tmpdir.ensure("a", "trail.py")
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
trail = config.get_collector_trail(col)
|
||||
assert len(trail) == 2
|
||||
assert trail[0] == a.relto(config.topdir)
|
||||
assert trail[1] == ('trail.py',)
|
||||
col2 = config._getcollector(trail)
|
||||
assert col2.listchain() == col.listchain()
|
||||
|
||||
def test_get_collector_trail_topdir_and_beyond(self):
|
||||
config = py.test.config._reparse([self.tmpdir])
|
||||
col = config._getcollector(config.topdir)
|
||||
trail = config.get_collector_trail(col)
|
||||
assert len(trail) == 2
|
||||
assert trail[0] == '.'
|
||||
assert trail[1] == ()
|
||||
col2 = config._getcollector(trail)
|
||||
assert col2.fspath == config.topdir
|
||||
assert len(col2.listchain()) == 1
|
||||
col3 = config._getcollector(config.topdir.dirpath())
|
||||
py.test.raises(ValueError,
|
||||
"config.get_collector_trail(col3)")
|
||||
|
||||
@@ -11,6 +11,11 @@ class TestConftestValueAccessGlobal:
|
||||
d.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
|
||||
d.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
|
||||
|
||||
def test_basic_init(self):
|
||||
conftest = Conftest()
|
||||
conftest.setinitial([self.basedir.join("adir")])
|
||||
assert conftest.rget("a") == 1
|
||||
|
||||
def test_immediate_initialiation_and_incremental_are_the_same(self):
|
||||
conftest = Conftest()
|
||||
snap0 = len(conftest._path2confmods)
|
||||
@@ -25,40 +30,40 @@ class TestConftestValueAccessGlobal:
|
||||
def test_default_Module_setting_is_visible_always(self):
|
||||
for path in self.basedir.parts():
|
||||
conftest = Conftest(path)
|
||||
assert conftest.lget("Module") == py.test.collect.Module
|
||||
#assert conftest.lget("Module") == py.test.collect.Module
|
||||
assert conftest.rget("Module") == py.test.collect.Module
|
||||
|
||||
def test_default_has_lower_prio(self):
|
||||
conftest = Conftest(self.basedir.join("adir"))
|
||||
assert conftest.rget('Directory') == 3
|
||||
assert conftest.lget('Directory') == py.test.collect.Directory
|
||||
#assert conftest.lget('Directory') == py.test.collect.Directory
|
||||
|
||||
def test_value_access_not_existing(self):
|
||||
conftest = Conftest(self.basedir)
|
||||
py.test.raises(KeyError, "conftest.rget('a')")
|
||||
py.test.raises(KeyError, "conftest.lget('a')")
|
||||
#py.test.raises(KeyError, "conftest.lget('a')")
|
||||
|
||||
def test_value_access_by_path(self):
|
||||
conftest = Conftest(self.basedir)
|
||||
assert conftest.rget("a", self.basedir.join('adir')) == 1
|
||||
assert conftest.lget("a", self.basedir.join('adir')) == 1
|
||||
#assert conftest.lget("a", self.basedir.join('adir')) == 1
|
||||
assert conftest.rget("a", self.basedir.join('adir', 'b')) == 1.5
|
||||
assert conftest.lget("a", self.basedir.join('adir', 'b')) == 1
|
||||
assert conftest.lget("b", self.basedir.join('adir', 'b')) == 2
|
||||
assert py.test.raises(KeyError,
|
||||
'conftest.lget("b", self.basedir.join("a"))'
|
||||
)
|
||||
#assert conftest.lget("a", self.basedir.join('adir', 'b')) == 1
|
||||
#assert conftest.lget("b", self.basedir.join('adir', 'b')) == 2
|
||||
#assert py.test.raises(KeyError,
|
||||
# 'conftest.lget("b", self.basedir.join("a"))'
|
||||
#)
|
||||
|
||||
def test_value_access_with_init_one_conftest(self):
|
||||
conftest = Conftest(self.basedir.join('adir'))
|
||||
assert conftest.rget("a") == 1
|
||||
assert conftest.lget("a") == 1
|
||||
#assert conftest.lget("a") == 1
|
||||
|
||||
def test_value_access_with_init_two_conftests(self):
|
||||
conftest = Conftest(self.basedir.join("adir", "b"))
|
||||
conftest.rget("a") == 1.5
|
||||
conftest.lget("a") == 1
|
||||
conftest.lget("b") == 1
|
||||
#conftest.lget("a") == 1
|
||||
#conftest.lget("b") == 1
|
||||
|
||||
class TestConftestValueAccessInPackage(TestConftestValueAccessGlobal):
|
||||
def setup_class(cls):
|
||||
|
||||
@@ -32,10 +32,10 @@ def test_collect_doctest_files_with_test_prefix():
|
||||
>>> i-1
|
||||
4
|
||||
"""))
|
||||
from py.__.test.collect import getfscollector
|
||||
for x in (o, checkfile):
|
||||
#print "checking that %s returns custom items" % (x,)
|
||||
col = getfscollector(x)
|
||||
config = py.test.config._reparse([x])
|
||||
col = config._getcollector(x)
|
||||
items = list(col.tryiter(py.test.Item))
|
||||
assert len(items) == 1
|
||||
assert isinstance(items[0], DoctestText)
|
||||
|
||||
64
py/test/testing/test_repr.py
Normal file
64
py/test/testing/test_repr.py
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
import py
|
||||
from py.__.test.representation import Presenter
|
||||
from py.__.test.terminal.out import getout
|
||||
from StringIO import StringIO
|
||||
import sys
|
||||
|
||||
def test_repr_source():
|
||||
source = py.code.Source("""
|
||||
def f(x):
|
||||
pass
|
||||
""").strip()
|
||||
config = py.test.config._reparse([])
|
||||
s = StringIO()
|
||||
out = getout(s)
|
||||
p = Presenter(out, config)
|
||||
p.repr_source(source, "|", 0)
|
||||
lines = s.getvalue().split("\n")
|
||||
assert len(lines) == 3
|
||||
assert lines[0].startswith("|")
|
||||
assert lines[0].find("def f(x)") != -1
|
||||
assert lines[1].find("pass") != -1
|
||||
|
||||
def test_repr_failure_explanation():
|
||||
""" We check here if indentation is right
|
||||
"""
|
||||
def f():
|
||||
def g():
|
||||
1/0
|
||||
try:
|
||||
g()
|
||||
except:
|
||||
e = py.code.ExceptionInfo()
|
||||
return e
|
||||
config = py.test.config._reparse([])
|
||||
s = StringIO()
|
||||
out = getout(s)
|
||||
p = Presenter(out, config)
|
||||
source = py.code.Source(f)
|
||||
e = f()
|
||||
p.repr_failure_explanation(e, source)
|
||||
assert s.getvalue().startswith("> ")
|
||||
|
||||
def test_repr_local():
|
||||
config = py.test.config._reparse(['--showlocals'])
|
||||
s = StringIO()
|
||||
out = getout(s)
|
||||
p = Presenter(out, config)
|
||||
p.repr_locals(locals())
|
||||
for key in locals().keys():
|
||||
assert s.getvalue().find(key) != -1
|
||||
|
||||
def test_repr_traceback_long():
|
||||
py.test.skip("unfinished")
|
||||
config = py.test.config._reparse([])
|
||||
s = StringIO()
|
||||
out = getout(s)
|
||||
p = Presenter(out, config)
|
||||
# errr... here we should
|
||||
# a) prepare an item
|
||||
# b) prepare excinfo
|
||||
# c) prepare some traceback info, with few different ideas,
|
||||
# like recursion detected etc.
|
||||
# test it...
|
||||
@@ -5,52 +5,27 @@ def setup_module(mod):
|
||||
mod.datadir = setupdatadir()
|
||||
mod.tmpdir = py.test.ensuretemp(mod.__name__)
|
||||
|
||||
class TestDefaultSession:
|
||||
def test_simple(self):
|
||||
config = py.test.config._reparse([datadir/'filetest.py'])
|
||||
session = config.getsessionclass()(config, py.std.sys.stdout)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Failed)
|
||||
assert len(l) == 2
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert not l
|
||||
def test_default_session_options():
|
||||
for opts in ([], ['-l'], ['-s'], ['--tb=no'], ['--tb=short'],
|
||||
['--tb=long'], ['--fulltrace'], ['--nomagic'],
|
||||
['--traceconfig'], ['-v'], ['-v', '-v']):
|
||||
yield runfiletest, opts
|
||||
|
||||
def test_simple_verbose(self):
|
||||
config = py.test.config._reparse([datadir/'filetest.py',
|
||||
'--verbose'])
|
||||
session = config.getsessionclass()(config, py.std.sys.stdout)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Failed)
|
||||
assert len(l) == 2
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert not l
|
||||
|
||||
def test_simple_verbose_verbose(self):
|
||||
config = py.test.config._reparse([datadir/'filetest.py',
|
||||
'-v', '-v'])
|
||||
session = config.getsessionclass()(config, py.std.sys.stdout)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Failed)
|
||||
assert len(l) == 2
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert not l
|
||||
|
||||
def test_session_parsing(self):
|
||||
from py.__.test.terminal.terminal import TerminalSession
|
||||
from py.__.test.tkinter.reportsession import ReportSession
|
||||
config = py.test.config._reparse(['--session=terminal'])
|
||||
assert issubclass(config.getsessionclass(), TerminalSession)
|
||||
config = py.test.config._reparse(['--session=tkinter'])
|
||||
assert issubclass(config.getsessionclass(), ReportSession)
|
||||
config = py.test.config._reparse(['--tkinter'])
|
||||
assert issubclass(config.getsessionclass(), ReportSession)
|
||||
def runfiletest(opts):
|
||||
config = py.test.config._reparse(opts + [datadir/'filetest.py'])
|
||||
session = config.initsession()
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Failed)
|
||||
assert len(l) == 2
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
assert not l
|
||||
|
||||
class TestKeywordSelection:
|
||||
def test_select_simple(self):
|
||||
for keyword in ['test_one', 'est_on']:
|
||||
config = py.test.config._reparse([datadir/'filetest.py',
|
||||
'-k', keyword])
|
||||
session = config.getsessionclass()(config, py.std.sys.stdout)
|
||||
session = config._getsessionclass()(config, py.std.sys.stdout)
|
||||
session.main()
|
||||
l = session.getitemoutcomepairs(py.test.Item.Failed)
|
||||
assert len(l) == 1
|
||||
@@ -79,7 +54,7 @@ class TestKeywordSelection:
|
||||
'TestClass test_2', 'xxx TestClass test_2',):
|
||||
f = py.std.StringIO.StringIO()
|
||||
config = py.test.config._reparse([o, '-k', keyword])
|
||||
session = config.getsessionclass()(config, f)
|
||||
session = config._getsessionclass()(config, f)
|
||||
session.main()
|
||||
print "keyword", repr(keyword)
|
||||
l = session.getitemoutcomepairs(py.test.Item.Passed)
|
||||
@@ -318,9 +293,8 @@ class TestTerminalSession:
|
||||
assert expected_output in out
|
||||
|
||||
|
||||
from py.__.test.terminal.remote import getrootdir
|
||||
class TestRemote:
|
||||
def test_rootdir_is_package(self):
|
||||
def XXXtest_rootdir_is_package(self):
|
||||
d = tmpdir.ensure('rootdirtest1', dir=1)
|
||||
d.ensure('__init__.py')
|
||||
x1 = d.ensure('subdir', '__init__.py')
|
||||
@@ -332,7 +306,7 @@ class TestRemote:
|
||||
assert getrootdir([x3,x2]) == d
|
||||
assert getrootdir([x2,x3]) == d
|
||||
|
||||
def test_rootdir_is_not_package(self):
|
||||
def XXXtest_rootdir_is_not_package(self):
|
||||
one = tmpdir.ensure('rootdirtest1', 'hello')
|
||||
rootdir = getrootdir([one])
|
||||
assert rootdir == one.dirpath()
|
||||
@@ -348,8 +322,7 @@ class TestRemote:
|
||||
config = py.test.config._reparse(
|
||||
['--exec=' + py.std.sys.executable,
|
||||
o])
|
||||
assert config.option._remote
|
||||
cls = config.getsessionclass()
|
||||
cls = config._getsessionclass()
|
||||
out = [] # out = py.std.Queue.Queue()
|
||||
session = cls(config, out.append)
|
||||
session.main()
|
||||
@@ -368,16 +341,16 @@ class TestRemote:
|
||||
"""))
|
||||
print py.std.sys.executable
|
||||
config = py.test.config._reparse(['--looponfailing', str(o)])
|
||||
assert config.option._remote
|
||||
cls = config.getsessionclass()
|
||||
cls = config._getsessionclass()
|
||||
out = py.std.Queue.Queue()
|
||||
session = cls(config, out.put)
|
||||
pool = py._thread.WorkerPool()
|
||||
reply = pool.dispatch(session.main)
|
||||
while 1:
|
||||
s = out.get()
|
||||
s = out.get(timeout=1.0)
|
||||
if s.find('1 failed') != -1:
|
||||
break
|
||||
print s
|
||||
else:
|
||||
py.test.fail("did not see test_1 failure")
|
||||
# XXX we would like to have a cleaner way to finish
|
||||
|
||||
Reference in New Issue
Block a user