getgroup can also create groups now

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-04-13 12:33:01 +02:00
parent ef63510f42
commit 5c854bea30
2 changed files with 11 additions and 3 deletions

View File

@ -38,11 +38,11 @@ class Parser:
self._groups.append(group)
return group
def getgroup(self, name):
def getgroup(self, name, description=""):
for group in self._groups:
if group.name == name:
return group
raise ValueError("group %r not found" %(name,))
return self.addgroup(name, description)
def addoption(self, *opts, **attrs):
""" add an optparse-style option. """

View File

@ -18,7 +18,15 @@ class TestParser:
py.test.raises(ValueError, parser.addgroup, "hello")
group2 = parser.getgroup("hello")
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):
group = parseopt.OptionGroup("hello")