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

Delta Between Two Patch Sets: Lib/distutils/tests/test_upload.py

Issue 21722: teach distutils "upload" to exit with code != 0 when error occurs
Left Patch Set: Created 5 years, 12 months ago
Right Patch Set: Created 5 years, 12 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:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/distutils/command/upload.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 # -*- encoding: utf8 -*- 1 # -*- encoding: utf8 -*-
2 """Tests for distutils.command.upload.""" 2 """Tests for distutils.command.upload."""
3 import os 3 import os
4 import unittest 4 import unittest
5 from test.test_support import run_unittest 5 from test.test_support import run_unittest
6 6
7 from distutils.command import upload as upload_mod 7 from distutils.command import upload as upload_mod
8 from distutils.command.upload import upload 8 from distutils.command.upload import upload
9 from distutils.core import Distribution 9 from distutils.core import Distribution
10 from distutils.errors import DistutilsError
10 11
11 from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase 12 from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
12 13
13 PYPIRC_LONG_PASSWORD = """\ 14 PYPIRC_LONG_PASSWORD = """\
14 [distutils] 15 [distutils]
15 16
16 index-servers = 17 index-servers =
17 server1 18 server1
18 server2 19 server2
19 20
(...skipping 14 matching lines...) Expand all
34 35
35 index-servers = 36 index-servers =
36 server1 37 server1
37 38
38 [server1] 39 [server1]
39 username:me 40 username:me
40 """ 41 """
41 42
42 class FakeOpen(object): 43 class FakeOpen(object):
43 44
44 def __init__(self, url): 45 def __init__(self, url, msg=None, code=None):
45 self.url = url 46 self.url = url
46 if not isinstance(url, str): 47 if not isinstance(url, str):
47 self.req = url 48 self.req = url
48 else: 49 else:
49 self.req = None 50 self.req = None
50 self.msg = 'OK' 51 self.msg = msg or 'OK'
52 self.code = code or 200
51 53
52 def getcode(self): 54 def getcode(self):
53 return 200 55 return self.code
54 56
55 57
56 class uploadTestCase(PyPIRCCommandTestCase): 58 class uploadTestCase(PyPIRCCommandTestCase):
57 59
58 def setUp(self): 60 def setUp(self):
59 super(uploadTestCase, self).setUp() 61 super(uploadTestCase, self).setUp()
60 self.old_open = upload_mod.urlopen 62 self.old_open = upload_mod.urlopen
61 upload_mod.urlopen = self._urlopen 63 upload_mod.urlopen = self._urlopen
62 self.last_open = None 64 self.last_open = None
65 self.next_msg = None
66 self.next_code = None
63 67
64 def tearDown(self): 68 def tearDown(self):
65 upload_mod.urlopen = self.old_open 69 upload_mod.urlopen = self.old_open
66 super(uploadTestCase, self).tearDown() 70 super(uploadTestCase, self).tearDown()
67 71
68 def _urlopen(self, url): 72 def _urlopen(self, url):
69 self.last_open = FakeOpen(url) 73 self.last_open = FakeOpen(url, msg=self.next_msg, code=self.next_code)
70 return self.last_open 74 return self.last_open
71 75
72 def test_finalize_options(self): 76 def test_finalize_options(self):
73 77
74 # new format 78 # new format
75 self.write_file(self.rc, PYPIRC) 79 self.write_file(self.rc, PYPIRC)
76 dist = Distribution() 80 dist = Distribution()
77 cmd = upload(dist) 81 cmd = upload(dist)
78 cmd.finalize_options() 82 cmd.finalize_options()
79 for attr, waited in (('username', 'me'), ('password', 'secret'), 83 for attr, waited in (('username', 'me'), ('password', 'secret'),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 headers = dict(self.last_open.req.headers) 121 headers = dict(self.last_open.req.headers)
118 self.assertEqual(headers['Content-length'], '2085') 122 self.assertEqual(headers['Content-length'], '2085')
119 self.assertTrue(headers['Content-type'].startswith('multipart/form-data' )) 123 self.assertTrue(headers['Content-type'].startswith('multipart/form-data' ))
120 self.assertEqual(self.last_open.req.get_method(), 'POST') 124 self.assertEqual(self.last_open.req.get_method(), 'POST')
121 self.assertEqual(self.last_open.req.get_full_url(), 125 self.assertEqual(self.last_open.req.get_full_url(),
122 'https://pypi.python.org/pypi') 126 'https://pypi.python.org/pypi')
123 self.assertIn('xxx', self.last_open.req.data) 127 self.assertIn('xxx', self.last_open.req.data)
124 auth = self.last_open.req.headers['Authorization'] 128 auth = self.last_open.req.headers['Authorization']
125 self.assertNotIn('\n', auth) 129 self.assertNotIn('\n', auth)
126 130
131 def test_upload_fails(self):
132 try:
133 self.next_msg = "Not Found"
134 self.next_code = 404
135 self.assertRaises(DistutilsError, self.test_upload)
136 finally:
137 self.next_msg = None
138 self.next_code = None
139
127 def test_suite(): 140 def test_suite():
128 return unittest.makeSuite(uploadTestCase) 141 return unittest.makeSuite(uploadTestCase)
129 142
130 if __name__ == "__main__": 143 if __name__ == "__main__":
131 run_unittest(test_suite()) 144 run_unittest(test_suite())
LEFTRIGHT

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