2008-05-11 11:00:00 -03:00
|
|
|
"""Tests for distutils.pypirc.pypirc."""
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import unittest
|
2009-02-14 10:10:23 -04:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
from distutils.core import PyPIRCCommand
|
|
|
|
from distutils.core import Distribution
|
2008-12-24 15:10:05 -04:00
|
|
|
from distutils.log import set_threshold
|
|
|
|
from distutils.log import WARN
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
from distutils.tests import support
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
from test.test_support import run_unittest
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
PYPIRC = """\
|
|
|
|
[distutils]
|
|
|
|
|
|
|
|
index-servers =
|
|
|
|
server1
|
|
|
|
server2
|
|
|
|
|
|
|
|
[server1]
|
|
|
|
username:me
|
|
|
|
password:secret
|
|
|
|
|
|
|
|
[server2]
|
|
|
|
username:meagain
|
|
|
|
password: secret
|
|
|
|
realm:acme
|
|
|
|
repository:http://another.pypi/
|
|
|
|
"""
|
|
|
|
|
|
|
|
PYPIRC_OLD = """\
|
|
|
|
[server-login]
|
|
|
|
username:tarek
|
|
|
|
password:secret
|
|
|
|
"""
|
|
|
|
|
2008-12-24 15:10:05 -04:00
|
|
|
WANTED = """\
|
|
|
|
[distutils]
|
|
|
|
index-servers =
|
|
|
|
pypi
|
|
|
|
|
|
|
|
[pypi]
|
|
|
|
username:tarek
|
|
|
|
password:xxx
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2009-03-31 17:56:11 -03:00
|
|
|
class PyPIRCCommandTestCase(support.TempdirManager,
|
|
|
|
support.LoggingSilencer,
|
2009-05-10 09:17:30 -03:00
|
|
|
support.EnvironGuard,
|
2009-03-31 17:56:11 -03:00
|
|
|
unittest.TestCase):
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""Patches the environment."""
|
2009-02-25 18:29:27 -04:00
|
|
|
super(PyPIRCCommandTestCase, self).setUp()
|
2009-02-14 10:10:23 -04:00
|
|
|
self.tmp_dir = self.mkdtemp()
|
2009-10-18 06:28:26 -03:00
|
|
|
os.environ['HOME'] = self.tmp_dir
|
2009-02-14 10:10:23 -04:00
|
|
|
self.rc = os.path.join(self.tmp_dir, '.pypirc')
|
2008-05-11 11:00:00 -03:00
|
|
|
self.dist = Distribution()
|
|
|
|
|
|
|
|
class command(PyPIRCCommand):
|
|
|
|
def __init__(self, dist):
|
|
|
|
PyPIRCCommand.__init__(self, dist)
|
|
|
|
def initialize_options(self):
|
|
|
|
pass
|
|
|
|
finalize_options = initialize_options
|
|
|
|
|
|
|
|
self._cmd = command
|
2008-12-24 15:10:05 -04:00
|
|
|
self.old_threshold = set_threshold(WARN)
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""Removes the patch."""
|
2008-12-24 15:10:05 -04:00
|
|
|
set_threshold(self.old_threshold)
|
2009-02-25 18:29:27 -04:00
|
|
|
super(PyPIRCCommandTestCase, self).tearDown()
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
def test_server_registration(self):
|
|
|
|
# This test makes sure PyPIRCCommand knows how to:
|
|
|
|
# 1. handle several sections in .pypirc
|
|
|
|
# 2. handle the old format
|
|
|
|
|
|
|
|
# new format
|
2009-05-10 09:17:30 -03:00
|
|
|
self.write_file(self.rc, PYPIRC)
|
2008-05-11 11:00:00 -03:00
|
|
|
cmd = self._cmd(self.dist)
|
|
|
|
config = cmd._read_pypirc()
|
|
|
|
|
|
|
|
config = config.items()
|
|
|
|
config.sort()
|
|
|
|
waited = [('password', 'secret'), ('realm', 'pypi'),
|
|
|
|
('repository', 'http://pypi.python.org/pypi'),
|
|
|
|
('server', 'server1'), ('username', 'me')]
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(config, waited)
|
2008-05-11 11:00:00 -03:00
|
|
|
|
|
|
|
# old format
|
2009-05-10 09:17:30 -03:00
|
|
|
self.write_file(self.rc, PYPIRC_OLD)
|
2008-05-11 11:00:00 -03:00
|
|
|
config = cmd._read_pypirc()
|
|
|
|
config = config.items()
|
|
|
|
config.sort()
|
|
|
|
waited = [('password', 'secret'), ('realm', 'pypi'),
|
|
|
|
('repository', 'http://pypi.python.org/pypi'),
|
|
|
|
('server', 'server-login'), ('username', 'tarek')]
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(config, waited)
|
2008-05-11 11:00:00 -03:00
|
|
|
|
2008-12-24 15:10:05 -04:00
|
|
|
def test_server_empty_registration(self):
|
|
|
|
cmd = self._cmd(self.dist)
|
|
|
|
rc = cmd._get_rc_file()
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(not os.path.exists(rc))
|
2008-12-24 15:10:05 -04:00
|
|
|
cmd._store_pypirc('tarek', 'xxx')
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(os.path.exists(rc))
|
2010-11-06 01:06:18 -03:00
|
|
|
f = open(rc)
|
|
|
|
try:
|
|
|
|
content = f.read()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(content, WANTED)
|
2010-11-06 01:06:18 -03:00
|
|
|
finally:
|
|
|
|
f.close()
|
2008-12-24 15:10:05 -04:00
|
|
|
|
2008-05-11 11:00:00 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(PyPIRCCommandTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
run_unittest(test_suite())
|