Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r54981:e63b94fbd72b Date: 2012-05-09 09:42 +0200 http://bitbucket.org/pypy/pypy/changeset/e63b94fbd72b/
Log: Fix conftest to recognize both the old and the new format of --info, based on a function that parses either. diff --git a/lib-python/conftest.py b/lib-python/conftest.py --- a/lib-python/conftest.py +++ b/lib-python/conftest.py @@ -18,6 +18,7 @@ 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/'] @@ -599,8 +600,9 @@ # 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)) diff --git a/pypy/config/parse.py b/pypy/config/parse.py new file mode 100644 --- /dev/null +++ b/pypy/config/parse.py @@ -0,0 +1,55 @@ + + +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 diff --git a/pypy/config/test/test_parse.py b/pypy/config/test/test_parse.py new file mode 100644 --- /dev/null +++ b/pypy/config/test/test_parse.py @@ -0,0 +1,35 @@ +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, + }) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit