Armin Rigo avatar Armin Rigo committed e63b94f

Fix conftest to recognize both the old and the new format of --info,
based on a function that parses either.

Comments (0)

Files changed (3)

lib-python/conftest.py

 
 from pypy.tool.pytest import appsupport 
 from pypy.tool.pytest.confpath import pypydir, testdir, testresultdir
+from pypy.config.parse import parse_info
 
 pytest_plugins = "resultlog",
 rsyncdirs = ['.', '../pypy/']
 
             # check modules
             info = py.process.cmdexec("%s --info" % execpath)
+            info = parse_info(info)
             for mod in regrtest.usemodules:
-                if "objspace.usemodules.%s: False" % mod in info:
+                if info.get('objspace.usemodules.%s' % mod) is not True:
                     py.test.skip("%s module not included in %s" % (mod,
                                                                    execpath))
                     

pypy/config/parse.py

+
+
+def parse_info(text):
+    """See test_parse.py."""
+    text = text.lstrip()
+    result = {}
+    if text.startswith('['):
+        # new format
+        current = {0: ''}
+        indentation_prefix = None
+        for line in text.splitlines():
+            line = line.rstrip()
+            if not line:
+                continue
+            realline = line.lstrip()
+            indent = len(line) - len(realline)
+            #
+            # 'indentation_prefix' is set when the previous line was a [group]
+            if indentation_prefix is not None:
+                assert indent > max(current)     # missing indent?
+                current[indent] = indentation_prefix
+                indentation_prefix = None
+                #
+            else:
+                # in case of dedent, must kill the extra items from 'current'
+                for n in current.keys():
+                    if n > indent:
+                        del current[n]
+            #
+            prefix = current[indent]      # KeyError if bad dedent
+            #
+            if realline.startswith('[') and realline.endswith(']'):
+                indentation_prefix = prefix + realline[1:-1] + '.'
+            else:
+                # build the whole dotted key and evaluate the value
+                i = realline.index(' = ')
+                key = prefix + realline[:i]
+                value = realline[i+3:]
+                value = eval(value, {})
+                result[key] = value
+        #
+    else:
+        # old format
+        for line in text.splitlines():
+            i = line.index(':')
+            key = line[:i].strip()
+            value = line[i+1:].strip()
+            try:
+                value = int(value)
+            except ValueError:
+                if value in ('True', 'False', 'None'):
+                    value = eval(value, {})
+            result[key] = value
+        #
+    return result

pypy/config/test/test_parse.py

+from pypy.config.parse import parse_info
+
+
+def test_parse_new_format():
+    assert (parse_info("[foo]\n"
+                       "    bar = True\n")
+            == {'foo.bar': True})
+    
+    assert (parse_info("[objspace]\n"
+                       "    x = 'hello'\n"
+                       "[translation]\n"
+                       "    bar = 42\n"
+                       "    [egg]\n"
+                       "        something = None\n"
+                       "    foo = True\n")
+            == {
+        'translation.foo': True,
+        'translation.bar': 42,
+        'translation.egg.something': None,
+        'objspace.x': 'hello',
+        })
+
+def test_parse_old_format():
+    assert (parse_info("                          objspace.allworkingmodules: True\n"
+                       "                    objspace.disable_call_speedhacks: False\n"
+                       "                                 objspace.extmodules: None\n"
+                       "                                       objspace.name: std\n"
+                       "                        objspace.std.prebuiltintfrom: -5\n")
+            == {
+        'objspace.allworkingmodules': True,
+        'objspace.disable_call_speedhacks': False,
+        'objspace.extmodules': None,
+        'objspace.name': 'std',
+        'objspace.std.prebuiltintfrom': -5,
+        })
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.