[svn r62290] slightly sanitizing initialization of serialised config objects.
--HG-- branch : trunk
This commit is contained in:
parent
0b074ae555
commit
50acc51ac1
|
@ -28,8 +28,9 @@ class Config(object):
|
||||||
_initialized = False
|
_initialized = False
|
||||||
_sessionclass = None
|
_sessionclass = None
|
||||||
|
|
||||||
def __init__(self, pytestplugins=None):
|
def __init__(self, pytestplugins=None, topdir=None):
|
||||||
self.option = CmdOptions()
|
self.option = CmdOptions()
|
||||||
|
self.topdir = topdir
|
||||||
self._parser = parseopt.Parser(
|
self._parser = parseopt.Parser(
|
||||||
usage="usage: %prog [options] [file_or_dir] [file_or_dir] [...]",
|
usage="usage: %prog [options] [file_or_dir] [file_or_dir] [...]",
|
||||||
processopt=self._processopt,
|
processopt=self._processopt,
|
||||||
|
@ -46,6 +47,11 @@ class Config(object):
|
||||||
if not hasattr(self.option, opt.dest):
|
if not hasattr(self.option, opt.dest):
|
||||||
setattr(self.option, opt.dest, opt.default)
|
setattr(self.option, opt.dest, opt.default)
|
||||||
|
|
||||||
|
def _preparse(self, args):
|
||||||
|
self._conftest.setinitial(args)
|
||||||
|
self.pytestplugins.consider_env()
|
||||||
|
self.pytestplugins.do_addoption(self._parser)
|
||||||
|
|
||||||
def parse(self, args):
|
def parse(self, args):
|
||||||
""" parse cmdline arguments into this config object.
|
""" parse cmdline arguments into this config object.
|
||||||
Note that this can only be called once per testing process.
|
Note that this can only be called once per testing process.
|
||||||
|
@ -53,9 +59,7 @@ class Config(object):
|
||||||
assert not self._initialized, (
|
assert not self._initialized, (
|
||||||
"can only parse cmdline args at most once per Config object")
|
"can only parse cmdline args at most once per Config object")
|
||||||
self._initialized = True
|
self._initialized = True
|
||||||
self._conftest.setinitial(args)
|
self._preparse(args)
|
||||||
self.pytestplugins.consider_env()
|
|
||||||
self.pytestplugins.do_addoption(self._parser)
|
|
||||||
args = self._parser.parse_setoption(args, self.option)
|
args = self._parser.parse_setoption(args, self.option)
|
||||||
if not args:
|
if not args:
|
||||||
args.append(py.std.os.getcwd())
|
args.append(py.std.os.getcwd())
|
||||||
|
@ -74,11 +78,11 @@ class Config(object):
|
||||||
def _initafterpickle(self, topdir):
|
def _initafterpickle(self, topdir):
|
||||||
self.__init__(
|
self.__init__(
|
||||||
#issue1
|
#issue1
|
||||||
#pytestplugins=py.test._PytestPlugins(py._com.pyplugins)
|
#pytestplugins=py.test._PytestPlugins(py._com.pyplugins),
|
||||||
|
topdir=topdir,
|
||||||
)
|
)
|
||||||
self._initialized = True
|
|
||||||
self.topdir = py.path.local(topdir)
|
|
||||||
self._mergerepr(self._repr)
|
self._mergerepr(self._repr)
|
||||||
|
self._initialized = True
|
||||||
del self._repr
|
del self._repr
|
||||||
|
|
||||||
def _makerepr(self):
|
def _makerepr(self):
|
||||||
|
@ -98,7 +102,7 @@ class Config(object):
|
||||||
args, cmdlineopts = repr
|
args, cmdlineopts = repr
|
||||||
self.args = [self.topdir.join(x) for x in args]
|
self.args = [self.topdir.join(x) for x in args]
|
||||||
self.option = cmdlineopts
|
self.option = cmdlineopts
|
||||||
self._conftest.setinitial(self.args)
|
self._preparse(self.args)
|
||||||
|
|
||||||
def getcolitems(self):
|
def getcolitems(self):
|
||||||
return [self.getfsnode(arg) for arg in self.args]
|
return [self.getfsnode(arg) for arg in self.args]
|
||||||
|
|
|
@ -4,6 +4,7 @@ pytes plugin for easing testing of pytest runs themselves.
|
||||||
|
|
||||||
import py
|
import py
|
||||||
from py.__.test import event
|
from py.__.test import event
|
||||||
|
from py.__.test.config import Config as pytestConfig
|
||||||
|
|
||||||
class PytesterPlugin:
|
class PytesterPlugin:
|
||||||
def pytest_pyfuncarg_linecomp(self, pyfuncitem):
|
def pytest_pyfuncarg_linecomp(self, pyfuncitem):
|
||||||
|
@ -49,8 +50,11 @@ class TmpTestdir:
|
||||||
self.tmpdir = tmpdir.mkdir(name)
|
self.tmpdir = tmpdir.mkdir(name)
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self._syspathremove = []
|
self._syspathremove = []
|
||||||
from py.__.test.config import Config
|
|
||||||
self.Config = Config
|
def Config(self, pyplugins=None, topdir=None):
|
||||||
|
if topdir is None:
|
||||||
|
topdir = self.tmpdir.dirpath()
|
||||||
|
return pytestConfig(pyplugins, topdir=topdir)
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
for p in self._syspathremove:
|
for p in self._syspathremove:
|
||||||
|
|
|
@ -285,10 +285,10 @@ class TestConfigPickling:
|
||||||
tmp.ensure("conftest.py").write("x=1 ; y=2")
|
tmp.ensure("conftest.py").write("x=1 ; y=2")
|
||||||
hello = tmp.ensure("test_hello.py")
|
hello = tmp.ensure("test_hello.py")
|
||||||
config = py.test.config._reparse([hello])
|
config = py.test.config._reparse([hello])
|
||||||
config2 = py.test.config._reparse([tmp.dirpath()])
|
config2 = testdir.Config()
|
||||||
config2._initialized = False # we have to do that from tests
|
config2._initialized = False # we have to do that from tests
|
||||||
config2._repr = config._makerepr()
|
config2._repr = config._makerepr()
|
||||||
config2._initafterpickle(topdir=tmp.dirpath())
|
config2._initafterpickle(tmp.dirpath())
|
||||||
|
|
||||||
for col1, col2 in zip(config.getcolitems(), config2.getcolitems()):
|
for col1, col2 in zip(config.getcolitems(), config2.getcolitems()):
|
||||||
assert col1.fspath == col2.fspath
|
assert col1.fspath == col2.fspath
|
||||||
|
@ -305,12 +305,21 @@ class TestConfigPickling:
|
||||||
tmp.ensure("conftest.py").write("x=1")
|
tmp.ensure("conftest.py").write("x=1")
|
||||||
config = py.test.config._reparse([tmp])
|
config = py.test.config._reparse([tmp])
|
||||||
repr = config._makerepr()
|
repr = config._makerepr()
|
||||||
|
|
||||||
config.option.verbose = 42
|
config.option.verbose = 42
|
||||||
repr2 = config._makerepr()
|
repr2 = config._makerepr()
|
||||||
config = py.test.config._reparse([tmp.dirpath()])
|
|
||||||
py.test.raises(KeyError, "config.getvalue('x')")
|
print "hello"
|
||||||
|
config = testdir.Config()
|
||||||
config._mergerepr(repr)
|
config._mergerepr(repr)
|
||||||
|
print config._conftest.getconftestmodules(None)
|
||||||
assert config.getvalue('x') == 1
|
assert config.getvalue('x') == 1
|
||||||
|
|
||||||
|
config = testdir.Config()
|
||||||
|
config._preparse([])
|
||||||
|
py.test.raises(KeyError, "config.getvalue('x')")
|
||||||
|
|
||||||
|
config = testdir.Config()
|
||||||
config._mergerepr(repr2)
|
config._mergerepr(repr2)
|
||||||
assert config.option.verbose == 42
|
assert config.option.verbose == 42
|
||||||
|
|
||||||
|
@ -327,13 +336,16 @@ class TestConfigPickling:
|
||||||
config = py.test.config._reparse([tmp, "-G", "11"])
|
config = py.test.config._reparse([tmp, "-G", "11"])
|
||||||
assert config.option.gdest == 11
|
assert config.option.gdest == 11
|
||||||
repr = config._makerepr()
|
repr = config._makerepr()
|
||||||
config = py.test.config._reparse([tmp.dirpath()])
|
|
||||||
|
config = testdir.Config()
|
||||||
py.test.raises(AttributeError, "config.option.gdest")
|
py.test.raises(AttributeError, "config.option.gdest")
|
||||||
config._mergerepr(repr)
|
|
||||||
option = config.addoptions("testing group",
|
config2 = testdir.Config()
|
||||||
config.Option('-G', '--glong', action="store", default=42,
|
config2._mergerepr(repr)
|
||||||
|
option = config2.addoptions("testing group",
|
||||||
|
config2.Option('-G', '--glong', action="store", default=42,
|
||||||
type="int", dest="gdest", help="g value."))
|
type="int", dest="gdest", help="g value."))
|
||||||
assert config.option.gdest == 11
|
assert config2.option.gdest == 11
|
||||||
assert option.gdest == 11
|
assert option.gdest == 11
|
||||||
|
|
||||||
def test_config_picklability(self, tmpdir):
|
def test_config_picklability(self, tmpdir):
|
||||||
|
|
Loading…
Reference in New Issue