getgroup can also create groups now
--HG-- branch : trunk
This commit is contained in:
parent
ef63510f42
commit
5c854bea30
|
@ -38,11 +38,11 @@ class Parser:
|
||||||
self._groups.append(group)
|
self._groups.append(group)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def getgroup(self, name):
|
def getgroup(self, name, description=""):
|
||||||
for group in self._groups:
|
for group in self._groups:
|
||||||
if group.name == name:
|
if group.name == name:
|
||||||
return group
|
return group
|
||||||
raise ValueError("group %r not found" %(name,))
|
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. """
|
||||||
|
|
|
@ -18,7 +18,15 @@ class TestParser:
|
||||||
py.test.raises(ValueError, parser.addgroup, "hello")
|
py.test.raises(ValueError, parser.addgroup, "hello")
|
||||||
group2 = parser.getgroup("hello")
|
group2 = parser.getgroup("hello")
|
||||||
assert group2 is group
|
assert group2 is group
|
||||||
py.test.raises(ValueError, parser.getgroup, 'something')
|
|
||||||
|
def test_getgroup_addsgroup(self):
|
||||||
|
parser = parseopt.Parser()
|
||||||
|
group = parser.getgroup("hello", description="desc")
|
||||||
|
assert group.name == "hello"
|
||||||
|
assert group.description == "desc"
|
||||||
|
group2 = parser.getgroup("hello")
|
||||||
|
assert group2 is group
|
||||||
|
|
||||||
|
|
||||||
def test_group_addoption(self):
|
def test_group_addoption(self):
|
||||||
group = parseopt.OptionGroup("hello")
|
group = parseopt.OptionGroup("hello")
|
||||||
|
|
Loading…
Reference in New Issue