[pypy-svn] r32061 - in pypy/branch/config-in-more-places/pypy/config: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Sep 7 18:15:03 CEST 2006


Author: cfbolz
Date: Thu Sep  7 18:15:02 2006
New Revision: 32061

Modified:
   pypy/branch/config-in-more-places/pypy/config/config.py
   pypy/branch/config-in-more-places/pypy/config/test/test_config.py
Log:
 * have the paths returned by getpaths be in the right order
 * make it possible to include groups


Modified: pypy/branch/config-in-more-places/pypy/config/config.py
==============================================================================
--- pypy/branch/config-in-more-places/pypy/config/config.py	(original)
+++ pypy/branch/config-in-more-places/pypy/config/config.py	Thu Sep  7 18:15:02 2006
@@ -87,7 +87,7 @@
                 result += substr
         return result
 
-    def getpaths(self, currpath=None):
+    def getpaths(self, include_groups=False, currpath=None):
         """returns a list of all paths in self, recursively
         
             currpath should not be provided (helps with recursion)
@@ -95,12 +95,16 @@
         if currpath is None:
             currpath = []
         paths = []
-        for attr, value in self.__dict__.iteritems():
+        for option in self._descr._children:
+            attr = option._name
             if attr.startswith('_'):
                 continue
+            value = getattr(self, attr)
             if isinstance(value, Config):
+                if include_groups:
+                    paths.append('.'.join(currpath + [attr]))
                 currpath.append(attr)
-                paths += value.getpaths(currpath)
+                paths += value.getpaths(currpath=currpath)
                 currpath.pop()
             else:
                 paths.append('.'.join(currpath + [attr]))
@@ -263,12 +267,11 @@
                           callback=_callback, *argnames)
 
 
-def to_optparse(config, useoptions, parser=None):
+def to_optparse(config, parser=None):
     if parser is None:
         parser = optparse.OptionParser()
     for path in useoptions:
-        if path.endswith("*"):
-            assert path.endswith("*")
+        if path.endswith(".*"):
             path = path[:-2]
             subconf, name = config._get_by_path(path)
             children = [

Modified: pypy/branch/config-in-more-places/pypy/config/test/test_config.py
==============================================================================
--- pypy/branch/config-in-more-places/pypy/config/test/test_config.py	(original)
+++ pypy/branch/config-in-more-places/pypy/config/test/test_config.py	Thu Sep  7 18:15:02 2006
@@ -208,10 +208,12 @@
     descr = make_description()
     config = Config(descr)
     
-    assert set(config.getpaths()) == set(
-        ['gc.name', 'gc.dummy', 'gc.float', 'bool',
-         'objspace', 'wantref', 'int'])
-    assert set(config.gc.getpaths()) == set(['name', 'dummy', 'float'])
+    assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
+                                 'objspace', 'wantref', 'int']
+    assert config.gc.getpaths() == ['name', 'dummy', 'float']
+    assert config.getpaths(include_groups=True) == [
+        'gc', 'gc.name', 'gc.dummy', 'gc.float',
+        'bool', 'objspace', 'wantref', 'int']
 
 def test_none():
     dummy1 = BoolOption('dummy1', 'doc dummy', default=False, cmdline=None)



More information about the Pypy-commit mailing list