[Python-checkins] distutils2 (merge default -> default): Merge commit

eric.araujo python-checkins at python.org
Wed May 16 07:07:26 CEST 2012


http://hg.python.org/distutils2/rev/c74e6b9f1b5e
changeset:   1330:c74e6b9f1b5e
parent:      1329:99382aafa4c5
parent:      1328:478700dd4f6c
user:        Pierre Paul <info at pierre-paul.com>
date:        Sat May 12 18:15:19 2012 -0400
summary:
  Merge commit

files:
  distutils2/metadata.py                              |   4 +-
  distutils2/run.py                                   |  17 ++-
  distutils2/tests/fake_dists/python-pager-readme.rst |  62 ----------
  distutils2/tests/test_command_register.py           |  15 +-
  distutils2/tests/test_run.py                        |  32 +++++-
  5 files changed, 54 insertions(+), 76 deletions(-)


diff --git a/distutils2/metadata.py b/distutils2/metadata.py
--- a/distutils2/metadata.py
+++ b/distutils2/metadata.py
@@ -36,7 +36,7 @@
         def system_message(self, level, message, *children, **kwargs):
             self.messages.append((level, message, children, kwargs))
             return nodes.system_message(message, level=level, type=self.
-                    levels[level], *children, **kwargs)
+                                        levels[level], *children, **kwargs)
 
 
     _HAS_DOCUTILS = True
@@ -279,7 +279,7 @@
         document.note_source(source_path, -1)
         try:
             parser.parse(data, document)
-        except (AttributeError, TypeError):
+        except AttributeError:
             reporter.messages.append((-1, 'Could not finish the parsing.',
                                       '', {}))
 
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -397,8 +397,9 @@
 
         allowed = [action[0] for action in actions] + [None]
         if self.action not in allowed:
-            msg = 'Unrecognized action "%s"' % self.action
-            raise PackagingArgError(msg)
+            msg = 'Unrecognized action %s' % self.action
+            self.show_help()
+            self.exit_with_error_msg(msg)
 
         self._set_logger()
         self.args = args
@@ -444,7 +445,8 @@
         try:
             cmd_class = get_command_class(command)
         except PackagingModuleError, msg:
-            raise PackagingArgError(msg)
+            self.show_help()
+            self.exit_with_error_msg(msg)
 
         # XXX We want to push this in distutils2.command
         #
@@ -485,7 +487,11 @@
                                 cmd_class.user_options +
                                 help_options)
         parser.set_negative_aliases(_negative_opt)
-        args, opts = parser.getopt(args[1:])
+        try:
+            args, opts = parser.getopt(args[1:])
+        except PackagingArgError, msg:
+            self.show_help()
+            self.exit_with_error_msg(msg)
 
         if hasattr(opts, 'help') and opts.help:
             self._show_command_help(cmd_class)
@@ -530,6 +536,9 @@
     def show_help(self):
         self._show_help(self.parser)
 
+    def exit_with_error_msg(self, msg):
+        sys.exit('error: ' + msg.__str__())
+
     def print_usage(self, parser):
         parser.set_option_table(global_options)
 
diff --git a/distutils2/tests/fake_dists/python-pager-readme.rst b/distutils2/tests/fake_dists/python-pager-readme.rst
deleted file mode 100644
--- a/distutils2/tests/fake_dists/python-pager-readme.rst
+++ /dev/null
@@ -1,65 +0,0 @@
-
-Python module to page screen output and get dimensions
-of available console space.
-
-It is meant to be finally included into standard library
-http://bugs.python.org/issue8408
-
-| Author:  anatoly techtonik <techtonik at gmail.com>
-| License: Public Domain (or MIT if a license is required)
-
-
-Status
-------
-
-0.1 (stable)
- - shows content page by page
- - allows to get console/terminal dimensions
- - works on Windows
- - works on Linux
-
-
-API
----
-
-..function:: getwidth()
-
-  Return width of available window in characters.  If detection fails,
-  return value of standard width 80.  Coordinate of the last character
-  on a line is -1 from returned value. 
-
-
-..function:: getheight()
-
-  Return available window height in characters or 25 if detection fails.
-  Coordinate of the last line is -1 from returned value. 
-
-
-..function:: getch()
-
-  Wait for keypress and return character in a cross-platform way.
-  Credits: Danny Yoo, Python Cookbook
-
-
-..function:: page(content, [pagecallback=prompt])
-
-  Output `content` iterable, calling `pagecallback` function after each
-  page. Default :func:`prompt` callback shows 'Press any key . . . ' prompt
-  and waits for keypress.
-
-
-References
-----------
-
-Excellent tutorials for Win32 Console by Adrian Worley
-http://www.adrianxw.dk/SoftwareSite/index.html
-Console Reference on MSDN
-http://msdn.microsoft.com/en-us/library/ms682087%28VS.85%29.aspx
-
-Public Domain Curses library maintained by William McBrine
-http://pdcurses.sourceforge.net/
-
-Ioctl (input/output control) introduction from Wikipedia
-http://en.wikipedia.org/wiki/Ioctl
-Linux Programmer's Manual - ioctls for terminals and serial lines
-http://www.kernel.org/doc/man-pages/online/pages/man4/tty_ioctl.4.html
diff --git a/distutils2/tests/test_command_register.py b/distutils2/tests/test_command_register.py
--- a/distutils2/tests/test_command_register.py
+++ b/distutils2/tests/test_command_register.py
@@ -10,7 +10,7 @@
     DOCUTILS_SUPPORT = False
 
 from distutils2.tests import unittest, support
-from distutils2.tests.support import Inputs
+from distutils2.tests.support import (Inputs, requires_docutils)
 from distutils2.command import register as register_module
 from distutils2.command.register import register
 from distutils2.errors import PackagingSetupError
@@ -253,12 +253,10 @@
         self.assertEqual(data['metadata_version'], '1.2')
         self.assertEqual(data['requires_dist'], ['lxml'])
 
+    @requires_docutils
     def test_register_invalid_long_description(self):
-        readme_file = os.path.join(os.path.dirname(__file__),
-                'fake_dists', 'python-pager-readme.rst')
-
-        # Contains :func: which break the rst format 
-        data = "".join(open(readme_file).readlines())
+        # Contains :func: which break the rst format
+        data = "Default :func:`prompt` callback shows"
 
         metadata = {'Home-page': 'xxx', 'Author': 'xxx',
                     'Author-email': 'xxx',
@@ -270,7 +268,10 @@
         cmd.strict = True
         inputs = Inputs('2', 'tarek', 'tarek at ziade.org')
         register_module.raw_input = inputs
-        self.assertRaises(PackagingSetupError, cmd.run)
+        with self.assertRaises(PackagingSetupError) as e:
+            cmd.run()
+        self.assertIsNotNone(e)
+        self.assertIn('func', repr(e.exception))
 
 def test_suite():
     return unittest.makeSuite(RegisterTestCase)
diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py
--- a/distutils2/tests/test_run.py
+++ b/distutils2/tests/test_run.py
@@ -8,7 +8,7 @@
 from distutils2.tests import unittest, support
 from distutils2.run import main
 
-from distutils2.tests.support import assert_python_ok
+from distutils2.tests.support import assert_python_ok, assert_python_failure
 
 # setup script that uses __file__
 setup_using___file__ = """\
@@ -94,6 +94,36 @@
         self.assertTrue(build_position, out)
         self.assertLess(check_position, build_position, out)
 
+    def test_unknown_run_option(self):
+        status, out, err = assert_python_failure(
+            '-c', 'from distutils2.run import main; main()', 'run', 'build',
+            '--unknown', PYTHONPATH=self.get_pythonpath()
+        )
+        self.assertEqual(status, 1)
+        self.assertGreater(out, '')
+        self.assertEqual(err.splitlines()[-1],
+                        'error: option --unknown not recognized')
+
+    def test_unknown_command(self):
+        status, out, err = assert_python_failure(
+            '-c', 'from distutils2.run import main; main()', 'run',
+            'invalid_command', PYTHONPATH=self.get_pythonpath()
+        )
+        self.assertEqual(status, 1)
+        self.assertGreater(out, 1)
+        self.assertEqual(err.splitlines()[-1],
+            'error: Invalid command invalid_command')
+
+    def test_unknown_action(self):
+        status, out, err = assert_python_failure(
+            '-c', 'from distutils2.run import main; main()', 'invalid_action',
+            PYTHONPATH=self.get_pythonpath()
+        )
+        self.assertEqual(status, 1)
+        self.assertGreater(out, 1)
+        self.assertEqual(err.splitlines()[-1],
+            'error: Unrecognized action invalid_action')
+
         # TODO test that custom commands don't break --list-commands
 
 

-- 
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list