add "linelist" type for ini-files
This commit is contained in:
parent
b1e4301457
commit
bb732a4e75
|
@ -70,7 +70,7 @@ class Parser:
|
|||
|
||||
def addini(self, name, help, type=None, default=None):
|
||||
""" add an ini-file option with the given name and description. """
|
||||
assert type in (None, "pathlist", "args")
|
||||
assert type in (None, "pathlist", "args", "linelist")
|
||||
self._inidict[name] = (help, type, default)
|
||||
|
||||
class OptionGroup:
|
||||
|
@ -365,7 +365,9 @@ class Config(object):
|
|||
except KeyError:
|
||||
if default is not None:
|
||||
return default
|
||||
return {'pathlist': [], 'args': [], None: ''}.get(type)
|
||||
if type is None:
|
||||
return ''
|
||||
return []
|
||||
if type == "pathlist":
|
||||
dp = py.path.local(self.inicfg.config.path).dirpath()
|
||||
l = []
|
||||
|
@ -374,6 +376,8 @@ class Config(object):
|
|||
return l
|
||||
elif type == "args":
|
||||
return py.std.shlex.split(value)
|
||||
elif type == "linelist":
|
||||
return filter(None, map(lambda x: x.strip(), value.split("\n")))
|
||||
else:
|
||||
assert type is None
|
||||
return value
|
||||
|
|
|
@ -169,6 +169,24 @@ class TestConfigAPI:
|
|||
l = config.getini("a2")
|
||||
assert l == list("123")
|
||||
|
||||
def test_addini_linelist(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_addoption(parser):
|
||||
parser.addini("xy", "", type="linelist")
|
||||
parser.addini("a2", "", "linelist")
|
||||
""")
|
||||
p = testdir.makeini("""
|
||||
[pytest]
|
||||
xy= 123 345
|
||||
second line
|
||||
""")
|
||||
config = testdir.parseconfig()
|
||||
l = config.getini("xy")
|
||||
assert len(l) == 2
|
||||
assert l == ["123 345", "second line"]
|
||||
l = config.getini("a2")
|
||||
assert l == []
|
||||
|
||||
def test_options_on_small_file_do_not_blow_up(testdir):
|
||||
def runfiletest(opts):
|
||||
reprec = testdir.inline_run(*opts)
|
||||
|
|
Loading…
Reference in New Issue