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
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.
1919
20 >>> testfile = "testfile"20 >>> testfile = "testfile"
21 >>> full_testfile = os.path.join(rootpath, testfile)21 >>> full_testfile = os.path.join(rootpath, testfile)
22 >>> testfile_contents = "contents of the file"22 >>> testfile_contents = b"contents of the file"
23 >>> open(full_testfile, 'w').write(testfile_contents)23 >>> open(full_testfile, 'wb').write(testfile_contents)
2424
25 >>> testdir = "testdir"25 >>> testdir = "testdir"
26 >>> full_testdir = os.path.join(rootpath, testdir)26 >>> full_testdir = os.path.join(rootpath, testdir)
27 >>> os.mkdir(full_testdir)27 >>> os.mkdir(full_testdir)
28 >>> propaganda = """28 >>> propaganda = b"""
29 ... GNU is aimed initially at machines in the 68000/16000 class with29 ... GNU is aimed initially at machines in the 68000/16000 class with
30 ... virtual memory, because they are the easiest machines to make it run30 ... virtual memory, because they are the easiest machines to make it run
31 ... on. The extra effort to make it run on smaller machines will be left31 ... on. The extra effort to make it run on smaller machines will be left
@@ -313,7 +313,7 @@ directory.
313 False313 False
314 >>> os.path.exists(new_full_testfile)314 >>> os.path.exists(new_full_testfile)
315 True315 True
316 >>> open(new_full_testfile).read() == testfile_contents316 >>> open(new_full_testfile, "rb").read() == testfile_contents
317 True317 True
318 >>> ufs.rename(new_testfile, testfile)318 >>> ufs.rename(new_testfile, testfile)
319 319
@@ -371,28 +371,28 @@ writefile
371371
372`writefile` writes data to a file.372`writefile` writes data to a file.
373373
374 >>> from StringIO import StringIO374 >>> import io
375 >>> ufs.writefile("upload", StringIO(propaganda))375 >>> ufs.writefile("upload", io.BytesIO(propaganda))
376 >>> open(os.path.join(rootpath, "upload")).read() == propaganda376 >>> open(os.path.join(rootpath, "upload"), "rb").read() == propaganda
377 True377 True
378 >>> ufs.remove("upload")378 >>> ufs.remove("upload")
379379
380If neither `start` nor `end` are specified, then the file contents380If neither `start` nor `end` are specified, then the file contents
381are overwritten.381are overwritten.
382382
383 >>> ufs.writefile(testfile, StringIO("MOO"))383 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"))
384 >>> open(full_testfile).read() == "MOO"384 >>> open(full_testfile, "rb").read() == b"MOO"
385 True385 True
386 >>> ufs.writefile(testfile, StringIO(testfile_contents))386 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
387387
388If `start` or `end` are specified, they must be non-negative.388If `start` or `end` are specified, they must be non-negative.
389389
390 >>> ufs.writefile("upload", StringIO(propaganda), -37)390 >>> ufs.writefile("upload", io.BytesIO(propaganda), -37)
391 Traceback (most recent call last):391 Traceback (most recent call last):
392 ...392 ...
393 ValueError: ('Negative start argument:', -37)393 ValueError: ('Negative start argument:', -37)
394394
395 >>> ufs.writefile("upload", StringIO(propaganda), 1, -43)395 >>> ufs.writefile("upload", io.BytesIO(propaganda), 1, -43)
396 Traceback (most recent call last):396 Traceback (most recent call last):
397 ...397 ...
398 ValueError: ('Negative end argument:', -43)398 ValueError: ('Negative end argument:', -43)
@@ -400,71 +400,71 @@ If `start` or `end` are specified, they must be non-negative.
400If `start` or `end` is not None, then only part of the file is400If `start` or `end` is not None, then only part of the file is
401written. The remainder of the file is unchanged.401written. The remainder of the file is unchanged.
402402
403 >>> ufs.writefile(testfile, StringIO("MOO"), 9, 12)403 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 12)
404 >>> open(full_testfile).read() == "contents MOOthe file"404 >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
405 True405 True
406 >>> ufs.writefile(testfile, StringIO(testfile_contents))406 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
407407
408If `end` is None, then the file is truncated after the data are408If `end` is None, then the file is truncated after the data are
409written. 409written.
410410
411 >>> ufs.writefile(testfile, StringIO("MOO"), 9)411 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9)
412 >>> open(full_testfile).read() == "contents MOO"412 >>> open(full_testfile).read() == "contents MOO"
413 True413 True
414 >>> ufs.writefile(testfile, StringIO(testfile_contents))414 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
415415
416If `start` is specified and the file doesn't exist or is shorter416If `start` is specified and the file doesn't exist or is shorter
417than start, the file will contain undefined data before start.417than start, the file will contain undefined data before start.
418418
419 >>> ufs.writefile("didnt-exist", StringIO("MOO"), 9)419 >>> ufs.writefile("didnt-exist", io.BytesIO(b"MOO"), 9)
420 >>> open(os.path.join(rootpath, "didnt-exist")).read() == "\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO"420 >>> open(os.path.join(rootpath, "didnt-exist"), "rb").read() == (
421 ... b"\x00\x00\x00\x00\x00\x00\x00\x00\x00MOO")
421 True422 True
422 >>> ufs.remove("didnt-exist")423 >>> ufs.remove("didnt-exist")
423424
424If `end` is not None and there isn't enough data in `instream` to fill425If `end` is not None and there isn't enough data in `instream` to fill
425out the file, then the missing data is undefined.426out the file, then the missing data is undefined.
426427
427 >>> ufs.writefile(testfile, StringIO("MOO"), 9, 15)428 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 15)
428 >>> open(full_testfile).read() == "contents MOOthe file"429 >>> open(full_testfile, "rb").read() == b"contents MOOthe file"
429 True430 True
430 >>> ufs.writefile(testfile, StringIO(testfile_contents))431 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
431432
432If `end` is less than or the same as `start no data is writen to the file.433If `end` is less than or the same as `start no data is writen to the file.
433434
434 >>> ufs.writefile(testfile, StringIO("MOO"), 9, 4)435 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 4)
435 >>> open(full_testfile).read() == "contents of the file"436 >>> open(full_testfile, "rb").read() == b"contents of the file"
436 True437 True
437438
438 >>> ufs.writefile(testfile, StringIO("MOO"), 9, 9)439 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 9, 9)
439 >>> open(full_testfile).read() == "contents of the file"440 >>> open(full_testfile, "rb").read() == b"contents of the file"
440 True441 True
441442
442If `append` is true the file is appended to rather than being443If `append` is true the file is appended to rather than being
443overwritten.444overwritten.
444445
445 >>> ufs.writefile(testfile, StringIO("MOO"), append=True)446 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), append=True)
446 >>> open(full_testfile).read() == "contents of the fileMOO"447 >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
447 True448 True
448 >>> ufs.writefile(testfile, StringIO(testfile_contents))449 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
449450
450Additionally, if `append` is true, `start` and `end` are ignored.451Additionally, if `append` is true, `start` and `end` are ignored.
451452
452 >>> ufs.writefile(testfile, StringIO("MOO"), 10, 13, append=True)453 >>> ufs.writefile(testfile, io.BytesIO(b"MOO"), 10, 13, append=True)
453 >>> open(full_testfile).read() == "contents of the fileMOO"454 >>> open(full_testfile, "rb").read() == b"contents of the fileMOO"
454 True455 True
455 >>> ufs.writefile(testfile, StringIO(testfile_contents))456 >>> ufs.writefile(testfile, io.BytesIO(testfile_contents))
456457
457'writefile' is able to create inexistent directories in a requested458'writefile' is able to create inexistent directories in a requested
458path:459path:
459460
460 >>> os.path.exists(os.path.join(rootpath, "foo"))461 >>> os.path.exists(os.path.join(rootpath, "foo"))
461 False462 False
462 >>> ufs.writefile("foo/bar", StringIO("fake")) is None463 >>> ufs.writefile("foo/bar", io.BytesIO(b"fake"))
463 True
464 >>> os.path.exists(os.path.join(rootpath, "foo/bar"))464 >>> os.path.exists(os.path.join(rootpath, "foo/bar"))
465 True465 True
466 >>> open(os.path.join(rootpath, "foo/bar")).read()466 >>> open(os.path.join(rootpath, "foo/bar"), "rb").read() == b"fake"
467 'fake'467 True
468468
469469
470writable470writable
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 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4from __future__ import absolute_import, print_function, unicode_literals
5
4__metaclass__ = type6__metaclass__ = type
57
6from collections import defaultdict8from collections import defaultdict
7from functools import partial9from functools import partial
10import io
8import os11import os
9import shutil12import shutil
10import stat13import stat
11import StringIO
12import sys14import sys
13import tempfile15import tempfile
14from textwrap import dedent16from textwrap import dedent
@@ -205,7 +207,7 @@ class PkgUploadFixture(DeferringFixture):
205 self.root, "txpkgupload-access.log")207 self.root, "txpkgupload-access.log")
206 if self.extra_config is not None:208 if self.extra_config is not None:
207 deep_update(209 deep_update(
208 config, yaml.load(StringIO.StringIO(self.extra_config)))210 config, yaml.load(io.StringIO(self.extra_config)))
209 # Make some paths absolute to cope with tests running in a different211 # Make some paths absolute to cope with tests running in a different
210 # working directory.212 # working directory.
211 for key in ("host_key_private", "host_key_public"):213 for key in ("host_key_private", "host_key_public"):
@@ -561,7 +563,6 @@ class TestPkgUploadServiceMakerMixin:
561 'test-source_0.1_source.changes']563 'test-source_0.1_source.changes']
562564
563 for upload in files:565 for upload in files:
564 fake_file = StringIO.StringIO(upload)
565 file_to_upload = "~ppa-user/ppa/ubuntu/%s" % upload566 file_to_upload = "~ppa-user/ppa/ubuntu/%s" % upload
566 yield self.server.createFile(567 yield self.server.createFile(
567 client, file_to_upload, upload.encode("ASCII"))568 client, file_to_upload, upload.encode("ASCII"))

Subscribers

People subscribed via source and target branches

to all changes: