Make test_env compatible with python 2 & 3

Use the vendored copy of the `six` library to make this code work across
Python versions.

Bug: 942720
Change-Id: I4bdb1032ed8e89e733b929eb13ada54efeb3b019
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229335
Commit-Queue: Chris McDonald <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Ben Pastene <[email protected]>
Cr-Commit-Position: refs/heads/master@{#774934}
diff --git a/testing/test_env_unittest.py b/testing/test_env_unittest.py
index 76d5766..707c65e 100755
--- a/testing/test_env_unittest.py
+++ b/testing/test_env_unittest.py
@@ -17,20 +17,29 @@
 import time
 import unittest
 
-
-TEST_SCRIPT = 'test_env_user_script.py'
+HERE = os.path.dirname(os.path.abspath(__file__))
+TEST_SCRIPT = os.path.join(HERE, 'test_env_user_script.py')
 
 
 def launch_process_windows(args):
+  # The `universal_newlines` option is equivalent to `text` in Python 3.
   return subprocess.Popen(
-      [sys.executable, TEST_SCRIPT] + args, stdout=subprocess.PIPE,
-      stderr=subprocess.STDOUT, env=os.environ.copy(),
-      creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
+      [sys.executable, TEST_SCRIPT] + args,
+      stdout=subprocess.PIPE,
+      stderr=subprocess.STDOUT,
+      env=os.environ.copy(),
+      creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
+      universal_newlines=True)
+
 
 def launch_process_nonwindows(args):
+  # The `universal_newlines` option is equivalent to `text` in Python 3.
   return subprocess.Popen(
-      [sys.executable, TEST_SCRIPT] + args, stdout=subprocess.PIPE,
-      stderr=subprocess.STDOUT, env=os.environ.copy())
+      [sys.executable, TEST_SCRIPT] + args,
+      stdout=subprocess.PIPE,
+      stderr=subprocess.STDOUT,
+      env=os.environ.copy(),
+      universal_newlines=True)
 
 
 def read_subprocess_message(proc, starts_with):
@@ -58,7 +67,7 @@
     proc = launch_process_windows([])
     send_and_wait(proc, signal.CTRL_BREAK_EVENT)
     sig = read_subprocess_message(proc, 'Signal :')
-    self.assertEqual(sig, str(signal.SIGBREAK))
+    self.assertEqual(sig, str(int(signal.SIGBREAK)))
 
 
 class SignalingNonWindowsTest(unittest.TestCase):
@@ -72,13 +81,13 @@
     proc = launch_process_nonwindows([])
     send_and_wait(proc, signal.SIGTERM)
     sig = read_subprocess_message(proc, 'Signal :')
-    self.assertEqual(sig, str(signal.SIGTERM))
+    self.assertEqual(sig, str(int(signal.SIGTERM)))
 
   def test_send_sigint(self):
     proc = launch_process_nonwindows([])
     send_and_wait(proc, signal.SIGINT)
     sig = read_subprocess_message(proc, 'Signal :')
-    self.assertEqual(sig, str(signal.SIGINT))
+    self.assertEqual(sig, str(int(signal.SIGINT)))
 
 
 if __name__ == '__main__':