summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_register.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-05-16 16:52:13 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-05-16 16:52:13 (GMT)
commit5af55c63607fb6bebfc95c57e6eda5db0c669b46 (patch)
tree13c4c08c3c60fbe5b79c1432145c1f0dc676070a /Lib/distutils/tests/test_register.py
parentafdfbc72fb58dd01200573728e603b3da246c6e6 (diff)
downloadcpython-5af55c63607fb6bebfc95c57e6eda5db0c669b46.zip
cpython-5af55c63607fb6bebfc95c57e6eda5db0c669b46.tar.gz
cpython-5af55c63607fb6bebfc95c57e6eda5db0c669b46.tar.bz2
Merged revisions 72681 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72681 | tarek.ziade | 2009-05-16 18:37:06 +0200 (Sat, 16 May 2009) | 1 line #6041: sdist and register now use the check command. No more duplicate code for metadata checking ........
Diffstat (limited to 'Lib/distutils/tests/test_register.py')
-rw-r--r--Lib/distutils/tests/test_register.py79
1 files changed, 73 insertions, 6 deletions
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py
index 46f7761..f486cf7 100644
--- a/Lib/distutils/tests/test_register.py
+++ b/Lib/distutils/tests/test_register.py
@@ -4,10 +4,14 @@ import os
import unittest
import getpass
import urllib
+import warnings
+
+from test.support import check_warnings
from distutils.command import register as register_module
from distutils.command.register import register
from distutils.core import Distribution
+from distutils.errors import DistutilsSetupError
from distutils.tests import support
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
@@ -59,7 +63,7 @@ class FakeOpener(object):
def read(self):
return 'xxx'
-class registerTestCase(PyPIRCCommandTestCase):
+class RegisterTestCase(PyPIRCCommandTestCase):
def setUp(self):
PyPIRCCommandTestCase.setUp(self)
@@ -76,10 +80,11 @@ class registerTestCase(PyPIRCCommandTestCase):
urllib.request.build_opener = self.old_opener
PyPIRCCommandTestCase.tearDown(self)
- def _get_cmd(self):
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
+ def _get_cmd(self, metadata=None):
+ if metadata is None:
+ metadata = {'url': 'xxx', 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx', 'version': 'xxx'}
pkg_info, dist = self.create_dist(**metadata)
return register(dist)
@@ -184,8 +189,70 @@ class registerTestCase(PyPIRCCommandTestCase):
self.assertEquals(headers['Content-length'], '290')
self.assert_((b'tarek') in req.data)
+ def test_strict(self):
+ # testing the script option
+ # when on, the register command stops if
+ # the metadata is incomplete or if
+ # long_description is not reSt compliant
+
+ # empty metadata
+ cmd = self._get_cmd({})
+ cmd.ensure_finalized()
+ 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',
+ 'author_email': 'xxx',
+ 'name': 'xxx', 'version': 'xxx',
+ 'long_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'
+ cmd = self._get_cmd(metadata)
+ cmd.ensure_finalized()
+ cmd.strict = 1
+ inputs = RawInputs('1', 'tarek', 'y')
+ register_module.raw_input = inputs.__call__
+ # let's run the command
+ try:
+ cmd.run()
+ finally:
+ del register_module.raw_input
+
+ # strict is not by default
+ cmd = self._get_cmd()
+ cmd.ensure_finalized()
+ inputs = RawInputs('1', 'tarek', 'y')
+ register_module.raw_input = inputs.__call__
+ # let's run the command
+ try:
+ cmd.run()
+ finally:
+ del register_module.raw_input
+
+ def test_check_metadata_deprecated(self):
+ # makes sure make_metadata is deprecated
+ cmd = self._get_cmd()
+ with check_warnings() as w:
+ warnings.simplefilter("always")
+ cmd.check_metadata()
+ self.assertEquals(len(w.warnings), 1)
+
def test_suite():
- return unittest.makeSuite(registerTestCase)
+ return unittest.makeSuite(RegisterTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")