parent
9854d9497c
commit
767dcc69f3
|
@ -1,98 +1,93 @@
|
||||||
import py
|
import py
|
||||||
from py.__.test.conftesthandle import Conftest
|
from py.__.test.conftesthandle import Conftest
|
||||||
|
|
||||||
class TestConftestValueAccessGlobal:
|
def pytest_generate_tests(metafunc, generator):
|
||||||
def setup_class(cls):
|
if "basedir" in metafunc.funcargnames:
|
||||||
# if we have "global" conftests (i.e. no __init__.py
|
metafunc.addcall(param="global")
|
||||||
# and thus no further import scope) it should still all work
|
metafunc.addcall(param="inpackage")
|
||||||
# because "global" conftests are imported with a
|
|
||||||
# mangled module name (related to their actual path)
|
def pytest_funcarg__basedir(request):
|
||||||
cls.basedir = d = py.test.ensuretemp(cls.__name__)
|
def basedirmaker(request):
|
||||||
|
basedir = d = request.config.ensuretemp(request.param)
|
||||||
d.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
|
d.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
|
||||||
d.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
|
d.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
|
||||||
|
if request.param == "inpackage":
|
||||||
|
d.ensure("adir/__init__.py")
|
||||||
|
d.ensure("adir/b/__init__.py")
|
||||||
|
return d
|
||||||
|
return request.cached_setup(perclass=basedirmaker)
|
||||||
|
return request.cached_setup(perclass=basedirmaker)
|
||||||
|
|
||||||
def test_basic_init(self):
|
class TestConftestValueAccessGlobal:
|
||||||
|
def test_basic_init(self, basedir):
|
||||||
conftest = Conftest()
|
conftest = Conftest()
|
||||||
conftest.setinitial([self.basedir.join("adir")])
|
conftest.setinitial([basedir.join("adir")])
|
||||||
assert conftest.rget("a") == 1
|
assert conftest.rget("a") == 1
|
||||||
|
|
||||||
def test_onimport(self):
|
def test_onimport(self, basedir):
|
||||||
l = []
|
l = []
|
||||||
conftest = Conftest(onimport=l.append)
|
conftest = Conftest(onimport=l.append)
|
||||||
conftest.setinitial([self.basedir.join("adir")])
|
conftest.setinitial([basedir.join("adir")])
|
||||||
assert len(l) == 2 # default + the one
|
assert len(l) == 2 # default + the one
|
||||||
assert conftest.rget("a") == 1
|
assert conftest.rget("a") == 1
|
||||||
assert conftest.rget("b", self.basedir.join("adir", "b")) == 2
|
assert conftest.rget("b", basedir.join("adir", "b")) == 2
|
||||||
assert len(l) == 3
|
assert len(l) == 3
|
||||||
|
|
||||||
def test_immediate_initialiation_and_incremental_are_the_same(self):
|
def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
|
||||||
conftest = Conftest()
|
conftest = Conftest()
|
||||||
snap0 = len(conftest._path2confmods)
|
snap0 = len(conftest._path2confmods)
|
||||||
conftest.getconftestmodules(self.basedir)
|
conftest.getconftestmodules(basedir)
|
||||||
snap1 = len(conftest._path2confmods)
|
snap1 = len(conftest._path2confmods)
|
||||||
#assert len(conftest._path2confmods) == snap1 + 1
|
#assert len(conftest._path2confmods) == snap1 + 1
|
||||||
conftest.getconftestmodules(self.basedir.join('adir'))
|
conftest.getconftestmodules(basedir.join('adir'))
|
||||||
assert len(conftest._path2confmods) == snap1 + 1
|
assert len(conftest._path2confmods) == snap1 + 1
|
||||||
conftest.getconftestmodules(self.basedir.join('b'))
|
conftest.getconftestmodules(basedir.join('b'))
|
||||||
assert len(conftest._path2confmods) == snap1 + 2
|
assert len(conftest._path2confmods) == snap1 + 2
|
||||||
|
|
||||||
def test_default_Module_setting_is_visible_always(self):
|
def test_default_Module_setting_is_visible_always(self, basedir):
|
||||||
for path in self.basedir.parts():
|
for path in basedir.parts():
|
||||||
conftest = Conftest(path)
|
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
|
assert conftest.rget("Module") == py.test.collect.Module
|
||||||
|
|
||||||
def test_default_has_lower_prio(self):
|
def test_default_has_lower_prio(self, basedir):
|
||||||
conftest = Conftest(self.basedir.join("adir"))
|
conftest = Conftest(basedir.join("adir"))
|
||||||
assert conftest.rget('Directory') == 3
|
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):
|
def test_value_access_not_existing(self, basedir):
|
||||||
conftest = Conftest(self.basedir)
|
conftest = Conftest(basedir)
|
||||||
py.test.raises(KeyError, "conftest.rget('a')")
|
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):
|
def test_value_access_by_path(self, basedir):
|
||||||
conftest = Conftest(self.basedir)
|
conftest = Conftest(basedir)
|
||||||
assert conftest.rget("a", self.basedir.join('adir')) == 1
|
assert conftest.rget("a", basedir.join('adir')) == 1
|
||||||
#assert conftest.lget("a", self.basedir.join('adir')) == 1
|
#assert conftest.lget("a", basedir.join('adir')) == 1
|
||||||
assert conftest.rget("a", self.basedir.join('adir', 'b')) == 1.5
|
assert conftest.rget("a", basedir.join('adir', 'b')) == 1.5
|
||||||
#assert conftest.lget("a", self.basedir.join('adir', 'b')) == 1
|
#assert conftest.lget("a", basedir.join('adir', 'b')) == 1
|
||||||
#assert conftest.lget("b", self.basedir.join('adir', 'b')) == 2
|
#assert conftest.lget("b", basedir.join('adir', 'b')) == 2
|
||||||
#assert py.test.raises(KeyError,
|
#assert py.test.raises(KeyError,
|
||||||
# 'conftest.lget("b", self.basedir.join("a"))'
|
# 'conftest.lget("b", basedir.join("a"))'
|
||||||
#)
|
#)
|
||||||
|
|
||||||
def test_value_access_with_init_one_conftest(self):
|
def test_value_access_with_init_one_conftest(self, basedir):
|
||||||
conftest = Conftest(self.basedir.join('adir'))
|
conftest = Conftest(basedir.join('adir'))
|
||||||
assert conftest.rget("a") == 1
|
assert conftest.rget("a") == 1
|
||||||
#assert conftest.lget("a") == 1
|
#assert conftest.lget("a") == 1
|
||||||
|
|
||||||
def test_value_access_with_init_two_conftests(self):
|
def test_value_access_with_init_two_conftests(self, basedir):
|
||||||
conftest = Conftest(self.basedir.join("adir", "b"))
|
conftest = Conftest(basedir.join("adir", "b"))
|
||||||
conftest.rget("a") == 1.5
|
conftest.rget("a") == 1.5
|
||||||
#conftest.lget("a") == 1
|
#conftest.lget("a") == 1
|
||||||
#conftest.lget("b") == 1
|
#conftest.lget("b") == 1
|
||||||
|
|
||||||
def test_value_access_with_confmod(self):
|
def test_value_access_with_confmod(self, basedir):
|
||||||
topdir = self.basedir.join("adir", "b")
|
topdir = basedir.join("adir", "b")
|
||||||
topdir.ensure("xx", dir=True)
|
topdir.ensure("xx", dir=True)
|
||||||
conftest = Conftest(topdir)
|
conftest = Conftest(topdir)
|
||||||
mod, value = conftest.rget_with_confmod("a", topdir)
|
mod, value = conftest.rget_with_confmod("a", topdir)
|
||||||
assert value == 1.5
|
assert value == 1.5
|
||||||
path = py.path.local(mod.__file__)
|
path = py.path.local(mod.__file__)
|
||||||
assert path.dirpath() == self.basedir.join("adir", "b")
|
assert path.dirpath() == basedir.join("adir", "b")
|
||||||
assert path.purebasename == "conftest"
|
assert path.purebasename == "conftest"
|
||||||
|
|
||||||
class TestConftestValueAccessInPackage(TestConftestValueAccessGlobal):
|
|
||||||
def setup_class(cls):
|
|
||||||
TestConftestValueAccessGlobal.__dict__['setup_class'](cls)
|
|
||||||
d = cls.basedir
|
|
||||||
d.ensure("adir/__init__.py")
|
|
||||||
d.ensure("adir/b/__init__.py")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue