[pypy-svn] r33128 - in pypy/branch/even-more-config2/pypy/config: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Oct 10 18:53:11 CEST 2006


Author: cfbolz
Date: Tue Oct 10 18:53:10 2006
New Revision: 33128

Modified:
   pypy/branch/even-more-config2/pypy/config/config.py
   pypy/branch/even-more-config2/pypy/config/test/test_config.py
Log:
make it possible to disable generation of the negative.


Modified: pypy/branch/even-more-config2/pypy/config/config.py
==============================================================================
--- pypy/branch/even-more-config2/pypy/config/config.py	(original)
+++ pypy/branch/even-more-config2/pypy/config/config.py	Tue Oct 10 18:53:10 2006
@@ -191,16 +191,17 @@
         return "with" + optname[len("without"):]
     if optname.startswith("with"):
         return "without" + optname[len("with"):]
-    return "no" + optname
+    return "no-" + optname
 
 class BoolOption(ChoiceOption):
     def __init__(self, name, doc, default=True, requires=None,
-                 cmdline=DEFAULT_OPTION_NAME):
+                 cmdline=DEFAULT_OPTION_NAME, negation=True):
         if requires is not None:
             requires = {True: requires}
         super(BoolOption, self).__init__(name, doc, [True, False], default,
                                          requires=requires,
                                          cmdline=cmdline)
+        self.negation = negation
 
     def validate(self, value):
         return isinstance(value, bool)
@@ -211,6 +212,8 @@
                 config.setoption(self._name, True, who='cmdline')
             except ValueError, e:
                 raise optparse.OptionValueError(e.args[0])
+        if not self.negation:
+            return
         option = parser.add_option(help=self.doc,
                                    action='callback',
                                    callback=_callback, *argnames)

Modified: pypy/branch/even-more-config2/pypy/config/test/test_config.py
==============================================================================
--- pypy/branch/even-more-config2/pypy/config/test/test_config.py	(original)
+++ pypy/branch/even-more-config2/pypy/config/test/test_config.py	Tue Oct 10 18:53:10 2006
@@ -148,7 +148,12 @@
                              cmdline='--bool1 -b')
     booloption2 = BoolOption('bool2', 'Boolean option test', default=True,
                              cmdline='--with-bool2 -c')
-    descr = OptionDescription('test', '', [booloption1, booloption2])
+    booloption3 = BoolOption('bool3', 'Boolean option test', default=True,
+                             cmdline='--bool3')
+    booloption4 = BoolOption('bool4', 'Boolean option test', default=True,
+                             cmdline='--bool4', negation=False)
+    descr = OptionDescription('test', '', [booloption1, booloption2,
+                                           booloption3, booloption4])
     config = Config(descr)
 
     parser = to_optparse(config, ['bool1', 'bool2'])
@@ -158,13 +163,16 @@
     assert config.bool2
 
     config = Config(descr)
-    parser = to_optparse(config, ['bool1', 'bool2'])
-    (options, args) = parser.parse_args(args=['--without-bool2'])
+    parser = to_optparse(config, ['bool1', 'bool2', 'bool3', 'bool4'])
+    (options, args) = parser.parse_args(args=['--without-bool2', '--no-bool3'])
     assert not config.bool1
     assert not config.bool2
+    assert not config.bool3
 
     py.test.raises(SystemExit,
             "(options, args) = parser.parse_args(args=['-bfoo'])")
+    py.test.raises(SystemExit,
+            "(options, args) = parser.parse_args(args=['--no-bool4'])")
 
 def test_optparse_boolgroup():
     group = OptionDescription("test", '', [



More information about the Pypy-commit mailing list