mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Make a number of small changes to ease the backport to distutils2
This commit is contained in:
parent
41479450ec
commit
229011d949
19 changed files with 104 additions and 125 deletions
|
@ -1,6 +1,5 @@
|
|||
"""Tests for packaging.command.upload_docs."""
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import zipfile
|
||||
try:
|
||||
|
@ -52,34 +51,27 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
|
||||
def test_default_uploaddir(self):
|
||||
sandbox = self.mkdtemp()
|
||||
previous = os.getcwd()
|
||||
os.chdir(sandbox)
|
||||
try:
|
||||
os.mkdir("build")
|
||||
self.prepare_sample_dir("build")
|
||||
self.cmd.ensure_finalized()
|
||||
self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
os.mkdir("build")
|
||||
self.prepare_sample_dir("build")
|
||||
self.cmd.ensure_finalized()
|
||||
self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
|
||||
|
||||
def test_default_uploaddir_looks_for_doc_also(self):
|
||||
sandbox = self.mkdtemp()
|
||||
previous = os.getcwd()
|
||||
os.chdir(sandbox)
|
||||
try:
|
||||
os.mkdir("build")
|
||||
self.prepare_sample_dir("build")
|
||||
os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
|
||||
self.cmd.ensure_finalized()
|
||||
self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
os.mkdir("build")
|
||||
self.prepare_sample_dir("build")
|
||||
os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
|
||||
self.cmd.ensure_finalized()
|
||||
self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
|
||||
|
||||
def prepare_sample_dir(self, sample_dir=None):
|
||||
if sample_dir is None:
|
||||
sample_dir = self.mkdtemp()
|
||||
os.mkdir(os.path.join(sample_dir, "docs"))
|
||||
self.write_file(os.path.join(sample_dir, "docs", "index.html"), "Ce mortel ennui")
|
||||
self.write_file(os.path.join(sample_dir, "docs", "index.html"),
|
||||
"Ce mortel ennui")
|
||||
self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la")
|
||||
return sample_dir
|
||||
|
||||
|
@ -108,9 +100,8 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
self.assertTrue(handler.headers['content-type']
|
||||
.startswith('multipart/form-data;'))
|
||||
|
||||
action, name, version, content =\
|
||||
request_data.split("----------------GHSKFJDLGDS7543FJKLFHRE75642756743254".encode())[1:5]
|
||||
|
||||
action, name, version, content = request_data.split(
|
||||
b'----------------GHSKFJDLGDS7543FJKLFHRE75642756743254')[1:5]
|
||||
|
||||
# check that we picked the right chunks
|
||||
self.assertIn(b'name=":action"', action)
|
||||
|
@ -126,27 +117,25 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
|
||||
@unittest.skipIf(_ssl is None, 'Needs SSL support')
|
||||
def test_https_connection(self):
|
||||
https_called = False
|
||||
|
||||
orig_https = upload_docs_mod.http.client.HTTPSConnection
|
||||
self.https_called = False
|
||||
self.addCleanup(
|
||||
setattr, upload_docs_mod.http.client, 'HTTPSConnection',
|
||||
upload_docs_mod.http.client.HTTPSConnection)
|
||||
|
||||
def https_conn_wrapper(*args):
|
||||
nonlocal https_called
|
||||
https_called = True
|
||||
self.https_called = True
|
||||
# the testing server is http
|
||||
return upload_docs_mod.http.client.HTTPConnection(*args)
|
||||
|
||||
upload_docs_mod.http.client.HTTPSConnection = https_conn_wrapper
|
||||
try:
|
||||
self.prepare_command()
|
||||
self.cmd.run()
|
||||
self.assertFalse(https_called)
|
||||
|
||||
self.cmd.repository = self.cmd.repository.replace("http", "https")
|
||||
self.cmd.run()
|
||||
self.assertTrue(https_called)
|
||||
finally:
|
||||
upload_docs_mod.http.client.HTTPSConnection = orig_https
|
||||
self.prepare_command()
|
||||
self.cmd.run()
|
||||
self.assertFalse(self.https_called)
|
||||
|
||||
self.cmd.repository = self.cmd.repository.replace("http", "https")
|
||||
self.cmd.run()
|
||||
self.assertTrue(self.https_called)
|
||||
|
||||
def test_handling_response(self):
|
||||
self.pypi.default_response_status = '403 Forbidden'
|
||||
|
@ -155,7 +144,8 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
self.assertIn('Upload failed (403): Forbidden', self.get_logs()[-1])
|
||||
|
||||
self.pypi.default_response_status = '301 Moved Permanently'
|
||||
self.pypi.default_response_headers.append(("Location", "brand_new_location"))
|
||||
self.pypi.default_response_headers.append(
|
||||
("Location", "brand_new_location"))
|
||||
self.cmd.run()
|
||||
self.assertIn('brand_new_location', self.get_logs()[-1])
|
||||
|
||||
|
@ -185,6 +175,7 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
self.assertTrue(record, "should report the response")
|
||||
self.assertIn(self.pypi.default_response_data, record)
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.makeSuite(UploadDocsTestCase)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue