[Python-checkins] distutils2: show_response option enabled

tarek.ziade python-checkins at python.org
Sun Jul 4 11:48:39 CEST 2010


tarek.ziade pushed 03bc7496c3b2 to distutils2:

http://hg.python.org/distutils2/rev/03bc7496c3b2
changeset:   278:03bc7496c3b2
user:        Konrad Delong <konryd at gmail.com>
date:        Tue Jun 01 17:09:32 2010 +0200
summary:     show_response option enabled
files:       src/distutils2/command/upload_docs.py, src/distutils2/tests/test_upload_docs.py

diff --git a/src/distutils2/command/upload_docs.py b/src/distutils2/command/upload_docs.py
--- a/src/distutils2/command/upload_docs.py
+++ b/src/distutils2/command/upload_docs.py
@@ -50,10 +50,8 @@
 class upload_docs(PyPIRCCommand):
 
     user_options = [
-        #('repository=', 'r',
-         #"url of repository [default: %s]" % upload.DEFAULT_REPOSITORY),
-        #('show-response', None,
-         #'display full response text from server'),
+        ('repository=', 'r', "url of repository [default: %s]" % upload.DEFAULT_REPOSITORY),
+        ('show-response', None, 'display full response text from server'),
         ('upload-dir=', None, 'directory to upload'),
         ]
 
@@ -132,3 +130,6 @@
         else:
             self.announce('Upload failed (%s): %s' % (r.status, r.reason),
                           log.ERROR)
+
+        if self.show_response:
+            print "\n".join(['-'*75, r.read(), '-'*75])
diff --git a/src/distutils2/tests/test_upload_docs.py b/src/distutils2/tests/test_upload_docs.py
--- a/src/distutils2/tests/test_upload_docs.py
+++ b/src/distutils2/tests/test_upload_docs.py
@@ -1,6 +1,6 @@
 """Tests for distutils.command.upload_docs."""
 # -*- encoding: utf8 -*-
-import httplib, os, os.path, shutil, tempfile, unittest2, zipfile
+import httplib, os, os.path, shutil, sys, tempfile, unittest2, zipfile
 from cStringIO import StringIO
 
 from distutils2.command import upload_docs as upload_docs_mod
@@ -174,6 +174,22 @@
         shutil.rmtree(os.path.join(self.cmd.upload_dir))
         self.assertRaises(DistutilsOptionError, self.cmd.ensure_finalized)
 
+    def test_show_response(self):
+        orig_stdout = sys.stdout
+        write_args = []
+        class MockStdIn(object):
+            def write(self, arg):
+                write_args.append(arg)
+        sys.stdout = MockStdIn()
+        try:
+            self.prepare_command()
+            self.cmd.show_response = True
+            self.cmd.run()
+        finally:
+            sys.stdout = orig_stdout
+        self.assertTrue(write_args[0], "should report the response")
+        self.assertIn("\n".join(self.pypi.default_response_data), write_args[0])
+
 def test_suite():
     return unittest2.makeSuite(UploadDocsTestCase)
 

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


More information about the Python-checkins mailing list