Merge ~cjwatson/txpkgupload:py3-avoid-stringio into txpkgupload:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 22ee4bb8c6886f989a8f1c72b1d1236359c340cd
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/txpkgupload:py3-avoid-stringio
Merge into: txpkgupload:master
Diff against target: 202 lines (+40/-39)
2 files modified
src/txpkgupload/tests/filesystem.txt (+36/-36)
src/txpkgupload/tests/test_plugin.py (+4/-3)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+392939@code.launchpad.net

Commit message

Port tests away from StringIO module

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/txpkgupload/tests/filesystem.txt b/src/txpkgupload/tests/filesystem.txt
2index 52f9dac..e630558 100644
3--- a/src/txpkgupload/tests/filesystem.txt
4+++ b/src/txpkgupload/tests/filesystem.txt
5@@ -19,13 +19,13 @@ First we need to setup our test environment.
6
7 >>> testfile = "testfile"
8 >>> full_testfile = os.path.join(rootpath, testfile)
9- >>> testfile_contents = "contents of the file"
10- >>> open(full_testfile, 'w').write(testfile_contents)
11+ >>> testfile_contents = b"contents of the file"
12+ >>> open(full_testfile, 'wb').write(testfile_contents)
13
14 >>> testdir = "testdir"
15 >>> full_testdir = os.path.join(rootpath, testdir)
16 >>> os.mkdir(full_testdir)
17- >>> propaganda = """
18+ >>> propaganda = b"""
19 ... GNU is aimed initially at machines in the 68000/16000 class with
20 ... virtual memory, because they are the easiest machines to make it run
21 ... on. The extra effort to make it run on smaller machines will be left
22@@ -313,7 +313,7 @@ directory.
23 False
24 >>> os.path.exists(new_full_testfile)
25 True
26- >>> open(new_full_testfile).read() == testfile_contents
27+ >>> open(new_full_testfile, "rb").read() == testfile_contents
28 True
29 >>> ufs.rename(new_testfile, testfile)
30
31@@ -371,28 +371,28 @@ writefile
32
33 `writefile` writes data to a file.
34
35- >>> from StringIO import StringIO
36- >>> ufs.writefile("upload", StringIO(propaganda))
37- >>> open(os.path.join(rootpath, "upload")).read() == propaganda
38+ >>> import io
39+ >>> ufs.writefile("upload", io.BytesIO(propaganda))
40+ >>> open(os.path.join(rootpath, "upload"), "rb").read() == propaganda
41 True
42 >>> ufs.remove("upload")
43
44 If neither `start` nor `end` are specified, then the file contents
45 are overwritten.
46
47- >>> ufs.writefile(testfile, StringIO("MOO"))
48- >>> open(full_testfile).read() == "MOO"
49+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"))
50+ >>> open(full_testfile, "rb").read() == b"MOO"
51 True
52- >>> ufs.writefile(testfile, StringIO(testfile_contents))
53+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
54
55 If `start` or `end` are specified, they must be non-negative.
56
57- >>> ufs.writefile("upload", StringIO(propaganda), -37)
58+ >>> ufs.writefile("upload", io.BytesIO(propaganda), -37)
59 Traceback (most recent call last):
60 ...
61 ValueError: ('Negative start argument:', -37)
62
63- >>> ufs.writefile("upload", StringIO(propaganda), 1, -43)
64+ >>> ufs.writefile("upload", io.BytesIO(propaganda), 1, -43)
65 Traceback (most recent call last):
66 ...
67 ValueError: ('Negative end argument:', -43)
68@@ -400,71 +400,71 @@ If `start` or `end` are specified, they must be non-negative.
69 If `start` or `end` is not None, then only part of the file is
70 written. The remainder of the file is unchanged.
71
72- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 12)
73- >>> open(full_testfile).read() == "contents MOOthe file"
74+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 12)
75+ >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
76 True
77- >>> ufs.writefile(testfile, StringIO(testfile_contents))
78+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
79
80 If `end` is None, then the file is truncated after the data are
81 written.
82
83- >>> ufs.writefile(testfile, StringIO("MOO"), 9)
84+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9)
85 >>> open(full_testfile).read() == "contents MOO"
86 True
87- >>> ufs.writefile(testfile, StringIO(testfile_contents))
88+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
89
90 If `start` is specified and the file doesn't exist or is shorter
91 than start, the file will contain undefined data before start.
92
93- >>> ufs.writefile("didnt-exist", StringIO("MOO"), 9)
94- >>> open(os.path.join(rootpath, "didnt-exist")).read() == "\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO"
95+ >>> ufs.writefile("didnt-exist", io.BytesIO(b"MOO"), 9)
96+ >>> open(os.path.join(rootpath, "didnt-exist"), "rb").read() == (
97+ ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO")
98 True
99 >>> ufs.remove("didnt-exist")
100
101 If `end` is not None and there isn't enough data in `instream` to fill
102 out the file, then the missing data is undefined.
103
104- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 15)
105- >>> open(full_testfile).read() == "contents MOOthe file"
106+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 15)
107+ >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
108 True
109- >>> ufs.writefile(testfile, StringIO(testfile_contents))
110+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
111
112 If `end` is less than or the same as `start no data is writen to the file.
113
114- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 4)
115- >>> open(full_testfile).read() == "contents of the file"
116+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 4)
117+ >>> open(full_testfile, "rb").read() == b"contents of the file"
118 True
119
120- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 9)
121- >>> open(full_testfile).read() == "contents of the file"
122+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 9)
123+ >>> open(full_testfile, "rb").read() == b"contents of the file"
124 True
125
126 If `append` is true the file is appended to rather than being
127 overwritten.
128
129- >>> ufs.writefile(testfile, StringIO("MOO"), append=True)
130- >>> open(full_testfile).read() == "contents of the fileMOO"
131+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), append=True)
132+ >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
133 True
134- >>> ufs.writefile(testfile, StringIO(testfile_contents))
135+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
136
137 Additionally, if `append` is true, `start` and `end` are ignored.
138
139- >>> ufs.writefile(testfile, StringIO("MOO"), 10, 13, append=True)
140- >>> open(full_testfile).read() == "contents of the fileMOO"
141+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 10, 13, append=True)
142+ >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
143 True
144- >>> ufs.writefile(testfile, StringIO(testfile_contents))
145+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
146
147 'writefile' is able to create inexistent directories in a requested
148 path:
149
150 >>> os.path.exists(os.path.join(rootpath, "foo"))
151 False
152- >>> ufs.writefile("foo/bar", StringIO("fake")) is None
153- True
154+ >>> ufs.writefile("foo/bar", io.BytesIO(b"fake"))
155 >>> os.path.exists(os.path.join(rootpath, "foo/bar"))
156 True
157- >>> open(os.path.join(rootpath, "foo/bar")).read()
158- 'fake'
159+ >>> open(os.path.join(rootpath, "foo/bar"), "rb").read() == b"fake"
160+ True
161
162
163 writable
164diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
165index 29418af..f131364 100644
166--- a/src/txpkgupload/tests/test_plugin.py
167+++ b/src/txpkgupload/tests/test_plugin.py
168@@ -1,14 +1,16 @@
169 # Copyright 2009-2011 Canonical Ltd. This software is licensed under the
170 # GNU Affero General Public License version 3 (see the file LICENSE).
171
172+from __future__ import absolute_import, print_function, unicode_literals
173+
174 __metaclass__ = type
175
176 from collections import defaultdict
177 from functools import partial
178+import io
179 import os
180 import shutil
181 import stat
182-import StringIO
183 import sys
184 import tempfile
185 from textwrap import dedent
186@@ -205,7 +207,7 @@ class PkgUploadFixture(DeferringFixture):
187 self.root, "txpkgupload-access.log")
188 if self.extra_config is not None:
189 deep_update(
190- config, yaml.load(StringIO.StringIO(self.extra_config)))
191+ config, yaml.load(io.StringIO(self.extra_config)))
192 # Make some paths absolute to cope with tests running in a different
193 # working directory.
194 for key in ("host_key_private", "host_key_public"):
195@@ -561,7 +563,6 @@ class TestPkgUploadServiceMakerMixin:
196 'test-source_0.1_source.changes']
197
198 for upload in files:
199- fake_file = StringIO.StringIO(upload)
200 file_to_upload = "~ppa-user/ppa/ubuntu/%s" % upload
201 yield self.server.createFile(
202 client, file_to_upload, upload.encode("ASCII"))

Subscribers

People subscribed via source and target branches

to all changes: