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

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Sep 7 15:32:34 CEST 2006


Author: cfbolz
Date: Thu Sep  7 15:32:32 2006
New Revision: 32054

Modified:
   pypy/branch/config-in-more-places/pypy/config/config.py
   pypy/branch/config-in-more-places/pypy/config/test/test_config.py
Log:
allow to prevent some options from being exposed on the cmdline


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 15:32:32 2006
@@ -106,8 +106,12 @@
                 paths.append('.'.join(currpath + [attr]))
         return paths
 
+
+DEFAULT_OPTION_NAME = object()
+
+
 class Option(object):
-    def __init__(self, name, doc, cmdline=None):
+    def __init__(self, name, doc, cmdline=DEFAULT_OPTION_NAME):
         self._name = name
         self.doc = doc
         self.cmdline = cmdline
@@ -131,7 +135,7 @@
         raise NotImplemented('abstract base class')
 
 class ChoiceOption(Option):
-    def __init__(self, name, doc, values, default, cmdline=None):
+    def __init__(self, name, doc, values, default, cmdline=DEFAULT_OPTION_NAME):
         super(ChoiceOption, self).__init__(name, doc, cmdline)
         self.values = values
         self.default = default
@@ -150,7 +154,7 @@
                             callback=_callback, *argnames)
 
 class BoolOption(ChoiceOption):
-    def __init__(self, name, doc, default=True, requires=None, cmdline=None):
+    def __init__(self, name, doc, default=True, requires=None, cmdline=DEFAULT_OPTION_NAME):
         super(BoolOption, self).__init__(name, doc, [True, False], default,
                                             cmdline=cmdline)
         self._requires = requires or []
@@ -173,7 +177,7 @@
                             callback=_callback, *argnames)
 
 class IntOption(Option):
-    def __init__(self, name, doc, default=0, cmdline=None):
+    def __init__(self, name, doc, default=0, cmdline=DEFAULT_OPTION_NAME):
         super(IntOption, self).__init__(name, doc, cmdline)
         self.default = default
 
@@ -198,7 +202,7 @@
                             callback=_callback, *argnames)
 
 class FloatOption(Option):
-    def __init__(self, name, doc, default=0.0, cmdline=None):
+    def __init__(self, name, doc, default=0.0, cmdline=DEFAULT_OPTION_NAME):
         super(FloatOption, self).__init__(name, doc, cmdline)
         self.default = default
 
@@ -223,7 +227,7 @@
                             callback=_callback, *argnames)
 
 class OptionDescription(object):
-    def __init__(self, name, children, cmdline=None):
+    def __init__(self, name, children, cmdline=DEFAULT_OPTION_NAME):
         self._name = name
         self._children = children
         self._build()
@@ -274,8 +278,10 @@
         else:
             subconf, name = config._get_by_path(path)
             option = getattr(subconf._descr, name)
-            if option.cmdline is None:
+            if option.cmdline is DEFAULT_OPTION_NAME:
                 chunks = ('--%s' % (path.replace('.', '-'),),)
+            elif option.cmdline is None:
+                continue
             else:
                 chunks = option.cmdline.split(' ')
             option.add_optparse_option(chunks, parser, subconf)

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 15:32:32 2006
@@ -4,7 +4,7 @@
 def make_description():
     gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
     gcdummy = BoolOption('dummy', 'dummy', default=False)
-    objspaceoption = ChoiceOption('objspace', 'Object space', 
+    objspaceoption = ChoiceOption('objspace', 'Object space',
                                 ['std', 'logic'], 'std')
     booloption = BoolOption('bool', 'Test boolean option')
     intoption = IntOption('int', 'Test int option')
@@ -115,7 +115,7 @@
     assert config.gc.name == 'ref'
 
     # XXX strange exception
-    py.test.raises(SystemExit, 
+    py.test.raises(SystemExit,
                     "(options, args) = parser.parse_args(args=['-g foobar'])")
 
 def test_to_optparse_number():
@@ -211,3 +211,14 @@
     assert config.getpaths(), ['gc.name', 'gc.dummy', 'gc.float', 'bool', 
                                 'objspace', 'wantref', 'int']
     assert config.gc.getpaths(), ['name', 'dummy', 'float']
+
+def test_none():
+    dummy1 = BoolOption('dummy1', 'doc dummy', default=False, cmdline=None)
+    dummy2 = BoolOption('dummy2', 'doc dummy', default=False, cmdline='--dummy')
+    group = OptionDescription('group', [dummy1, dummy2])
+    config = Config(group)
+
+    parser = to_optparse(config, config.getpaths())
+    py.test.raises(SystemExit,
+        "(options, args) = parser.parse_args(args=['--dummy1'])")
+ 



More information about the Pypy-commit mailing list