Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/framework/test/filecontent_test.py b/framework/test/filecontent_test.py
index 4843b47..f2c8d9e 100644
--- a/framework/test/filecontent_test.py
+++ b/framework/test/filecontent_test.py
@@ -1,13 +1,13 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """Tests for the filecontent module."""
 from __future__ import print_function
 from __future__ import division
 from __future__ import absolute_import
 
+import six
 import unittest
 
 from framework import filecontent
@@ -84,10 +84,10 @@
     return is_binary
 
   def testFileIsBinaryEmpty(self):
-    self.assertFalse(self.IsBinary(''))
+    self.assertFalse(self.IsBinary(b''))
 
   def testFileIsBinaryShortText(self):
-    self.assertFalse(self.IsBinary('This is some plain text.'))
+    self.assertFalse(self.IsBinary(b'This is some plain text.'))
 
   def testLineLengthDetection(self):
     unicode_str = (
@@ -101,29 +101,35 @@
     lines.append(long_line)
 
     # High lower ratio - text
-    self.assertFalse(self.IsBinary('\n'.join(lines)))
+    self.assertFalse(self.IsBinary(b'\n'.join(lines)))
 
     lines.extend([long_line] * 99)
 
     # 50/50 lower/upper ratio - binary
-    self.assertTrue(self.IsBinary('\n'.join(lines)))
+    self.assertTrue(self.IsBinary(b'\n'.join(lines)))
 
     # Single line too long - binary
     lines = [short_line] * 100
     lines.append(short_line * 100)  # Very long line
-    self.assertTrue(self.IsBinary('\n'.join(lines)))
+    self.assertTrue(self.IsBinary(b'\n'.join(lines)))
 
   def testFileIsBinaryLongText(self):
-    self.assertFalse(self.IsBinary('This is plain text. \n' * 100))
+    self.assertFalse(self.IsBinary(b'This is plain text. \n' * 100))
     # long utf-8 lines are OK
-    self.assertFalse(self.IsBinary('This one long line. ' * 100))
+    self.assertFalse(self.IsBinary(b'This one long line. ' * 100))
 
   def testFileIsBinaryLongBinary(self):
-    bin_string = ''.join([chr(c) for c in range(122, 252)])
+    if six.PY2:
+      bin_string = ''.join([chr(c) for c in range(122, 252)])
+    else:
+      bin_string = bytes(range(122, 252))
     self.assertTrue(self.IsBinary(bin_string * 100))
 
   def testFileIsTextByPath(self):
-    bin_string = ''.join([chr(c) for c in range(122, 252)] * 100)
+    if six.PY2:
+      bin_string = ''.join([chr(c) for c in range(122, 252)] * 100)
+    else:
+      bin_string = bytes(range(122, 252)) * 100
     unicode_str = (
         u'Some non-ascii chars - '
         u'\xa2\xfa\xb6\xe7\xfc\xea\xd0\xf4\xe6\xf0\xce\xf6\xbe')
@@ -143,7 +149,7 @@
             filecontent.DecodeFileContents(contents, path=path)[1])
 
   def testFileIsBinaryByCommonExtensions(self):
-    contents = 'this is not examined'
+    contents = b'this is not examined'
     self.assertTrue(filecontent.DecodeFileContents(
         contents, path='junk.zip')[1])
     self.assertTrue(filecontent.DecodeFileContents(
@@ -175,13 +181,13 @@
         contents, path='/wiki/PageName.wiki')[1])
 
   def testUnreasonablyLongFile(self):
-    contents = '\n' * (filecontent.SOURCE_FILE_MAX_LINES + 2)
+    contents = b'\n' * (filecontent.SOURCE_FILE_MAX_LINES + 2)
     _contents, is_binary, is_long = filecontent.DecodeFileContents(
         contents)
     self.assertFalse(is_binary)
     self.assertTrue(is_long)
 
-    contents = '\n' * 100
+    contents = b'\n' * 100
     _contents, is_binary, is_long = filecontent.DecodeFileContents(
         contents)
     self.assertFalse(is_binary)