Issue #7575: An overflow test for math.expm1 was failing on OS X 10.4/Intel,
[python.git] / Lib / distutils / tests / test_config.py
blob0a1bb961ff0cc06c78d56250dc99ee2c74d64929
1 """Tests for distutils.pypirc.pypirc."""
2 import sys
3 import os
4 import unittest
5 import tempfile
6 import shutil
8 from distutils.core import PyPIRCCommand
9 from distutils.core import Distribution
10 from distutils.log import set_threshold
11 from distutils.log import WARN
13 from distutils.tests import support
15 PYPIRC = """\
16 [distutils]
18 index-servers =
19 server1
20 server2
22 [server1]
23 username:me
24 password:secret
26 [server2]
27 username:meagain
28 password: secret
29 realm:acme
30 repository:http://another.pypi/
31 """
33 PYPIRC_OLD = """\
34 [server-login]
35 username:tarek
36 password:secret
37 """
39 WANTED = """\
40 [distutils]
41 index-servers =
42 pypi
44 [pypi]
45 username:tarek
46 password:xxx
47 """
50 class PyPIRCCommandTestCase(support.TempdirManager,
51 support.LoggingSilencer,
52 support.EnvironGuard,
53 unittest.TestCase):
55 def setUp(self):
56 """Patches the environment."""
57 super(PyPIRCCommandTestCase, self).setUp()
58 self.tmp_dir = self.mkdtemp()
59 os.environ['HOME'] = self.tmp_dir
60 self.rc = os.path.join(self.tmp_dir, '.pypirc')
61 self.dist = Distribution()
63 class command(PyPIRCCommand):
64 def __init__(self, dist):
65 PyPIRCCommand.__init__(self, dist)
66 def initialize_options(self):
67 pass
68 finalize_options = initialize_options
70 self._cmd = command
71 self.old_threshold = set_threshold(WARN)
73 def tearDown(self):
74 """Removes the patch."""
75 set_threshold(self.old_threshold)
76 super(PyPIRCCommandTestCase, self).tearDown()
78 def test_server_registration(self):
79 # This test makes sure PyPIRCCommand knows how to:
80 # 1. handle several sections in .pypirc
81 # 2. handle the old format
83 # new format
84 self.write_file(self.rc, PYPIRC)
85 cmd = self._cmd(self.dist)
86 config = cmd._read_pypirc()
88 config = config.items()
89 config.sort()
90 waited = [('password', 'secret'), ('realm', 'pypi'),
91 ('repository', 'http://pypi.python.org/pypi'),
92 ('server', 'server1'), ('username', 'me')]
93 self.assertEquals(config, waited)
95 # old format
96 self.write_file(self.rc, PYPIRC_OLD)
97 config = cmd._read_pypirc()
98 config = config.items()
99 config.sort()
100 waited = [('password', 'secret'), ('realm', 'pypi'),
101 ('repository', 'http://pypi.python.org/pypi'),
102 ('server', 'server-login'), ('username', 'tarek')]
103 self.assertEquals(config, waited)
105 def test_server_empty_registration(self):
106 cmd = self._cmd(self.dist)
107 rc = cmd._get_rc_file()
108 self.assertTrue(not os.path.exists(rc))
109 cmd._store_pypirc('tarek', 'xxx')
110 self.assertTrue(os.path.exists(rc))
111 content = open(rc).read()
112 self.assertEquals(content, WANTED)
114 def test_suite():
115 return unittest.makeSuite(PyPIRCCommandTestCase)
117 if __name__ == "__main__":
118 unittest.main(defaultTest="test_suite")