one less exception

This commit is contained in:
Jörn-Michael Miehe 2021-10-28 15:39:11 +02:00
parent 2a8764577f
commit 1dcf542c6d
2 changed files with 2 additions and 7 deletions

View file

@ -154,15 +154,13 @@ class KiwiConfig(BaseModel):
return cls() return cls()
def get_project_config(self, name: str) -> ProjectConfig: def get_project_config(self, name: str) -> Optional[ProjectConfig]:
"""returns the config of a project with a given name""" """returns the config of a project with a given name"""
for project in self.projects: for project in self.projects:
if project.name == name: if project.name == name:
return project return project
raise ValueError("No Such Project")
@property @property
def kiwi_dict(self) -> Dict[str, Any]: def kiwi_dict(self) -> Dict[str, Any]:
"""write this object as a dictionary of strings""" """write this object as a dictionary of strings"""

View file

@ -149,10 +149,7 @@ class TestProject:
assert c == KiwiConfig(projects=[]) assert c == KiwiConfig(projects=[])
assert c.projects == [] assert c.projects == []
with pytest.raises(ValueError) as exc_info: assert c.get_project_config("invalid") is None
c.get_project_config("invalid")
assert str(exc_info.value) == "No Such Project"
def test_long(self): def test_long(self):
kiwi_dict = { kiwi_dict = {