deprecate addgroup / allow ordering of option groups
--HG-- branch : trunk
This commit is contained in:
parent
3795b08e95
commit
80f3e33e41
|
@ -21,7 +21,7 @@ class Parser:
|
||||||
|
|
||||||
def __init__(self, usage=None, processopt=None):
|
def __init__(self, usage=None, processopt=None):
|
||||||
self._anonymous = OptionGroup("custom options", parser=self)
|
self._anonymous = OptionGroup("custom options", parser=self)
|
||||||
self._groups = [self._anonymous]
|
self._groups = []
|
||||||
self._processopt = processopt
|
self._processopt = processopt
|
||||||
self._usage = usage
|
self._usage = usage
|
||||||
self.epilog = ""
|
self.epilog = ""
|
||||||
|
@ -34,19 +34,21 @@ class Parser:
|
||||||
def addnote(self, note):
|
def addnote(self, note):
|
||||||
self._notes.append(note)
|
self._notes.append(note)
|
||||||
|
|
||||||
def addgroup(self, name, description=""):
|
def getgroup(self, name, description="", after=None):
|
||||||
for group in self._groups:
|
for group in self._groups:
|
||||||
if group.name == name:
|
if group.name == name:
|
||||||
raise ValueError("group %r already exists" % name)
|
return group
|
||||||
group = OptionGroup(name, description, parser=self)
|
group = OptionGroup(name, description, parser=self)
|
||||||
self._groups.append(group)
|
i = 0
|
||||||
|
for i, grp in enumerate(self._groups):
|
||||||
|
if grp.name == after:
|
||||||
|
break
|
||||||
|
self._groups.insert(i+1, group)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def getgroup(self, name, description=""):
|
def addgroup(self, name, description=""):
|
||||||
for group in self._groups:
|
py.log._apiwarn("1.1", "use getgroup() which gets-or-creates")
|
||||||
if group.name == name:
|
return self.getgroup(name, description)
|
||||||
return group
|
|
||||||
return self.addgroup(name, description)
|
|
||||||
|
|
||||||
def addoption(self, *opts, **attrs):
|
def addoption(self, *opts, **attrs):
|
||||||
""" add an optparse-style option. """
|
""" add an optparse-style option. """
|
||||||
|
@ -56,7 +58,7 @@ class Parser:
|
||||||
optparser = optparse.OptionParser(usage=self._usage)
|
optparser = optparse.OptionParser(usage=self._usage)
|
||||||
# make sure anaonymous group is at the end
|
# make sure anaonymous group is at the end
|
||||||
optparser.epilog = self.epilog
|
optparser.epilog = self.epilog
|
||||||
groups = self._groups[1:] + [self._groups[0]]
|
groups = self._groups + [self._anonymous]
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group.options:
|
if group.options:
|
||||||
desc = group.description or group.name
|
desc = group.description or group.name
|
||||||
|
|
|
@ -73,7 +73,8 @@ def pytest_addoption(parser):
|
||||||
action="store_true", dest="looponfail", default=False,
|
action="store_true", dest="looponfail", default=False,
|
||||||
help="run tests, re-run failing test set until all pass.")
|
help="run tests, re-run failing test set until all pass.")
|
||||||
|
|
||||||
group = parser.addgroup("debugconfig", "test process debugging and configuration")
|
group = parser.getgroup("debugconfig",
|
||||||
|
"test process debugging and configuration")
|
||||||
group.addoption('--basetemp', dest="basetemp", default=None, metavar="dir",
|
group.addoption('--basetemp', dest="basetemp", default=None, metavar="dir",
|
||||||
help="base temporary directory for this test run.")
|
help="base temporary directory for this test run.")
|
||||||
|
|
||||||
|
@ -84,7 +85,8 @@ def pytest_addoption(parser):
|
||||||
"execnet missing: --looponfailing and distributed testing not available.")
|
"execnet missing: --looponfailing and distributed testing not available.")
|
||||||
|
|
||||||
def add_dist_options(parser):
|
def add_dist_options(parser):
|
||||||
group = parser.addgroup("dist", "distributed testing") # see http://pytest.org/help/dist")
|
# see http://pytest.org/help/dist")
|
||||||
|
group = parser.getgroup("dist", "distributed testing")
|
||||||
group._addoption('--dist', metavar="distmode",
|
group._addoption('--dist', metavar="distmode",
|
||||||
action="store", choices=['load', 'each', 'no'],
|
action="store", choices=['load', 'each', 'no'],
|
||||||
type="choice", dest="dist", default="no",
|
type="choice", dest="dist", default="no",
|
||||||
|
|
|
@ -18,7 +18,7 @@ from _py.code.code import TerminalRepr, ReprFileLocation
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.addgroup("doctest options")
|
group = parser.getgroup("doctest options")
|
||||||
group.addoption("--doctest-modules",
|
group.addoption("--doctest-modules",
|
||||||
action="store_true", default=False,
|
action="store_true", default=False,
|
||||||
help="search all python files for doctests",
|
help="search all python files for doctests",
|
||||||
|
|
|
@ -4,7 +4,7 @@ rsyncdirs = ['conftest.py', 'py', 'doc', 'testing']
|
||||||
|
|
||||||
import py
|
import py
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.addgroup("pylib", "py lib testing options")
|
group = parser.getgroup("pylib", "py lib testing options")
|
||||||
group.addoption('--sshhost',
|
group.addoption('--sshhost',
|
||||||
action="store", dest="sshhost", default=None,
|
action="store", dest="sshhost", default=None,
|
||||||
help=("ssh xspec for ssh functional tests. "))
|
help=("ssh xspec for ssh functional tests. "))
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
Changes between 1.0.2 and '1.1.0b1'
|
Changes between 1.0.2 and '1.1.0b1'
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
|
* deprecate parser.addgroup in favour of getgroup which creates option group
|
||||||
|
|
||||||
* add --report command line option that allows to control showing of skipped/xfailed sections
|
* add --report command line option that allows to control showing of skipped/xfailed sections
|
||||||
|
|
||||||
* generalized skipping: a new way to mark python functions with skipif or xfail
|
* generalized skipping: a new way to mark python functions with skipif or xfail
|
||||||
|
|
|
@ -19,11 +19,15 @@ class TestParser:
|
||||||
group = parser.addgroup("hello", description="desc")
|
group = parser.addgroup("hello", description="desc")
|
||||||
assert group.name == "hello"
|
assert group.name == "hello"
|
||||||
assert group.description == "desc"
|
assert group.description == "desc"
|
||||||
py.test.raises(ValueError, parser.addgroup, "hello")
|
|
||||||
group2 = parser.getgroup("hello")
|
|
||||||
assert group2 is group
|
|
||||||
|
|
||||||
def test_getgroup_addsgroup(self):
|
def test_addgroup_deprecation(self, recwarn):
|
||||||
|
parser = parseopt.Parser()
|
||||||
|
group = parser.addgroup("hello", description="desc")
|
||||||
|
assert recwarn.pop()
|
||||||
|
group2 = parser.getgroup("hello")
|
||||||
|
assert group == group2
|
||||||
|
|
||||||
|
def test_getgroup_simple(self):
|
||||||
parser = parseopt.Parser()
|
parser = parseopt.Parser()
|
||||||
group = parser.getgroup("hello", description="desc")
|
group = parser.getgroup("hello", description="desc")
|
||||||
assert group.name == "hello"
|
assert group.name == "hello"
|
||||||
|
@ -31,6 +35,14 @@ class TestParser:
|
||||||
group2 = parser.getgroup("hello")
|
group2 = parser.getgroup("hello")
|
||||||
assert group2 is group
|
assert group2 is group
|
||||||
|
|
||||||
|
def test_group_ordering(self):
|
||||||
|
parser = parseopt.Parser()
|
||||||
|
group0 = parser.getgroup("1")
|
||||||
|
group1 = parser.getgroup("2")
|
||||||
|
group1 = parser.getgroup("3", after="1")
|
||||||
|
groups = parser._groups
|
||||||
|
groups_names = [x.name for x in groups]
|
||||||
|
assert groups_names == list("132")
|
||||||
|
|
||||||
def test_group_addoption(self):
|
def test_group_addoption(self):
|
||||||
group = parseopt.OptionGroup("hello")
|
group = parseopt.OptionGroup("hello")
|
||||||
|
|
Loading…
Reference in New Issue