[Python-checkins] distutils2: fixed all doctutils tests
tarek.ziade
python-checkins at python.org
Sat Apr 24 13:36:55 CEST 2010
tarek.ziade pushed 69952f1f6af5 to distutils2:
http://hg.python.org/distutils2/rev/69952f1f6af5
changeset: 122:69952f1f6af5
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sat Apr 24 13:36:47 2010 +0200
summary: fixed all doctutils tests
files: src/distutils2/command/check.py, src/distutils2/tests/test_check.py, src/distutils2/tests/test_register.py
diff --git a/src/distutils2/command/check.py b/src/distutils2/command/check.py
--- a/src/distutils2/command/check.py
+++ b/src/distutils2/command/check.py
@@ -25,14 +25,14 @@
self.restructuredtext = 0
self.metadata = 1
self.strict = 0
- self._warnings = 0
+ self._warnings = []
def finalize_options(self):
pass
def warn(self, msg):
"""Counts the number of warnings that occurs."""
- self._warnings += 1
+ self._warnings.append(msg)
return Command.warn(self, msg)
def run(self):
@@ -48,8 +48,9 @@
# let's raise an error in strict mode, if we have at least
# one warning
- if self.strict and self._warnings > 0:
- raise DistutilsSetupError('Please correct your package.')
+ if self.strict and len(self._warnings) > 0:
+ msg = '\n'.join(self._warnings)
+ raise DistutilsSetupError(msg)
def check_metadata(self):
"""Ensures that all required elements of meta-data are supplied.
diff --git a/src/distutils2/tests/test_check.py b/src/distutils2/tests/test_check.py
--- a/src/distutils2/tests/test_check.py
+++ b/src/distutils2/tests/test_check.py
@@ -27,7 +27,7 @@
# by default, check is checking the metadata
# should have some warnings
cmd = self._run()
- self.assert_(cmd._warnings > 0)
+ self.assert_(len(cmd._warnings) > 0)
# now let's add the required fields
# and run it again, to make sure we don't get
@@ -37,7 +37,7 @@
'name': 'xxx', 'version': 'xxx'
}
cmd = self._run(metadata)
- self.assertEquals(cmd._warnings, 0)
+ self.assertEquals(len(cmd._warnings), 0)
# now with the strict mode, we should
# get an error if there are missing metadata
@@ -45,34 +45,35 @@
# and of course, no error when all metadata are present
cmd = self._run(metadata, strict=1)
- self.assertEquals(cmd._warnings, 0)
+ self.assertEquals(len(cmd._warnings), 0)
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(long_description=broken_rest)
+ pkg_info, dist = self.create_dist(description=broken_rest)
cmd = check(dist)
cmd.check_restructuredtext()
- self.assertEquals(cmd._warnings, 1)
+ self.assertEquals(len(cmd._warnings), 1)
# let's see if we have an error with strict=1
- metadata = {'url': 'xxx', 'author': 'xxx',
+ metadata = {'home_page': 'xxx', 'author': 'xxx',
'author_email': 'xxx',
'name': 'xxx', 'version': 'xxx',
- 'long_description': broken_rest}
+ 'description': broken_rest}
+
self.assertRaises(DistutilsSetupError, self._run, metadata,
**{'strict': 1, 'restructuredtext': 1})
# and non-broken rest
- metadata['long_description'] = 'title\n=====\n\ntest'
+ metadata['description'] = 'title\n=====\n\ntest'
cmd = self._run(metadata, strict=1, restructuredtext=1)
- self.assertEquals(cmd._warnings, 0)
+ self.assertEquals(len(cmd._warnings), 0)
def test_check_all(self):
- metadata = {'url': 'xxx', 'author': 'xxx'}
+ metadata = {'home_page': 'xxx', 'author': 'xxx'}
self.assertRaises(DistutilsSetupError, self._run,
{}, **{'strict': 1,
'restructuredtext': 1})
diff --git a/src/distutils2/tests/test_register.py b/src/distutils2/tests/test_register.py
--- a/src/distutils2/tests/test_register.py
+++ b/src/distutils2/tests/test_register.py
@@ -7,6 +7,12 @@
import urllib2
import warnings
+try:
+ import docutils
+ DOCUTILS_SUPPORT = True
+except ImportError:
+ DOCUTILS_SUPPORT = False
+
from distutils2.command import register as register_module
from distutils2.command.register import register
from distutils2.core import Distribution
@@ -186,6 +192,7 @@
self.assertEquals(headers['Content-length'], '290')
self.assertTrue('tarek' in req.data)
+ @unittest2.skipUnless(DOCUTILS_SUPPORT, 'needs docutils')
def test_strict(self):
# testing the script option
# when on, the register command stops if
@@ -198,26 +205,20 @@
cmd.strict = 1
self.assertRaises(DistutilsSetupError, cmd.run)
- # we don't test the reSt feature if docutils
- # is not installed
- try:
- import docutils
- except ImportError:
- return
-
# metadata are OK but long_description is broken
- metadata = {'url': 'xxx', 'author': 'xxx',
+ metadata = {'home_page': 'xxx', 'author': 'xxx',
'author_email': u'éxéxé',
'name': 'xxx', 'version': 'xxx',
- 'long_description': 'title\n==\n\ntext'}
+ 'description': 'title\n==\n\ntext'}
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
cmd.strict = 1
+
self.assertRaises(DistutilsSetupError, cmd.run)
# now something that works
- metadata['long_description'] = 'title\n=====\n\ntext'
+ metadata['description'] = 'title\n=====\n\ntext'
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
cmd.strict = 1
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list