Commits

holger krekel  committed 4796aab

add __contains__ and CHANGELOG

  • Participants
  • Parent commits ee76a01

Comments (0)

Files changed (4)

+
+0.2
+==================
+
+- added ability to ask "name in iniconfig", i.e. to check
+  if a section is contained.
     ['section1', 'section2']
     >>> list(list(ini)[0].items())
     [('name1', 'value1'), ('name1b', 'value1,value2')]
-
+    >>> 'section1' in ini
+    True
+    >>> 'inexistendsection' in ini
+    False

File iniconfig.py

     def __iter__(self):
         for name in sorted(self.sections, key=self.lineof):
             yield SectionWrapper(self, name)
+
+    def __contains__(self, arg):
+        return arg in self.sections

File test_iniconfig.py

     assert l[1].name == 'section2'
     assert l[1]['value'] == '2'
 
+def test_config_contains():
+    config = IniConfig("x.ini", data=dedent('''
+          [section1]
+          value=1
+          [section2]
+          value=2
+    '''))
+    assert 'xyz' not in config
+    assert 'section1' in config
+    assert 'section2' in config
+
 def test_iter_file_order():
     config = IniConfig("x.ini", data="""
 [section2] #cpython dict ordered before section