Make diff_test_trace_processor Python 3 compatible.
Test: python3 tools/diff_test_trace_processor.py out/linux_clang_release/trace_processor_shell
Change-Id: I6071b8c5045bb4975d40af79bd21215e232fe9c3
diff --git a/tools/diff_test_trace_processor.py b/tools/diff_test_trace_processor.py
index ea1f5b5..9b98644 100755
--- a/tools/diff_test_trace_processor.py
+++ b/tools/diff_test_trace_processor.py
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
import argparse
import datetime
import difflib
@@ -135,7 +139,7 @@
if json_output:
expected_text = expected
- actual_text = stdout
+ actual_text = stdout.decode('utf8')
else:
# Expected will be in text proto format and we'll need to parse it to a real
# proto.
@@ -152,7 +156,7 @@
actual_text = text_format.MessageToString(actual_message)
return TestResult('metric', metric, gen_trace_path, cmd, expected_text,
- actual_text, stderr, tp.returncode)
+ actual_text, stderr.decode('utf8'), tp.returncode)
def run_query_test(trace_processor_path, gen_trace_path, query_path,
@@ -171,8 +175,8 @@
tp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = tp.communicate()
- return TestResult('query', query_path, gen_trace_path, cmd, expected, stdout,
- stderr, tp.returncode)
+ return TestResult('query', query_path, gen_trace_path, cmd, expected,
+ stdout.decode('utf8'), stderr.decode('utf8'), tp.returncode)
def run_all_tests(trace_processor, trace_descriptor_path,
@@ -228,11 +232,11 @@
else:
assert False
- perf_lines = tmp_perf_file.readlines()
+ perf_lines = [line.decode('utf8') for line in tmp_perf_file.readlines()]
if gen_trace_file:
if keep_input:
- print "Saving generated input trace: ", gen_trace_path
+ print("Saving generated input trace: {}".format(gen_trace_path))
else:
gen_trace_file.close()
os.remove(gen_trace_path)