Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
distutils.tests.test_register.RegisterTestCase Class Reference
Inheritance diagram for distutils.tests.test_register.RegisterTestCase:
Inheritance graph
[legend]
Collaboration diagram for distutils.tests.test_register.RegisterTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def test_create_pypirc
def test_password_not_in_file
def test_registering
def test_password_reset
def test_strict
def test_check_metadata_deprecated
def test_server_registration
def test_server_empty_registration
def mkdtemp
def write_file
def create_dist
def get_logs
def clear_logs

Public Attributes

 old_opener
 conn
 tmp_dir
 rc
 dist
 old_threshold
 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
struct _typeobjectob_type
struct _typeobjectob_type
 threshold
 logs
 old_environ

Private Member Functions

def _get_cmd

Private Attributes

 _old_getpass

Detailed Description

Definition at line 66 of file test_register.py.


Member Function Documentation

def distutils.tests.test_register.RegisterTestCase._get_cmd (   self,
  metadata = None 
) [private]

Definition at line 83 of file test_register.py.

00083 
00084     def _get_cmd(self, metadata=None):
00085         if metadata is None:
00086             metadata = {'url': 'xxx', 'author': 'xxx',
00087                         'author_email': 'xxx',
00088                         'name': 'xxx', 'version': 'xxx'}
00089         pkg_info, dist = self.create_dist(**metadata)
00090         return register(dist)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file support.py.

00045 
00046     def clear_logs(self):
00047         self.logs = []
00048 

Here is the caller graph for this function:

def distutils.tests.support.TempdirManager.create_dist (   self,
  pkg_name = 'foo',
  kw 
) [inherited]
Will generate a test environment.

This function creates:
 - a Distribution instance using keywords
 - a temporary directory with a package structure

It returns the package directory and the distribution
instance.

Definition at line 92 of file support.py.

00092 
00093     def create_dist(self, pkg_name='foo', **kw):
00094         """Will generate a test environment.
00095 
00096         This function creates:
00097          - a Distribution instance using keywords
00098          - a temporary directory with a package structure
00099 
00100         It returns the package directory and the distribution
00101         instance.
00102         """
00103         tmp_dir = self.mkdtemp()
00104         pkg_dir = os.path.join(tmp_dir, pkg_name)
00105         os.mkdir(pkg_dir)
00106         dist = Distribution(attrs=kw)
00107 
00108         return pkg_dir, dist
00109 

Here is the call graph for this function:

Here is the caller graph for this function:

def distutils.tests.support.LoggingSilencer.get_logs (   self,
  levels 
) [inherited]

Definition at line 37 of file support.py.

00037 
00038     def get_logs(self, *levels):
00039         def _format(msg, args):
00040             if len(args) == 0:
00041                 return msg
00042             return msg % args
00043         return [_format(msg, args) for level, msg, args
00044                 in self.logs if level in levels]

Here is the call graph for this function:

Here is the caller graph for this function:

Create a temporary directory that will be cleaned up.

Returns the path of the directory.

Definition at line 69 of file support.py.

00069 
00070     def mkdtemp(self):
00071         """Create a temporary directory that will be cleaned up.
00072 
00073         Returns the path of the directory.
00074         """
00075         d = tempfile.mkdtemp()
00076         self.tempdirs.append(d)
00077         return d

Here is the call graph for this function:

Here is the caller graph for this function:

Patches the environment.

Reimplemented from distutils.tests.test_config.PyPIRCCommandTestCase.

Definition at line 68 of file test_register.py.

00068 
00069     def setUp(self):
00070         super(RegisterTestCase, self).setUp()
00071         # patching the password prompt
00072         self._old_getpass = getpass.getpass
00073         def _getpass(prompt):
00074             return 'password'
00075         getpass.getpass = _getpass
00076         self.old_opener = urllib.request.build_opener
00077         self.conn = urllib.request.build_opener = FakeOpener()

Here is the caller graph for this function:

Removes the patch.

Reimplemented from distutils.tests.test_config.PyPIRCCommandTestCase.

Definition at line 78 of file test_register.py.

00078 
00079     def tearDown(self):
00080         getpass.getpass = self._old_getpass
00081         urllib.request.build_opener = self.old_opener
00082         super(RegisterTestCase, self).tearDown()

Here is the caller graph for this function:

Definition at line 250 of file test_register.py.

00250 
00251     def test_check_metadata_deprecated(self):
00252         # makes sure make_metadata is deprecated
00253         cmd = self._get_cmd()
00254         with check_warnings() as w:
00255             warnings.simplefilter("always")
00256             cmd.check_metadata()
00257             self.assertEqual(len(w.warnings), 1)

Here is the call graph for this function:

Definition at line 91 of file test_register.py.

00091 
00092     def test_create_pypirc(self):
00093         # this test makes sure a .pypirc file
00094         # is created when requested.
00095 
00096         # let's create a register instance
00097         cmd = self._get_cmd()
00098 
00099         # we shouldn't have a .pypirc file yet
00100         self.assertTrue(not os.path.exists(self.rc))
00101 
00102         # patching input and getpass.getpass
00103         # so register gets happy
00104         #
00105         # Here's what we are faking :
00106         # use your existing login (choice 1.)
00107         # Username : 'tarek'
00108         # Password : 'password'
00109         # Save your login (y/N)? : 'y'
00110         inputs = Inputs('1', 'tarek', 'y')
00111         register_module.input = inputs.__call__
00112         # let's run the command
00113         try:
00114             cmd.run()
00115         finally:
00116             del register_module.input
00117 
00118         # we should have a brand new .pypirc file
00119         self.assertTrue(os.path.exists(self.rc))
00120 
00121         # with the content similar to WANTED_PYPIRC
00122         f = open(self.rc)
00123         try:
00124             content = f.read()
00125             self.assertEqual(content, WANTED_PYPIRC)
00126         finally:
00127             f.close()
00128 
00129         # now let's make sure the .pypirc file generated
00130         # really works : we shouldn't be asked anything
00131         # if we run the command again
00132         def _no_way(prompt=''):
00133             raise AssertionError(prompt)
00134         register_module.input = _no_way
00135 
00136         cmd.show_response = 1
00137         cmd.run()
00138 
00139         # let's see what the server received : we should
00140         # have 2 similar requests
00141         self.assertEqual(len(self.conn.reqs), 2)
00142         req1 = dict(self.conn.reqs[0].headers)
00143         req2 = dict(self.conn.reqs[1].headers)
00144 
00145         self.assertEqual(req1['Content-length'], '1374')
00146         self.assertEqual(req2['Content-length'], '1374')
00147         self.assertTrue((b'xxx') in self.conn.reqs[1].data)

Here is the call graph for this function:

Definition at line 148 of file test_register.py.

00148 
00149     def test_password_not_in_file(self):
00150 
00151         self.write_file(self.rc, PYPIRC_NOPASSWORD)
00152         cmd = self._get_cmd()
00153         cmd._set_config()
00154         cmd.finalize_options()
00155         cmd.send_metadata()
00156 
00157         # dist.password should be set
00158         # therefore used afterwards by other commands
00159         self.assertEqual(cmd.distribution.password, 'password')

Here is the call graph for this function:

Definition at line 178 of file test_register.py.

00178 
00179     def test_password_reset(self):
00180         # this test runs choice 3
00181         cmd = self._get_cmd()
00182         inputs = Inputs('3', 'tarek@ziade.org')
00183         register_module.input = inputs.__call__
00184         try:
00185             # let's run the command
00186             cmd.run()
00187         finally:
00188             del register_module.input
00189 
00190         # we should have send a request
00191         self.assertEqual(len(self.conn.reqs), 1)
00192         req = self.conn.reqs[0]
00193         headers = dict(req.headers)
00194         self.assertEqual(headers['Content-length'], '290')
00195         self.assertTrue((b'tarek') in req.data)

Here is the call graph for this function:

Definition at line 160 of file test_register.py.

00160 
00161     def test_registering(self):
00162         # this test runs choice 2
00163         cmd = self._get_cmd()
00164         inputs = Inputs('2', 'tarek', 'tarek@ziade.org')
00165         register_module.input = inputs.__call__
00166         try:
00167             # let's run the command
00168             cmd.run()
00169         finally:
00170             del register_module.input
00171 
00172         # we should have send a request
00173         self.assertEqual(len(self.conn.reqs), 1)
00174         req = self.conn.reqs[0]
00175         headers = dict(req.headers)
00176         self.assertEqual(headers['Content-length'], '608')
00177         self.assertTrue((b'tarek') in req.data)

Here is the call graph for this function:

Definition at line 103 of file test_config.py.

00103 
00104     def test_server_empty_registration(self):
00105         cmd = self._cmd(self.dist)
00106         rc = cmd._get_rc_file()
00107         self.assertTrue(not os.path.exists(rc))
00108         cmd._store_pypirc('tarek', 'xxx')
00109         self.assertTrue(os.path.exists(rc))
00110         f = open(rc)
00111         try:
00112             content = f.read()
00113             self.assertEqual(content, WANTED)
00114         finally:
00115             f.close()

Here is the call graph for this function:

Definition at line 78 of file test_config.py.

00078 
00079     def test_server_registration(self):
00080         # This test makes sure PyPIRCCommand knows how to:
00081         # 1. handle several sections in .pypirc
00082         # 2. handle the old format
00083 
00084         # new format
00085         self.write_file(self.rc, PYPIRC)
00086         cmd = self._cmd(self.dist)
00087         config = cmd._read_pypirc()
00088 
00089         config = list(sorted(config.items()))
00090         waited = [('password', 'secret'), ('realm', 'pypi'),
00091                   ('repository', 'http://pypi.python.org/pypi'),
00092                   ('server', 'server1'), ('username', 'me')]
00093         self.assertEqual(config, waited)
00094 
00095         # old format
00096         self.write_file(self.rc, PYPIRC_OLD)
00097         config = cmd._read_pypirc()
00098         config = list(sorted(config.items()))
00099         waited = [('password', 'secret'), ('realm', 'pypi'),
00100                   ('repository', 'http://pypi.python.org/pypi'),
00101                   ('server', 'server-login'), ('username', 'tarek')]
00102         self.assertEqual(config, waited)

Here is the call graph for this function:

Definition at line 196 of file test_register.py.

00196 
00197     def test_strict(self):
00198         # testing the script option
00199         # when on, the register command stops if
00200         # the metadata is incomplete or if
00201         # long_description is not reSt compliant
00202 
00203         # empty metadata
00204         cmd = self._get_cmd({})
00205         cmd.ensure_finalized()
00206         cmd.strict = 1
00207         self.assertRaises(DistutilsSetupError, cmd.run)
00208 
00209         # we don't test the reSt feature if docutils
00210         # is not installed
00211         try:
00212             import docutils
00213         except ImportError:
00214             return
00215 
00216         # metadata are OK but long_description is broken
00217         metadata = {'url': 'xxx', 'author': 'xxx',
00218                     'author_email': 'xxx',
00219                     'name': 'xxx', 'version': 'xxx',
00220                     'long_description': 'title\n==\n\ntext'}
00221 
00222         cmd = self._get_cmd(metadata)
00223         cmd.ensure_finalized()
00224         cmd.strict = 1
00225         self.assertRaises(DistutilsSetupError, cmd.run)
00226 
00227         # now something that works
00228         metadata['long_description'] = 'title\n=====\n\ntext'
00229         cmd = self._get_cmd(metadata)
00230         cmd.ensure_finalized()
00231         cmd.strict = 1
00232         inputs = Inputs('1', 'tarek', 'y')
00233         register_module.input = inputs.__call__
00234         # let's run the command
00235         try:
00236             cmd.run()
00237         finally:
00238             del register_module.input
00239 
00240         # strict is not by default
00241         cmd = self._get_cmd()
00242         cmd.ensure_finalized()
00243         inputs = Inputs('1', 'tarek', 'y')
00244         register_module.input = inputs.__call__
00245         # let's run the command
00246         try:
00247             cmd.run()
00248         finally:
00249             del register_module.input

Here is the call graph for this function:

def distutils.tests.support.TempdirManager.write_file (   self,
  path,
  content = 'xxx' 
) [inherited]
Writes a file in the given path.


path can be a string or a sequence.

Definition at line 78 of file support.py.

00078 
00079     def write_file(self, path, content='xxx'):
00080         """Writes a file in the given path.
00081 
00082 
00083         path can be a string or a sequence.
00084         """
00085         if isinstance(path, (list, tuple)):
00086             path = os.path.join(*path)
00087         f = open(path, 'w')
00088         try:
00089             f.write(content)
00090         finally:
00091             f.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 71 of file test_register.py.

Definition at line 76 of file test_register.py.

Definition at line 61 of file test_config.py.

Definition at line 25 of file support.py.

Definition at line 107 of file object.h.

Definition at line 107 of file object.h.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 57 of file support.py.

Definition at line 125 of file support.py.

Definition at line 75 of file test_register.py.

Definition at line 71 of file test_config.py.

Definition at line 60 of file test_config.py.

Definition at line 58 of file support.py.

Definition at line 19 of file support.py.

Definition at line 58 of file test_config.py.


The documentation for this class was generated from the following file: