← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-tac-test-setup-bytes into launchpad:master.

Commit message:
Fix TacTestSetup to handle log files consistently as binary

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/381340
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-tac-test-setup-bytes into launchpad:master.
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):
         the log file.
         """
         if os.path.exists(self.logfile):
-            with open(self.logfile, 'r') as logfile:
-                return readyservice.LOG_MAGIC in logfile.read()
+            with open(self.logfile, 'rb') as logfile:
+                return readyservice.LOG_MAGIC.encode('UTF-8') in logfile.read()
         else:
             return False
 
@@ -73,11 +73,12 @@ class TacTestSetup(TacTestFixture):
         0 bytes.
         """
         if os.path.exists(self.logfile):
+            log_magic_bytes = readyservice.LOG_MAGIC.encode('UTF-8')
             with open(self.logfile, "r+b") as logfile:
                 position = 0
                 for line in logfile:
                     position += len(line)
-                    if readyservice.LOG_MAGIC in line:
+                    if log_magic_bytes in line:
                         logfile.truncate(position)
                         break
                 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):
 
         # Put something in the log file.
         with open(fixture.logfile, "wb") as logfile:
-            logfile.write("Hello\n")
+            logfile.write(b"Hello\n")
 
         # Truncating the log does not remove the log file.
         fixture.truncateLog()
         self.assertTrue(exists(fixture.logfile))
         with open(fixture.logfile, "rb") as logfile:
-            self.assertEqual("", logfile.read())
+            self.assertEqual(b"", logfile.read())
 
         # Put something in the log again, along with LOG_MAGIC.
         with open(fixture.logfile, "wb") as logfile:
-            logfile.write("One\n")
-            logfile.write("Two\n")
-            logfile.write("Three, %s\n" % LOG_MAGIC)
-            logfile.write("Four\n")
+            logfile.write(b"One\n")
+            logfile.write(b"Two\n")
+            logfile.write(b"Three, %s\n" % LOG_MAGIC.encode("UTF-8"))
+            logfile.write(b"Four\n")
 
         # Truncating the log leaves everything up to and including the line
         # containing LOG_MAGIC.
         fixture.truncateLog()
         with open(fixture.logfile, "rb") as logfile:
             self.assertEqual(
-                "One\nTwo\nThree, %s\n" % LOG_MAGIC,
+                b"One\nTwo\nThree, %s\n" % LOG_MAGIC.encode("UTF-8"),
                 logfile.read())
diff --git a/lib/lp/testing/html5browser.py b/lib/lp/testing/html5browser.py
index e6099e1..b314667 100644
--- a/lib/lp/testing/html5browser.py
+++ b/lib/lp/testing/html5browser.py
@@ -197,7 +197,7 @@ class Browser(WebKit.WebView):
 
     def _disconnect(self, signal=None):
         if signal is None:
-            signals = self.listeners.keys()
+            signals = list(self.listeners.keys())
         elif isinstance(signal, str):
             signals = [signal]
         for key in signals: