[pypy-svn] r55963 - in pypy/branch/2.5-features/pypy/translator/goal: . test2

bgola at codespeak.net bgola at codespeak.net
Thu Jun 19 17:36:54 CEST 2008


Author: bgola
Date: Thu Jun 19 17:36:53 2008
New Revision: 55963

Modified:
   pypy/branch/2.5-features/pypy/translator/goal/app_main.py
   pypy/branch/2.5-features/pypy/translator/goal/test2/test_app_main.py
Log:
supporting -W cmdline option in app_main

Modified: pypy/branch/2.5-features/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/branch/2.5-features/pypy/translator/goal/app_main.py	(original)
+++ pypy/branch/2.5-features/pypy/translator/goal/app_main.py	Thu Jun 19 17:36:53 2008
@@ -12,6 +12,7 @@
   -m             library module to be run as a script (terminates option list)
   -k, --oldstyle use old-style classes instead of newstyle classes
                  everywhere %(oldstyle)s
+  -W arg         warning control (arg is action:message:category:module:lineno)
   --version      print the PyPy version
   --info         print translation information about this PyPy executable
 """
@@ -206,6 +207,7 @@
     i = 0
     run_module = False
     run_stdin = False
+    warnoptions = []
     oldstyle_classes = False
     while i < len(argv):
         arg = argv[i]
@@ -246,9 +248,18 @@
             break
         elif arg in ('-k', '--oldstyle'):
             oldstyle_classes = True
+        elif arg.startswith('-W'):
+            arg = arg.replace("-W", "")
+            if not arg:
+                i += 1
+                if i >= len(argv):
+                    print_error('Argument expected for the -W option')
+                    return 2
+                arg = argv[i]
+            warnoptions = arg
         elif arg == '--':
             i += 1
-            break     # terminates option list
+            break     # terminates option list    
         else:
             print_error('unrecognized option %r' % (arg,))
             return 2
@@ -275,6 +286,10 @@
         except:
             print >> sys.stderr, "'import site' failed"
 
+    if warnoptions:
+        sys.warnoptions.append(warnoptions)
+        from warnings import _processoptions
+        _processoptions(sys.warnoptions)
 
     # set up the Ctrl-C => KeyboardInterrupt signal handler, if the
     # signal module is available

Modified: pypy/branch/2.5-features/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/branch/2.5-features/pypy/translator/goal/test2/test_app_main.py	(original)
+++ pypy/branch/2.5-features/pypy/translator/goal/test2/test_app_main.py	Thu Jun 19 17:36:53 2008
@@ -331,6 +331,20 @@
         assert 'NameError' in data
         assert 'Goodbye2' not in data
 
+    def test_option_W(self):
+        data = self.run('-W d -c "print 42"')
+        assert '42' in data
+        data = self.run('-Wd -c "print 42"')
+        assert '42' in data
+
+    def test_option_W_crashing(self):
+        data = self.run('-W')
+        assert 'Argument expected for the -W option' in data
+
+    def test_option_W_arg_ignored(self):
+        data = self.run('-Wc')
+        assert "Invalid -W option ignored: invalid action: 'c'" in data
+
     def test_option_c(self):
         data = self.run('-c "print 6**5"')
         assert '7776' in data



More information about the Pypy-commit mailing list