Merge ~cjwatson/launchpad:py3-tac-test-setup-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: d061604c5fa675d67e9890fdc4cdc0a5b415c318
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-tac-test-setup-bytes
Merge into: launchpad:master
Diff against target: 66 lines (+11/-10)
2 files modified
lib/lp/services/daemons/tachandler.py (+4/-3)
lib/lp/services/daemons/tests/test_tachandler.py (+7/-7)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+381340@code.launchpad.net

Commit message

Fix TacTestSetup to handle log files consistently as binary

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/lib/lp/services/daemons/tachandler.py b/lib/lp/services/daemons/tachandler.py
2index 45b15e2..46ee2b5 100644
3--- a/lib/lp/services/daemons/tachandler.py
4+++ b/lib/lp/services/daemons/tachandler.py
5@@ -57,8 +57,8 @@ class TacTestSetup(TacTestFixture):
6 the log file.
7 """
8 if os.path.exists(self.logfile):
9- with open(self.logfile, 'r') as logfile:
10- return readyservice.LOG_MAGIC in logfile.read()
11+ with open(self.logfile, 'rb') as logfile:
12+ return readyservice.LOG_MAGIC.encode('UTF-8') in logfile.read()
13 else:
14 return False
15
16@@ -73,11 +73,12 @@ class TacTestSetup(TacTestFixture):
17 0 bytes.
18 """
19 if os.path.exists(self.logfile):
20+ log_magic_bytes = readyservice.LOG_MAGIC.encode('UTF-8')
21 with open(self.logfile, "r+b") as logfile:
22 position = 0
23 for line in logfile:
24 position += len(line)
25- if readyservice.LOG_MAGIC in line:
26+ if log_magic_bytes in line:
27 logfile.truncate(position)
28 break
29 else:
30diff --git a/lib/lp/services/daemons/tests/test_tachandler.py b/lib/lp/services/daemons/tests/test_tachandler.py
31index 6c6b76d..75d45a7 100644
32--- a/lib/lp/services/daemons/tests/test_tachandler.py
33+++ b/lib/lp/services/daemons/tests/test_tachandler.py
34@@ -157,25 +157,25 @@ class TacTestSetupTestCase(testtools.TestCase):
35
36 # Put something in the log file.
37 with open(fixture.logfile, "wb") as logfile:
38- logfile.write("Hello\n")
39+ logfile.write(b"Hello\n")
40
41 # Truncating the log does not remove the log file.
42 fixture.truncateLog()
43 self.assertTrue(exists(fixture.logfile))
44 with open(fixture.logfile, "rb") as logfile:
45- self.assertEqual("", logfile.read())
46+ self.assertEqual(b"", logfile.read())
47
48 # Put something in the log again, along with LOG_MAGIC.
49 with open(fixture.logfile, "wb") as logfile:
50- logfile.write("One\n")
51- logfile.write("Two\n")
52- logfile.write("Three, %s\n" % LOG_MAGIC)
53- logfile.write("Four\n")
54+ logfile.write(b"One\n")
55+ logfile.write(b"Two\n")
56+ logfile.write(b"Three, %s\n" % LOG_MAGIC.encode("UTF-8"))
57+ logfile.write(b"Four\n")
58
59 # Truncating the log leaves everything up to and including the line
60 # containing LOG_MAGIC.
61 fixture.truncateLog()
62 with open(fixture.logfile, "rb") as logfile:
63 self.assertEqual(
64- "One\nTwo\nThree, %s\n" % LOG_MAGIC,
65+ b"One\nTwo\nThree, %s\n" % LOG_MAGIC.encode("UTF-8"),
66 logfile.read())

Subscribers

People subscribed via source and target branches

to status/vote changes: