Merge lp:~allenap/maas/restore-content-from-file into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5652
Proposed branch: lp:~allenap/maas/restore-content-from-file
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 66 lines (+38/-0)
2 files modified
src/maastesting/tests/test_parallel.py (+19/-0)
src/maastesting/utils.py (+19/-0)
To merge this branch: bzr merge lp:~allenap/maas/restore-content-from-file
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+315385@code.launchpad.net

Commit message

Restore content_from_file; test.parallel uses it.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Selfie: undoing part of a branch I landed earlier.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/maastesting/tests/test_parallel.py'
2--- src/maastesting/tests/test_parallel.py 1970-01-01 00:00:00 +0000
3+++ src/maastesting/tests/test_parallel.py 2017-01-23 16:40:51 +0000
4@@ -0,0 +1,19 @@
5+# Copyright 2017 Canonical Ltd. This software is licensed under the
6+# GNU Affero General Public License version 3 (see the file LICENSE).
7+
8+"""Tests for `maastesting.parallel`."""
9+
10+__all__ = []
11+
12+import types
13+
14+from maastesting.testcase import MAASTestCase
15+from testtools.matchers import IsInstance
16+
17+
18+class TestSmoke(MAASTestCase):
19+ """Trivial smoke test."""
20+
21+ def test_imports_cleanly(self):
22+ from maastesting import parallel
23+ self.assertThat(parallel, IsInstance(types.ModuleType))
24
25=== modified file 'src/maastesting/utils.py'
26--- src/maastesting/utils.py 2017-01-06 09:50:17 +0000
27+++ src/maastesting/utils.py 2017-01-23 16:40:51 +0000
28@@ -5,6 +5,7 @@
29
30 __all__ = [
31 "age_file",
32+ "content_from_file",
33 "extract_word_list",
34 "sample_binary_data",
35 ]
36@@ -13,6 +14,9 @@
37 import os
38 import re
39
40+from testtools.content import Content
41+from testtools.content_type import UTF8_TEXT
42+
43
44 def age_file(path, seconds):
45 """Backdate a file's modification time so that it looks older."""
46@@ -22,6 +26,21 @@
47 os.utime(path, (atime, mtime - seconds))
48
49
50+def content_from_file(path):
51+ """Alternative to testtools' version.
52+
53+ This keeps an open file-handle, so it can obtain the log even when the
54+ file has been unlinked.
55+ """
56+ fd = open(path, "rb")
57+
58+ def iterate():
59+ fd.seek(0)
60+ return iter(fd)
61+
62+ return Content(UTF8_TEXT, iterate)
63+
64+
65 def extract_word_list(string):
66 """Return a list of words from a string.
67