aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/test/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'binary_search_tool/test/common.py')
-rwxr-xr-xbinary_search_tool/test/common.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/binary_search_tool/test/common.py b/binary_search_tool/test/common.py
index 5c3ff538..cf5300f5 100755
--- a/binary_search_tool/test/common.py
+++ b/binary_search_tool/test/common.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
"""Common utility functions."""
DEFAULT_OBJECT_NUMBER = 1238
@@ -9,33 +14,29 @@ WORKING_SET_FILE = 'working_set.txt'
def ReadWorkingSet():
working_set = []
- f = open(WORKING_SET_FILE, 'r')
- for l in f:
- working_set.append(int(l))
- f.close()
+ with open(WORKING_SET_FILE, 'r', encoding='utf-8') as f:
+ for l in f:
+ working_set.append(int(l))
return working_set
def WriteWorkingSet(working_set):
- f = open(WORKING_SET_FILE, 'w')
- for o in working_set:
- f.write('{0}\n'.format(o))
- f.close()
+ with open(WORKING_SET_FILE, 'w', encoding='utf-8') as f:
+ for o in working_set:
+ f.write('{0}\n'.format(o))
def ReadObjectsFile():
objects_file = []
- f = open(OBJECTS_FILE, 'r')
- for l in f:
- objects_file.append(int(l))
- f.close()
+ with open(OBJECTS_FILE, 'r', encoding='utf-8') as f:
+ for l in f:
+ objects_file.append(int(l))
return objects_file
def ReadObjectIndex(filename):
object_index = []
- f = open(filename, 'r')
- for o in f:
- object_index.append(int(o))
- f.close()
+ with open(filename, 'r', encoding='utf-8') as f:
+ for o in f:
+ object_index.append(int(o))
return object_index