summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Paul <info@pierre-paul.com>2012-05-12 18:15:19 -0400
committerPierre Paul <info@pierre-paul.com>2012-05-12 18:15:19 -0400
commitab781d67700f6a0506f255ae9c9a121937a8698b (patch)
tree42808886bd02df3c2248acb5cb77d94499b8aef3
parent80b0aa42676621a920907bdf7bb1f3f5cc47ac12 (diff)
parentcf38a177968d063fd81c989770f137e16cecc17b (diff)
downloaddisutils2-ab781d67700f6a0506f255ae9c9a121937a8698b.tar.gz
Merge commit
-rw-r--r--distutils2/metadata.py4
-rw-r--r--distutils2/run.py17
-rw-r--r--distutils2/tests/fake_dists/python-pager-readme.rst65
-rw-r--r--distutils2/tests/test_command_register.py15
-rw-r--r--distutils2/tests/test_run.py32
5 files changed, 54 insertions, 79 deletions
diff --git a/distutils2/metadata.py b/distutils2/metadata.py
index a16b2be..7b66ba6 100644
--- a/distutils2/metadata.py
+++ b/distutils2/metadata.py
@@ -36,7 +36,7 @@ try:
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 @@ class Metadata(object):
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
index f845dbc..1729761 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -397,8 +397,9 @@ class Dispatcher(object):
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 @@ class Dispatcher(object):
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 @@ class Dispatcher(object):
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 @@ class Dispatcher(object):
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
index c01f53f..0000000
--- 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@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
index 7deb6e4..5fc8e99 100644
--- a/distutils2/tests/test_command_register.py
+++ b/distutils2/tests/test_command_register.py
@@ -10,7 +10,7 @@ except ImportError:
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 @@ class RegisterTestCase(support.TempdirManager,
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 @@ class RegisterTestCase(support.TempdirManager,
cmd.strict = True
inputs = Inputs('2', 'tarek', 'tarek@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
index 64df17f..a6e2c20 100644
--- a/distutils2/tests/test_run.py
+++ b/distutils2/tests/test_run.py
@@ -8,7 +8,7 @@ from distutils2 import install
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 @@ class RunTestCase(support.TempdirManager,
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