diff options
| author | Konrad Delong <konryd@gmail.com> | 2010-08-16 17:11:19 +0200 |
|---|---|---|
| committer | Konrad Delong <konryd@gmail.com> | 2010-08-16 17:11:19 +0200 |
| commit | e0660e14ea322e6f5166e332f14f201d4be73f02 (patch) | |
| tree | 5cde77c2cdc6317ebc2f28f7c38bbccddd708655 /src | |
| parent | b47bd1c023f37a011958666b2136188820428bce (diff) | |
| download | disutils2-e0660e14ea322e6f5166e332f14f201d4be73f02.tar.gz | |
added additional check for the check command
Diffstat (limited to 'src')
| -rw-r--r-- | src/distutils2/command/check.py | 45 | ||||
| -rw-r--r-- | src/distutils2/command/register.py | 4 | ||||
| -rw-r--r-- | src/distutils2/tests/support.py | 23 | ||||
| -rw-r--r-- | src/distutils2/tests/test_check.py | 30 | ||||
| -rw-r--r-- | src/distutils2/tests/test_dist.py | 43 |
5 files changed, 80 insertions, 65 deletions
diff --git a/src/distutils2/command/check.py b/src/distutils2/command/check.py index b3175e7..cfb6694 100644 --- a/src/distutils2/command/check.py +++ b/src/distutils2/command/check.py @@ -6,23 +6,23 @@ __revision__ = "$Id: check.py 75266 2009-10-05 22:32:48Z andrew.kuchling $" from distutils2.core import Command from distutils2.errors import DistutilsSetupError +from distutils2.util import resolve_name class check(Command): """This command checks the metadata of the package. """ description = ("perform some checks on the package") user_options = [('metadata', 'm', 'Verify metadata'), - ('restructuredtext', 'r', - ('Checks if long string metadata syntax ' - 'is reStructuredText-compliant')), + ('all', 'a', + ('runs extended set of checks')), ('strict', 's', 'Will exit with an error if a check fails')] - boolean_options = ['metadata', 'restructuredtext', 'strict'] + boolean_options = ['metadata', 'all', 'strict'] def initialize_options(self): """Sets default values for options.""" - self.restructuredtext = 0 + self.all = 0 self.metadata = 1 self.strict = 0 self._warnings = [] @@ -40,11 +40,9 @@ class check(Command): # perform the various tests if self.metadata: self.check_metadata() - if self.restructuredtext: - if self.distribution.metadata.docutils_support: - self.check_restructuredtext() - elif self.strict: - raise DistutilsSetupError('The docutils package is needed.') + if self.all: + self.check_restructuredtext() + self.check_hooks_resolvable() # let's raise an error in strict mode, if we have at least # one warning @@ -67,11 +65,24 @@ class check(Command): def check_restructuredtext(self): """Checks if the long string fields are reST-compliant.""" missing, warnings = self.distribution.metadata.check() - for warning in warnings: - line = warning[-1].get('line') - if line is None: - warning = warning[1] - else: - warning = '%s (line %s)' % (warning[1], line) - self.warn(warning) + if self.distribution.metadata.docutils_support: + for warning in warnings: + line = warning[-1].get('line') + if line is None: + warning = warning[1] + else: + warning = '%s (line %s)' % (warning[1], line) + self.warn(warning) + elif self.strict: + raise DistutilsSetupError('The docutils package is needed.') + def check_hooks_resolvable(self): + for options in self.distribution.command_options.values(): + for hook_kind in ("pre_hook", "post_hook"): + if hook_kind not in options: + break + for hook_name in options[hook_kind][1].values(): + try: + resolve_name(hook_name) + except ImportError: + self.warn("Name '%s' cannot be resolved." % hook_name) diff --git a/src/distutils2/command/register.py b/src/distutils2/command/register.py index 3f27272..bb97936 100644 --- a/src/distutils2/command/register.py +++ b/src/distutils2/command/register.py @@ -50,7 +50,7 @@ class register(Command): self.realm = DEFAULT_REALM # setting options for the `check` subcommand check_options = {'strict': ('register', self.strict), - 'restructuredtext': ('register', 1)} + 'all': ('register', 1)} self.distribution.command_options['check'] = check_options def run(self): @@ -74,7 +74,7 @@ class register(Command): check = self.distribution.get_command_obj('check') check.ensure_finalized() check.strict = self.strict - check.restructuredtext = 1 + check.all = 1 check.run() def _set_config(self): diff --git a/src/distutils2/tests/support.py b/src/distutils2/tests/support.py index 1ff2217..a365548 100644 --- a/src/distutils2/tests/support.py +++ b/src/distutils2/tests/support.py @@ -35,6 +35,7 @@ import warnings from copy import deepcopy from distutils2 import log +from distutils2.dist import Distribution from distutils2.log import DEBUG, INFO, WARN, ERROR, FATAL if sys.version_info >= (3, 2): @@ -210,3 +211,25 @@ class DummyCommand(object): def ensure_finalized(self): pass + + +class TestDistribution(Distribution): + """Distribution subclasses that avoids the default search for + configuration files. + + The ._config_files attribute must be set before + .parse_config_files() is called. + """ + + def find_config_files(self): + return self._config_files + + +def create_distribution(configfiles=()): + """Prepares a distribution with given config files parsed.""" + d = TestDistribution() + d._config_files = configfiles + d.parse_config_files() + d.parse_command_line() + return d + diff --git a/src/distutils2/tests/test_check.py b/src/distutils2/tests/test_check.py index e6242cf..02e2484 100644 --- a/src/distutils2/tests/test_check.py +++ b/src/distutils2/tests/test_check.py @@ -47,9 +47,8 @@ class CheckTestCase(support.LoggingCatcher, cmd = self._run(metadata, strict=1) self.assertEqual(len(cmd._warnings), 0) + @unittest.skipUnless(_HAS_DOCUTILS, "requires docutils") def test_check_restructuredtext(self): - if not _HAS_DOCUTILS: # won't test without docutils - return # let's see if it detects broken rest in long_description broken_rest = 'title\n===\n\ntest' pkg_info, dist = self.create_dist(description=broken_rest) @@ -57,18 +56,9 @@ class CheckTestCase(support.LoggingCatcher, cmd.check_restructuredtext() self.assertEqual(len(cmd._warnings), 1) - # let's see if we have an error with strict=1 - metadata = {'home_page': 'xxx', 'author': 'xxx', - 'author_email': 'xxx', - 'name': 'xxx', 'version': 'xxx', - 'description': broken_rest} - - self.assertRaises(DistutilsSetupError, self._run, metadata, - **{'strict': 1, 'restructuredtext': 1}) - - # and non-broken rest - metadata['description'] = 'title\n=====\n\ntest' - cmd = self._run(metadata, strict=1, restructuredtext=1) + pkg_info, dist = self.create_dist(description='title\n=====\n\ntest') + cmd = check(dist) + cmd.check_restructuredtext() self.assertEqual(len(cmd._warnings), 0) def test_check_all(self): @@ -76,7 +66,17 @@ class CheckTestCase(support.LoggingCatcher, metadata = {'home_page': 'xxx', 'author': 'xxx'} self.assertRaises(DistutilsSetupError, self._run, {}, **{'strict': 1, - 'restructuredtext': 1}) + 'all': 1}) + + def test_check_hooks(self): + pkg_info, dist = self.create_dist() + dist.command_options['install'] = { + 'pre_hook': ('file', {"a": 'some.nonextistant.hook.ghrrraarrhll'}), + } + cmd = check(dist) + cmd.check_hooks_resolvable() + self.assertEqual(len(cmd._warnings), 1) + def test_suite(): return unittest.makeSuite(CheckTestCase) diff --git a/src/distutils2/tests/test_dist.py b/src/distutils2/tests/test_dist.py index fe28b6b..77d32fa 100644 --- a/src/distutils2/tests/test_dist.py +++ b/src/distutils2/tests/test_dist.py @@ -13,7 +13,7 @@ from distutils2.command.cmd import Command from distutils2.errors import DistutilsModuleError, DistutilsOptionError from distutils2.tests import TESTFN, captured_stdout from distutils2.tests import support -from distutils2.tests.support import unittest +from distutils2.tests.support import unittest, create_distribution class test_dist(Command): @@ -30,18 +30,6 @@ class test_dist(Command): pass -class TestDistribution(Distribution): - """Distribution subclasses that avoids the default search for - configuration files. - - The ._config_files attribute must be set before - .parse_config_files() is called. - """ - - def find_config_files(self): - return self._config_files - - class DistributionTestCase(support.TempdirManager, support.LoggingCatcher, support.WarningsCatcher, @@ -58,13 +46,6 @@ class DistributionTestCase(support.TempdirManager, sys.argv[:] = self.argv[1] super(DistributionTestCase, self).tearDown() - def create_distribution(self, configfiles=()): - d = TestDistribution() - d._config_files = configfiles - d.parse_config_files() - d.parse_command_line() - return d - def test_debug_mode(self): f = open(TESTFN, "w") try: @@ -76,18 +57,18 @@ class DistributionTestCase(support.TempdirManager, files = [TESTFN] sys.argv.append("build") - __, stdout = captured_stdout(self.create_distribution, files) + __, stdout = captured_stdout(create_distribution, files) self.assertEqual(stdout, '') distutils2.dist.DEBUG = True try: - __, stdout = captured_stdout(self.create_distribution, files) + __, stdout = captured_stdout(create_distribution, files) self.assertEqual(stdout, '') finally: distutils2.dist.DEBUG = False def test_command_packages_unspecified(self): sys.argv.append("build") - d = self.create_distribution() + d = create_distribution() self.assertEqual(d.get_command_packages(), ["distutils2.command"]) def test_command_packages_cmdline(self): @@ -97,7 +78,7 @@ class DistributionTestCase(support.TempdirManager, "test_dist", "-Ssometext", ]) - d = self.create_distribution() + d = create_distribution() # let's actually try to load our test command: self.assertEqual(d.get_command_packages(), ["distutils2.command", "foo.bar", "distutils2.tests"]) @@ -112,20 +93,20 @@ class DistributionTestCase(support.TempdirManager, print >> f, "[global]" print >> f, "command_packages = foo.bar, splat" f.close() - d = self.create_distribution([TESTFN]) + d = create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils2.command", "foo.bar", "splat"]) # ensure command line overrides config: sys.argv[1:] = ["--command-packages", "spork", "build"] - d = self.create_distribution([TESTFN]) + d = create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils2.command", "spork"]) # Setting --command-packages to '' should cause the default to # be used even if a config file specified something else: sys.argv[1:] = ["--command-packages", "", "build"] - d = self.create_distribution([TESTFN]) + d = create_distribution([TESTFN]) self.assertEqual(d.get_command_packages(), ["distutils2.command"]) finally: @@ -276,7 +257,7 @@ class DistributionTestCase(support.TempdirManager, sys.argv.extend(["--command-packages", "distutils2.tests", "test_dist"]) - dist = self.create_distribution(config_files) + dist = create_distribution(config_files) cmd = dist.get_command_obj("test_dist") self.assertEqual(cmd.pre_hook, {"a": 'type', "b": 'type'}) @@ -306,7 +287,7 @@ class DistributionTestCase(support.TempdirManager, "distutils2.tests", "test_dist"]) - d = self.create_distribution([config_file]) + d = create_distribution([config_file]) cmd = d.get_command_obj("test_dist") # prepare the call recorders @@ -339,7 +320,7 @@ class DistributionTestCase(support.TempdirManager, "distutils2.tests", "test_dist"]) - d = self.create_distribution([config_file]) + d = create_distribution([config_file]) cmd = d.get_command_obj("test_dist") cmd.ensure_finalized() @@ -357,7 +338,7 @@ class DistributionTestCase(support.TempdirManager, "distutils2.tests", "test_dist"]) - d = self.create_distribution([config_file]) + d = create_distribution([config_file]) cmd = d.get_command_obj("test_dist") cmd.ensure_finalized() |
