launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25573
[Merge] ~cjwatson/txpkgupload:py3-avoid-stringio into txpkgupload:master
Colin Watson has proposed merging ~cjwatson/txpkgupload:py3-avoid-stringio into txpkgupload:master.
Commit message:
Port tests away from StringIO module
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/txpkgupload/+git/txpkgupload/+merge/392939
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/txpkgupload:py3-avoid-stringio into txpkgupload:master.
diff --git a/src/txpkgupload/tests/filesystem.txt b/src/txpkgupload/tests/filesystem.txt
index 52f9dac..e630558 100644
--- a/src/txpkgupload/tests/filesystem.txt
+++ b/src/txpkgupload/tests/filesystem.txt
@@ -19,13 +19,13 @@ First we need to setup our test environment.
>>> testfile = "testfile"
>>> full_testfile = os.path.join(rootpath, testfile)
- >>> testfile_contents = "contents of the file"
- >>> open(full_testfile, 'w').write(testfile_contents)
+ >>> testfile_contents = b"contents of the file"
+ >>> open(full_testfile, 'wb').write(testfile_contents)
>>> testdir = "testdir"
>>> full_testdir = os.path.join(rootpath, testdir)
>>> os.mkdir(full_testdir)
- >>> propaganda = """
+ >>> propaganda = b"""
... GNU is aimed initially at machines in the 68000/16000 class with
... virtual memory, because they are the easiest machines to make it run
... on. The extra effort to make it run on smaller machines will be left
@@ -313,7 +313,7 @@ directory.
False
>>> os.path.exists(new_full_testfile)
True
- >>> open(new_full_testfile).read() == testfile_contents
+ >>> open(new_full_testfile, "rb").read() == testfile_contents
True
>>> ufs.rename(new_testfile, testfile)
@@ -371,28 +371,28 @@ writefile
`writefile` writes data to a file.
- >>> from StringIO import StringIO
- >>> ufs.writefile("upload", StringIO(propaganda))
- >>> open(os.path.join(rootpath, "upload")).read() == propaganda
+ >>> import io
+ >>> ufs.writefile("upload", io.BytesIO(propaganda))
+ >>> open(os.path.join(rootpath, "upload"), "rb").read() == propaganda
True
>>> ufs.remove("upload")
If neither `start` nor `end` are specified, then the file contents
are overwritten.
- >>> ufs.writefile(testfile, StringIO("MOO"))
- >>> open(full_testfile).read() == "MOO"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"))
+ >>> open(full_testfile, "rb").read() == b"MOO"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
If `start` or `end` are specified, they must be non-negative.
- >>> ufs.writefile("upload", StringIO(propaganda), -37)
+ >>> ufs.writefile("upload", io.BytesIO(propaganda), -37)
Traceback (most recent call last):
...
ValueError: ('Negative start argument:', -37)
- >>> ufs.writefile("upload", StringIO(propaganda), 1, -43)
+ >>> ufs.writefile("upload", io.BytesIO(propaganda), 1, -43)
Traceback (most recent call last):
...
ValueError: ('Negative end argument:', -43)
@@ -400,71 +400,71 @@ If `start` or `end` are specified, they must be non-negative.
If `start` or `end` is not None, then only part of the file is
written. The remainder of the file is unchanged.
- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 12)
- >>> open(full_testfile).read() == "contents MOOthe file"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 12)
+ >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
If `end` is None, then the file is truncated after the data are
written.
- >>> ufs.writefile(testfile, StringIO("MOO"), 9)
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9)
>>> open(full_testfile).read() == "contents MOO"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
If `start` is specified and the file doesn't exist or is shorter
than start, the file will contain undefined data before start.
- >>> ufs.writefile("didnt-exist", StringIO("MOO"), 9)
- >>> open(os.path.join(rootpath, "didnt-exist")).read() == "\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO"
+ >>> ufs.writefile("didnt-exist", io.BytesIO(b"MOO"), 9)
+ >>> open(os.path.join(rootpath, "didnt-exist"), "rb").read() == (
+ ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO")
True
>>> ufs.remove("didnt-exist")
If `end` is not None and there isn't enough data in `instream` to fill
out the file, then the missing data is undefined.
- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 15)
- >>> open(full_testfile).read() == "contents MOOthe file"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 15)
+ >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
If `end` is less than or the same as `start no data is writen to the file.
- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 4)
- >>> open(full_testfile).read() == "contents of the file"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 4)
+ >>> open(full_testfile, "rb").read() == b"contents of the file"
True
- >>> ufs.writefile(testfile, StringIO("MOO"), 9, 9)
- >>> open(full_testfile).read() == "contents of the file"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 9)
+ >>> open(full_testfile, "rb").read() == b"contents of the file"
True
If `append` is true the file is appended to rather than being
overwritten.
- >>> ufs.writefile(testfile, StringIO("MOO"), append=True)
- >>> open(full_testfile).read() == "contents of the fileMOO"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), append=True)
+ >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
Additionally, if `append` is true, `start` and `end` are ignored.
- >>> ufs.writefile(testfile, StringIO("MOO"), 10, 13, append=True)
- >>> open(full_testfile).read() == "contents of the fileMOO"
+ >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 10, 13, append=True)
+ >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
True
- >>> ufs.writefile(testfile, StringIO(testfile_contents))
+ >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
'writefile' is able to create inexistent directories in a requested
path:
>>> os.path.exists(os.path.join(rootpath, "foo"))
False
- >>> ufs.writefile("foo/bar", StringIO("fake")) is None
- True
+ >>> ufs.writefile("foo/bar", io.BytesIO(b"fake"))
>>> os.path.exists(os.path.join(rootpath, "foo/bar"))
True
- >>> open(os.path.join(rootpath, "foo/bar")).read()
- 'fake'
+ >>> open(os.path.join(rootpath, "foo/bar"), "rb").read() == b"fake"
+ True
writable
diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
index 29418af..f131364 100644
--- a/src/txpkgupload/tests/test_plugin.py
+++ b/src/txpkgupload/tests/test_plugin.py
@@ -1,14 +1,16 @@
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from collections import defaultdict
from functools import partial
+import io
import os
import shutil
import stat
-import StringIO
import sys
import tempfile
from textwrap import dedent
@@ -205,7 +207,7 @@ class PkgUploadFixture(DeferringFixture):
self.root, "txpkgupload-access.log")
if self.extra_config is not None:
deep_update(
- config, yaml.load(StringIO.StringIO(self.extra_config)))
+ config, yaml.load(io.StringIO(self.extra_config)))
# Make some paths absolute to cope with tests running in a different
# working directory.
for key in ("host_key_private", "host_key_public"):
@@ -561,7 +563,6 @@ class TestPkgUploadServiceMakerMixin:
'test-source_0.1_source.changes']
for upload in files:
- fake_file = StringIO.StringIO(upload)
file_to_upload = "~ppa-user/ppa/ubuntu/%s" % upload
yield self.server.createFile(
client, file_to_upload, upload.encode("ASCII"))