mirror of
https://github.com/python/cpython.git
synced 2025-09-13 12:17:24 +00:00
initial import of the packaging package in the standard library
This commit is contained in:
parent
566f8a646e
commit
1231a4e097
193 changed files with 30376 additions and 149 deletions
59
Lib/packaging/tests/pypi_test_server.py
Normal file
59
Lib/packaging/tests/pypi_test_server.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""Test PyPI Server implementation at testpypi.python.org, to use in tests.
|
||||
|
||||
This is a drop-in replacement for the mock pypi server for testing against a
|
||||
real pypi server hosted by python.org especially for testing against.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
PYPI_DEFAULT_STATIC_PATH = None
|
||||
|
||||
|
||||
def use_xmlrpc_server(*server_args, **server_kwargs):
|
||||
server_kwargs['serve_xmlrpc'] = True
|
||||
return use_pypi_server(*server_args, **server_kwargs)
|
||||
|
||||
|
||||
def use_http_server(*server_args, **server_kwargs):
|
||||
server_kwargs['serve_xmlrpc'] = False
|
||||
return use_pypi_server(*server_args, **server_kwargs)
|
||||
|
||||
|
||||
def use_pypi_server(*server_args, **server_kwargs):
|
||||
"""Decorator to make use of the PyPIServer for test methods,
|
||||
just when needed, and not for the entire duration of the testcase.
|
||||
"""
|
||||
def wrapper(func):
|
||||
def wrapped(*args, **kwargs):
|
||||
server = PyPIServer(*server_args, **server_kwargs)
|
||||
func(server=server, *args, **kwargs)
|
||||
return wrapped
|
||||
return wrapper
|
||||
|
||||
|
||||
class PyPIServerTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PyPIServerTestCase, self).setUp()
|
||||
self.pypi = PyPIServer()
|
||||
self.pypi.start()
|
||||
self.addCleanup(self.pypi.stop)
|
||||
|
||||
|
||||
class PyPIServer:
|
||||
"""Shim to access testpypi.python.org, for testing a real server."""
|
||||
|
||||
def __init__(self, test_static_path=None,
|
||||
static_filesystem_paths=["default"],
|
||||
static_uri_paths=["simple"], serve_xmlrpc=False):
|
||||
self.address = ('testpypi.python.org', '80')
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def full_address(self):
|
||||
return "http://%s:%s" % self.address
|
Loading…
Add table
Add a link
Reference in a new issue