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

Side by Side Diff: Lib/packaging/tests/test_command_upload_docs.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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
« no previous file with comments | « Lib/packaging/tests/test_command_register.py ('k') | Lib/packaging/tests/test_uninstall.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Tests for packaging.command.upload_docs.""" 1 """Tests for packaging.command.upload_docs."""
2 import os 2 import os
3 import sys 3 import sys
4 import shutil 4 import shutil
5 import zipfile 5 import zipfile
6 try: 6 try:
7 import _ssl 7 import _ssl
8 except ImportError: 8 except ImportError:
9 _ssl = None 9 _ssl = None
10 10
11 from packaging.command import upload_docs as upload_docs_mod 11 from packaging.command import upload_docs as upload_docs_mod
12 from packaging.command.upload_docs import upload_docs, zip_dir 12 from packaging.command.upload_docs import (upload_docs, zip_dir,
13 encode_multipart)
13 from packaging.dist import Distribution 14 from packaging.dist import Distribution
14 from packaging.errors import PackagingFileError, PackagingOptionError 15 from packaging.errors import PackagingFileError, PackagingOptionError
15 16
16 from packaging.tests import unittest, support 17 from packaging.tests import unittest, support
17 try: 18 try:
18 import threading 19 import threading
19 from packaging.tests.pypi_server import PyPIServerTestCase 20 from packaging.tests.pypi_server import PyPIServerTestCase
20 except ImportError: 21 except ImportError:
21 threading = None 22 threading = None
22 PyPIServerTestCase = object 23 PyPIServerTestCase = object
23 24
25
26 EXPECTED_MULTIPART_OUTPUT = [
27 b'---x',
28 b'Content-Disposition: form-data; name="username"',
29 b'',
30 b'wok',
31 b'---x',
32 b'Content-Disposition: form-data; name="password"',
33 b'',
34 b'secret',
35 b'---x',
36 b'Content-Disposition: form-data; name="picture"; filename="wok.png"',
37 b'',
38 b'PNG89',
39 b'---x--',
40 b'',
41 ]
24 42
25 PYPIRC = """\ 43 PYPIRC = """\
26 [distutils] 44 [distutils]
27 index-servers = server1 45 index-servers = server1
28 46
29 [server1] 47 [server1]
30 repository = %s 48 repository = %s
31 username = real_slim_shady 49 username = real_slim_shady
32 password = long_island 50 password = long_island
33 """ 51 """
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 self.write_file(os.path.join(sample_dir, "docs", "index.html"), "Ce mort el ennui") 100 self.write_file(os.path.join(sample_dir, "docs", "index.html"), "Ce mort el ennui")
83 self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la") 101 self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la")
84 return sample_dir 102 return sample_dir
85 103
86 def test_zip_dir(self): 104 def test_zip_dir(self):
87 source_dir = self.prepare_sample_dir() 105 source_dir = self.prepare_sample_dir()
88 compressed = zip_dir(source_dir) 106 compressed = zip_dir(source_dir)
89 107
90 zip_f = zipfile.ZipFile(compressed) 108 zip_f = zipfile.ZipFile(compressed)
91 self.assertEqual(zip_f.namelist(), ['index.html', 'docs/index.html']) 109 self.assertEqual(zip_f.namelist(), ['index.html', 'docs/index.html'])
110
111 def test_encode_multipart(self):
112 fields = [('username', 'wok'), ('password', 'secret')]
113 files = [('picture', 'wok.png', b'PNG89')]
114 content_type, body = encode_multipart(fields, files, b'-x')
115 self.assertEqual(b'multipart/form-data; boundary=-x', content_type)
116 self.assertEqual(EXPECTED_MULTIPART_OUTPUT, body.split(b'\r\n'))
92 117
93 def prepare_command(self): 118 def prepare_command(self):
94 self.cmd.upload_dir = self.prepare_sample_dir() 119 self.cmd.upload_dir = self.prepare_sample_dir()
95 self.cmd.ensure_finalized() 120 self.cmd.ensure_finalized()
96 self.cmd.repository = self.pypi.full_address 121 self.cmd.repository = self.pypi.full_address
97 self.cmd.username = "username" 122 self.cmd.username = "username"
98 self.cmd.password = "password" 123 self.cmd.password = "password"
99 124
100 def test_upload(self): 125 def test_upload(self):
101 self.prepare_command() 126 self.prepare_command()
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 self.cmd.run() 208 self.cmd.run()
184 record = self.get_logs()[-1] 209 record = self.get_logs()[-1]
185 self.assertTrue(record, "should report the response") 210 self.assertTrue(record, "should report the response")
186 self.assertIn(self.pypi.default_response_data, record) 211 self.assertIn(self.pypi.default_response_data, record)
187 212
188 def test_suite(): 213 def test_suite():
189 return unittest.makeSuite(UploadDocsTestCase) 214 return unittest.makeSuite(UploadDocsTestCase)
190 215
191 if __name__ == "__main__": 216 if __name__ == "__main__":
192 unittest.main(defaultTest="test_suite") 217 unittest.main(defaultTest="test_suite")
OLDNEW
« no previous file with comments | « Lib/packaging/tests/test_command_register.py ('k') | Lib/packaging/tests/test_uninstall.py » ('j') | no next file with comments »

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