# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <hol...@merlinux.eu>
# Date 1288996651 -3600
# Node ID 125c0136ba20fa7c651de76a4c679b1c59440487
# Parent  e4e9f0f7c4dd2e8b39991b38db44f676802f1b99
add "linelist" type for ini-files

--- a/pytest/plugin/config.py
+++ b/pytest/plugin/config.py
@@ -70,7 +70,7 @@ class Parser:
 
     def addini(self, name, help, type=None, default=None):
         """ add an ini-file option with the given name and description. """
-        assert type in (None, "pathlist", "args")
+        assert type in (None, "pathlist", "args", "linelist")
         self._inidict[name] = (help, type, default)
 
 class OptionGroup:
@@ -365,7 +365,9 @@ class Config(object):
         except KeyError:
             if default is not None:
                 return default
-            return {'pathlist': [], 'args': [], None: ''}.get(type)
+            if type is None:
+                return ''
+            return []
         if type == "pathlist":
             dp = py.path.local(self.inicfg.config.path).dirpath()
             l = []
@@ -374,6 +376,8 @@ class Config(object):
             return l
         elif type == "args":
             return py.std.shlex.split(value)
+        elif type == "linelist":
+            return filter(None, map(lambda x: x.strip(), value.split("\n")))
         else:
             assert type is None
             return value

--- a/testing/test_config.py
+++ b/testing/test_config.py
@@ -169,6 +169,24 @@ class TestConfigAPI:
         l = config.getini("a2")
         assert l == list("123")
 
+    def test_addini_linelist(self, testdir):
+        testdir.makeconftest("""
+            def pytest_addoption(parser):
+                parser.addini("xy", "", type="linelist")
+                parser.addini("a2", "", "linelist")
+        """)
+        p = testdir.makeini("""
+            [pytest]
+            xy= 123 345
+                second line
+        """)
+        config = testdir.parseconfig()
+        l = config.getini("xy")
+        assert len(l) == 2
+        assert l == ["123 345", "second line"]
+        l = config.getini("a2")
+        assert l == []
+
 def test_options_on_small_file_do_not_blow_up(testdir):
     def runfiletest(opts):
         reprec = testdir.inline_run(*opts)
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to