Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(43464)

Side by Side Diff: Lib/distutils/tests/test_register.py

Issue 19600: Use specific asserts in distutils tests
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 """Tests for distutils.command.register.""" 1 """Tests for distutils.command.register."""
2 import os 2 import os
3 import unittest 3 import unittest
4 import getpass 4 import getpass
5 import urllib 5 import urllib
6 import warnings 6 import warnings
7 7
8 from test.support import check_warnings, run_unittest 8 from test.support import check_warnings, run_unittest
9 9
10 from distutils.command import register as register_module 10 from distutils.command import register as register_module
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return register(dist) 91 return register(dist)
92 92
93 def test_create_pypirc(self): 93 def test_create_pypirc(self):
94 # this test makes sure a .pypirc file 94 # this test makes sure a .pypirc file
95 # is created when requested. 95 # is created when requested.
96 96
97 # let's create a register instance 97 # let's create a register instance
98 cmd = self._get_cmd() 98 cmd = self._get_cmd()
99 99
100 # we shouldn't have a .pypirc file yet 100 # we shouldn't have a .pypirc file yet
101 self.assertTrue(not os.path.exists(self.rc)) 101 self.assertFalse(os.path.exists(self.rc))
102 102
103 # patching input and getpass.getpass 103 # patching input and getpass.getpass
104 # so register gets happy 104 # so register gets happy
105 # 105 #
106 # Here's what we are faking : 106 # Here's what we are faking :
107 # use your existing login (choice 1.) 107 # use your existing login (choice 1.)
108 # Username : 'tarek' 108 # Username : 'tarek'
109 # Password : 'password' 109 # Password : 'password'
110 # Save your login (y/N)? : 'y' 110 # Save your login (y/N)? : 'y'
111 inputs = Inputs('1', 'tarek', 'y') 111 inputs = Inputs('1', 'tarek', 'y')
(...skipping 26 matching lines...) Expand all
138 cmd.run() 138 cmd.run()
139 139
140 # let's see what the server received : we should 140 # let's see what the server received : we should
141 # have 2 similar requests 141 # have 2 similar requests
142 self.assertEqual(len(self.conn.reqs), 2) 142 self.assertEqual(len(self.conn.reqs), 2)
143 req1 = dict(self.conn.reqs[0].headers) 143 req1 = dict(self.conn.reqs[0].headers)
144 req2 = dict(self.conn.reqs[1].headers) 144 req2 = dict(self.conn.reqs[1].headers)
145 145
146 self.assertEqual(req1['Content-length'], '1374') 146 self.assertEqual(req1['Content-length'], '1374')
147 self.assertEqual(req2['Content-length'], '1374') 147 self.assertEqual(req2['Content-length'], '1374')
148 self.assertTrue((b'xxx') in self.conn.reqs[1].data) 148 self.assertIn(b'xxx', self.conn.reqs[1].data)
149 149
150 def test_password_not_in_file(self): 150 def test_password_not_in_file(self):
151 151
152 self.write_file(self.rc, PYPIRC_NOPASSWORD) 152 self.write_file(self.rc, PYPIRC_NOPASSWORD)
153 cmd = self._get_cmd() 153 cmd = self._get_cmd()
154 cmd._set_config() 154 cmd._set_config()
155 cmd.finalize_options() 155 cmd.finalize_options()
156 cmd.send_metadata() 156 cmd.send_metadata()
157 157
158 # dist.password should be set 158 # dist.password should be set
159 # therefore used afterwards by other commands 159 # therefore used afterwards by other commands
160 self.assertEqual(cmd.distribution.password, 'password') 160 self.assertEqual(cmd.distribution.password, 'password')
161 161
162 def test_registering(self): 162 def test_registering(self):
163 # this test runs choice 2 163 # this test runs choice 2
164 cmd = self._get_cmd() 164 cmd = self._get_cmd()
165 inputs = Inputs('2', 'tarek', 'tarek@ziade.org') 165 inputs = Inputs('2', 'tarek', 'tarek@ziade.org')
166 register_module.input = inputs.__call__ 166 register_module.input = inputs.__call__
167 try: 167 try:
168 # let's run the command 168 # let's run the command
169 cmd.run() 169 cmd.run()
170 finally: 170 finally:
171 del register_module.input 171 del register_module.input
172 172
173 # we should have send a request 173 # we should have send a request
174 self.assertEqual(len(self.conn.reqs), 1) 174 self.assertEqual(len(self.conn.reqs), 1)
175 req = self.conn.reqs[0] 175 req = self.conn.reqs[0]
176 headers = dict(req.headers) 176 headers = dict(req.headers)
177 self.assertEqual(headers['Content-length'], '608') 177 self.assertEqual(headers['Content-length'], '608')
178 self.assertTrue((b'tarek') in req.data) 178 self.assertIn(b'tarek', req.data)
179 179
180 def test_password_reset(self): 180 def test_password_reset(self):
181 # this test runs choice 3 181 # this test runs choice 3
182 cmd = self._get_cmd() 182 cmd = self._get_cmd()
183 inputs = Inputs('3', 'tarek@ziade.org') 183 inputs = Inputs('3', 'tarek@ziade.org')
184 register_module.input = inputs.__call__ 184 register_module.input = inputs.__call__
185 try: 185 try:
186 # let's run the command 186 # let's run the command
187 cmd.run() 187 cmd.run()
188 finally: 188 finally:
189 del register_module.input 189 del register_module.input
190 190
191 # we should have send a request 191 # we should have send a request
192 self.assertEqual(len(self.conn.reqs), 1) 192 self.assertEqual(len(self.conn.reqs), 1)
193 req = self.conn.reqs[0] 193 req = self.conn.reqs[0]
194 headers = dict(req.headers) 194 headers = dict(req.headers)
195 self.assertEqual(headers['Content-length'], '290') 195 self.assertEqual(headers['Content-length'], '290')
196 self.assertTrue((b'tarek') in req.data) 196 self.assertIn(b'tarek', req.data)
197 197
198 @unittest.skipUnless(docutils is not None, 'needs docutils') 198 @unittest.skipUnless(docutils is not None, 'needs docutils')
199 def test_strict(self): 199 def test_strict(self):
200 # testing the script option 200 # testing the script option
201 # when on, the register command stops if 201 # when on, the register command stops if
202 # the metadata is incomplete or if 202 # the metadata is incomplete or if
203 # long_description is not reSt compliant 203 # long_description is not reSt compliant
204 204
205 # empty metadata 205 # empty metadata
206 cmd = self._get_cmd({}) 206 cmd = self._get_cmd({})
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 with check_warnings() as w: 283 with check_warnings() as w:
284 warnings.simplefilter("always") 284 warnings.simplefilter("always")
285 cmd.check_metadata() 285 cmd.check_metadata()
286 self.assertEqual(len(w.warnings), 1) 286 self.assertEqual(len(w.warnings), 1)
287 287
288 def test_suite(): 288 def test_suite():
289 return unittest.makeSuite(RegisterTestCase) 289 return unittest.makeSuite(RegisterTestCase)
290 290
291 if __name__ == "__main__": 291 if __name__ == "__main__":
292 run_unittest(test_suite()) 292 run_unittest(test_suite())
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+