OLD | NEW |
1 """Tests for distutils.command.register.""" | 1 """Tests for distutils.command.register.""" |
2 import sys | 2 import sys |
3 import os | 3 import os |
4 import unittest | 4 import unittest |
5 import getpass | 5 import getpass |
6 import urllib | 6 import urllib |
7 import warnings | 7 import warnings |
8 | 8 |
9 from test.support import check_warnings, run_unittest | 9 from test.support import check_warnings, run_unittest |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 finally: | 114 finally: |
115 del register_module.input | 115 del register_module.input |
116 | 116 |
117 # we should have a brand new .pypirc file | 117 # we should have a brand new .pypirc file |
118 self.assertTrue(os.path.exists(self.rc)) | 118 self.assertTrue(os.path.exists(self.rc)) |
119 | 119 |
120 # with the content similar to WANTED_PYPIRC | 120 # with the content similar to WANTED_PYPIRC |
121 f = open(self.rc) | 121 f = open(self.rc) |
122 try: | 122 try: |
123 content = f.read() | 123 content = f.read() |
124 self.assertEquals(content, WANTED_PYPIRC) | 124 self.assertEqual(content, WANTED_PYPIRC) |
125 finally: | 125 finally: |
126 f.close() | 126 f.close() |
127 | 127 |
128 # now let's make sure the .pypirc file generated | 128 # now let's make sure the .pypirc file generated |
129 # really works : we shouldn't be asked anything | 129 # really works : we shouldn't be asked anything |
130 # if we run the command again | 130 # if we run the command again |
131 def _no_way(prompt=''): | 131 def _no_way(prompt=''): |
132 raise AssertionError(prompt) | 132 raise AssertionError(prompt) |
133 register_module.input = _no_way | 133 register_module.input = _no_way |
134 | 134 |
135 cmd.show_response = 1 | 135 cmd.show_response = 1 |
136 cmd.run() | 136 cmd.run() |
137 | 137 |
138 # let's see what the server received : we should | 138 # let's see what the server received : we should |
139 # have 2 similar requests | 139 # have 2 similar requests |
140 self.assertTrue(self.conn.reqs, 2) | 140 self.assertTrue(self.conn.reqs, 2) |
141 req1 = dict(self.conn.reqs[0].headers) | 141 req1 = dict(self.conn.reqs[0].headers) |
142 req2 = dict(self.conn.reqs[1].headers) | 142 req2 = dict(self.conn.reqs[1].headers) |
143 | 143 |
144 self.assertEquals(req1['Content-length'], '1374') | 144 self.assertEqual(req1['Content-length'], '1374') |
145 self.assertEquals(req2['Content-length'], '1374') | 145 self.assertEqual(req2['Content-length'], '1374') |
146 self.assertTrue((b'xxx') in self.conn.reqs[1].data) | 146 self.assertTrue((b'xxx') in self.conn.reqs[1].data) |
147 | 147 |
148 def test_password_not_in_file(self): | 148 def test_password_not_in_file(self): |
149 | 149 |
150 self.write_file(self.rc, PYPIRC_NOPASSWORD) | 150 self.write_file(self.rc, PYPIRC_NOPASSWORD) |
151 cmd = self._get_cmd() | 151 cmd = self._get_cmd() |
152 cmd._set_config() | 152 cmd._set_config() |
153 cmd.finalize_options() | 153 cmd.finalize_options() |
154 cmd.send_metadata() | 154 cmd.send_metadata() |
155 | 155 |
156 # dist.password should be set | 156 # dist.password should be set |
157 # therefore used afterwards by other commands | 157 # therefore used afterwards by other commands |
158 self.assertEquals(cmd.distribution.password, 'password') | 158 self.assertEqual(cmd.distribution.password, 'password') |
159 | 159 |
160 def test_registering(self): | 160 def test_registering(self): |
161 # this test runs choice 2 | 161 # this test runs choice 2 |
162 cmd = self._get_cmd() | 162 cmd = self._get_cmd() |
163 inputs = Inputs('2', 'tarek', 'tarek@ziade.org') | 163 inputs = Inputs('2', 'tarek', 'tarek@ziade.org') |
164 register_module.input = inputs.__call__ | 164 register_module.input = inputs.__call__ |
165 try: | 165 try: |
166 # let's run the command | 166 # let's run the command |
167 cmd.run() | 167 cmd.run() |
168 finally: | 168 finally: |
169 del register_module.input | 169 del register_module.input |
170 | 170 |
171 # we should have send a request | 171 # we should have send a request |
172 self.assertTrue(self.conn.reqs, 1) | 172 self.assertTrue(self.conn.reqs, 1) |
173 req = self.conn.reqs[0] | 173 req = self.conn.reqs[0] |
174 headers = dict(req.headers) | 174 headers = dict(req.headers) |
175 self.assertEquals(headers['Content-length'], '608') | 175 self.assertEqual(headers['Content-length'], '608') |
176 self.assertTrue((b'tarek') in req.data) | 176 self.assertTrue((b'tarek') in req.data) |
177 | 177 |
178 def test_password_reset(self): | 178 def test_password_reset(self): |
179 # this test runs choice 3 | 179 # this test runs choice 3 |
180 cmd = self._get_cmd() | 180 cmd = self._get_cmd() |
181 inputs = Inputs('3', 'tarek@ziade.org') | 181 inputs = Inputs('3', 'tarek@ziade.org') |
182 register_module.input = inputs.__call__ | 182 register_module.input = inputs.__call__ |
183 try: | 183 try: |
184 # let's run the command | 184 # let's run the command |
185 cmd.run() | 185 cmd.run() |
186 finally: | 186 finally: |
187 del register_module.input | 187 del register_module.input |
188 | 188 |
189 # we should have send a request | 189 # we should have send a request |
190 self.assertTrue(self.conn.reqs, 1) | 190 self.assertTrue(self.conn.reqs, 1) |
191 req = self.conn.reqs[0] | 191 req = self.conn.reqs[0] |
192 headers = dict(req.headers) | 192 headers = dict(req.headers) |
193 self.assertEquals(headers['Content-length'], '290') | 193 self.assertEqual(headers['Content-length'], '290') |
194 self.assertTrue((b'tarek') in req.data) | 194 self.assertTrue((b'tarek') in req.data) |
195 | 195 |
196 def test_strict(self): | 196 def test_strict(self): |
197 # testing the script option | 197 # testing the script option |
198 # when on, the register command stops if | 198 # when on, the register command stops if |
199 # the metadata is incomplete or if | 199 # the metadata is incomplete or if |
200 # long_description is not reSt compliant | 200 # long_description is not reSt compliant |
201 | 201 |
202 # empty metadata | 202 # empty metadata |
203 cmd = self._get_cmd({}) | 203 cmd = self._get_cmd({}) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 cmd.run() | 246 cmd.run() |
247 finally: | 247 finally: |
248 del register_module.input | 248 del register_module.input |
249 | 249 |
250 def test_check_metadata_deprecated(self): | 250 def test_check_metadata_deprecated(self): |
251 # makes sure make_metadata is deprecated | 251 # makes sure make_metadata is deprecated |
252 cmd = self._get_cmd() | 252 cmd = self._get_cmd() |
253 with check_warnings() as w: | 253 with check_warnings() as w: |
254 warnings.simplefilter("always") | 254 warnings.simplefilter("always") |
255 cmd.check_metadata() | 255 cmd.check_metadata() |
256 self.assertEquals(len(w.warnings), 1) | 256 self.assertEqual(len(w.warnings), 1) |
257 | 257 |
258 def test_suite(): | 258 def test_suite(): |
259 return unittest.makeSuite(RegisterTestCase) | 259 return unittest.makeSuite(RegisterTestCase) |
260 | 260 |
261 if __name__ == "__main__": | 261 if __name__ == "__main__": |
262 run_unittest(test_suite()) | 262 run_unittest(test_suite()) |
OLD | NEW |