Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions iniparse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigNamespace:
# Methods that must be implemented by subclasses

def _getitem(self, key: str) -> object:
return NotImplementedError(key)
raise NotImplementedError(key)

def __setitem__(self, key: str, value: object):
raise NotImplementedError(key, value)
Expand All @@ -32,8 +32,7 @@ def __delitem__(self, key: str) -> None:
raise NotImplementedError(key)

def __iter__(self) -> Iterable[str]:
# FIXME Raise instead return
return NotImplementedError()
raise NotImplementedError()

def _new_namespace(self, name: str) -> "ConfigNamespace":
raise NotImplementedError(name)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,25 @@ def test_option_continuation_single(self):
ip.section.option = '\n'.join(['', '', '', 'foo', '', '', ''])
ip.section.another = 'baz'
self.assertEqual(str(ip), self.s6)


class TestConfigNamespaceAbstract(unittest.TestCase):
def test_abstract_methods_raise(self):
"""
:id: 855cbd60-05d1-449f-91c0-d77a8dfa2e59
:title: Abstract ConfigNamespace methods raise NotImplementedError
:description:
Verifies that the abstract _getitem() and __iter__() methods of
ConfigNamespace raise NotImplementedError instead of returning
the exception object (which made `key in ns` always True).
:tags: Tier 3
:steps:
1. Create a bare ConfigNamespace.
2. Check membership and iterate over it.
:expectedresults:
1. Object is created.
2. NotImplementedError is raised in both cases.
"""
ns = config.ConfigNamespace()
self.assertRaises(NotImplementedError, lambda: 'key' in ns)
self.assertRaises(NotImplementedError, iter, ns)