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
diff --git a/lib/lp/services/daemons/tachandler.py b/lib/lp/services/daemons/tachandler.py
index 45b15e2..46ee2b5 100644
--- a/lib/lp/services/daemons/tachandler.py
+++ b/lib/lp/services/daemons/tachandler.py
@@ -57,8 +57,8 @@ class TacTestSetup(TacTestFixture):
57 the log file.57 the log file.
58 """58 """
59 if os.path.exists(self.logfile):59 if os.path.exists(self.logfile):
60 with open(self.logfile, 'r') as logfile:60 with open(self.logfile, 'rb') as logfile:
61 return readyservice.LOG_MAGIC in logfile.read()61 return readyservice.LOG_MAGIC.encode('UTF-8') in logfile.read()
62 else:62 else:
63 return False63 return False
6464
@@ -73,11 +73,12 @@ class TacTestSetup(TacTestFixture):
73 0 bytes.73 0 bytes.
74 """74 """
75 if os.path.exists(self.logfile):75 if os.path.exists(self.logfile):
76 log_magic_bytes = readyservice.LOG_MAGIC.encode('UTF-8')
76 with open(self.logfile, "r+b") as logfile:77 with open(self.logfile, "r+b") as logfile:
77 position = 078 position = 0
78 for line in logfile:79 for line in logfile:
79 position += len(line)80 position += len(line)
80 if readyservice.LOG_MAGIC in line:81 if log_magic_bytes in line:
81 logfile.truncate(position)82 logfile.truncate(position)
82 break83 break
83 else:84 else:
diff --git a/lib/lp/services/daemons/tests/test_tachandler.py b/lib/lp/services/daemons/tests/test_tachandler.py
index 6c6b76d..75d45a7 100644
--- a/lib/lp/services/daemons/tests/test_tachandler.py
+++ b/lib/lp/services/daemons/tests/test_tachandler.py
@@ -157,25 +157,25 @@ class TacTestSetupTestCase(testtools.TestCase):
157157
158 # Put something in the log file.158 # Put something in the log file.
159 with open(fixture.logfile, "wb") as logfile:159 with open(fixture.logfile, "wb") as logfile:
160 logfile.write("Hello\n")160 logfile.write(b"Hello\n")
161161
162 # Truncating the log does not remove the log file.162 # Truncating the log does not remove the log file.
163 fixture.truncateLog()163 fixture.truncateLog()
164 self.assertTrue(exists(fixture.logfile))164 self.assertTrue(exists(fixture.logfile))
165 with open(fixture.logfile, "rb") as logfile:165 with open(fixture.logfile, "rb") as logfile:
166 self.assertEqual("", logfile.read())166 self.assertEqual(b"", logfile.read())
167167
168 # Put something in the log again, along with LOG_MAGIC.168 # Put something in the log again, along with LOG_MAGIC.
169 with open(fixture.logfile, "wb") as logfile:169 with open(fixture.logfile, "wb") as logfile:
170 logfile.write("One\n")170 logfile.write(b"One\n")
171 logfile.write("Two\n")171 logfile.write(b"Two\n")
172 logfile.write("Three, %s\n" % LOG_MAGIC)172 logfile.write(b"Three, %s\n" % LOG_MAGIC.encode("UTF-8"))
173 logfile.write("Four\n")173 logfile.write(b"Four\n")
174174
175 # Truncating the log leaves everything up to and including the line175 # Truncating the log leaves everything up to and including the line
176 # containing LOG_MAGIC.176 # containing LOG_MAGIC.
177 fixture.truncateLog()177 fixture.truncateLog()
178 with open(fixture.logfile, "rb") as logfile:178 with open(fixture.logfile, "rb") as logfile:
179 self.assertEqual(179 self.assertEqual(
180 "One\nTwo\nThree, %s\n" % LOG_MAGIC,180 b"One\nTwo\nThree, %s\n" % LOG_MAGIC.encode("UTF-8"),
181 logfile.read())181 logfile.read())

Subscribers

People subscribed via source and target branches

to status/vote changes: