diff options
author | Richard Belleville <gnossen@gmail.com> | 2018-11-05 16:54:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-05 16:54:05 -0800 |
commit | 6b934a8361ae0908dc59626351355f615b87dd43 (patch) | |
tree | 6b4323fd03cd8e7d8cfa85226c9197297700b76e | |
parent | a04a928cf387a845931ad10490f2ba4b0f472a16 (diff) | |
parent | 762b269525c011f5fab3acf1c77763942651da3d (diff) |
Merge pull request #17088 from grpc/tools_py3_2
Make run_tests.py python-version agnostic
-rwxr-xr-x | tools/gcp/utils/big_query_utils.py | 28 | ||||
-rwxr-xr-x | tools/run_tests/python_utils/jobset.py | 6 | ||||
-rwxr-xr-x | tools/run_tests/python_utils/port_server.py | 16 | ||||
-rw-r--r-- | tools/run_tests/python_utils/report_utils.py | 2 | ||||
-rw-r--r-- | tools/run_tests/python_utils/start_port_server.py | 19 | ||||
-rwxr-xr-x | tools/run_tests/python_utils/watch_dirs.py | 3 | ||||
-rwxr-xr-x | tools/run_tests/run_tests.py | 6 |
7 files changed, 42 insertions, 38 deletions
diff --git a/tools/gcp/utils/big_query_utils.py b/tools/gcp/utils/big_query_utils.py index 3e811ca2bf..6e9cda376b 100755 --- a/tools/gcp/utils/big_query_utils.py +++ b/tools/gcp/utils/big_query_utils.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + import argparse import json import uuid @@ -50,11 +52,11 @@ def create_dataset(biq_query, project_id, dataset_id): dataset_req.execute(num_retries=NUM_RETRIES) except HttpError as http_error: if http_error.resp.status == 409: - print 'Warning: The dataset %s already exists' % dataset_id + print('Warning: The dataset %s already exists' % dataset_id) else: # Note: For more debugging info, print "http_error.content" - print 'Error in creating dataset: %s. Err: %s' % (dataset_id, - http_error) + print('Error in creating dataset: %s. Err: %s' % (dataset_id, + http_error)) is_success = False return is_success @@ -122,13 +124,13 @@ def create_table2(big_query, table_req = big_query.tables().insert( projectId=project_id, datasetId=dataset_id, body=body) res = table_req.execute(num_retries=NUM_RETRIES) - print 'Successfully created %s "%s"' % (res['kind'], res['id']) + print('Successfully created %s "%s"' % (res['kind'], res['id'])) except HttpError as http_error: if http_error.resp.status == 409: - print 'Warning: Table %s already exists' % table_id + print('Warning: Table %s already exists' % table_id) else: - print 'Error in creating table: %s. Err: %s' % (table_id, - http_error) + print('Error in creating table: %s. Err: %s' % (table_id, + http_error)) is_success = False return is_success @@ -154,9 +156,9 @@ def patch_table(big_query, project_id, dataset_id, table_id, fields_schema): tableId=table_id, body=body) res = table_req.execute(num_retries=NUM_RETRIES) - print 'Successfully patched %s "%s"' % (res['kind'], res['id']) + print('Successfully patched %s "%s"' % (res['kind'], res['id'])) except HttpError as http_error: - print 'Error in creating table: %s. Err: %s' % (table_id, http_error) + print('Error in creating table: %s. Err: %s' % (table_id, http_error)) is_success = False return is_success @@ -172,10 +174,10 @@ def insert_rows(big_query, project_id, dataset_id, table_id, rows_list): body=body) res = insert_req.execute(num_retries=NUM_RETRIES) if res.get('insertErrors', None): - print 'Error inserting rows! Response: %s' % res + print('Error inserting rows! Response: %s' % res) is_success = False except HttpError as http_error: - print 'Error inserting rows to the table %s' % table_id + print('Error inserting rows to the table %s' % table_id) is_success = False return is_success @@ -189,8 +191,8 @@ def sync_query_job(big_query, project_id, query, timeout=5000): projectId=project_id, body=query_data).execute(num_retries=NUM_RETRIES) except HttpError as http_error: - print 'Query execute job failed with error: %s' % http_error - print http_error.content + print('Query execute job failed with error: %s' % http_error) + print(http_error.content) return query_job diff --git a/tools/run_tests/python_utils/jobset.py b/tools/run_tests/python_utils/jobset.py index b732e1e03e..578712c393 100755 --- a/tools/run_tests/python_utils/jobset.py +++ b/tools/run_tests/python_utils/jobset.py @@ -13,8 +13,6 @@ # limitations under the License. """Run a group of subprocesses and then finish.""" -from __future__ import print_function - import logging import multiprocessing import os @@ -118,7 +116,7 @@ def eintr_be_gone(fn): while True: try: return fn() - except IOError, e: + except IOError as e: if e.errno != errno.EINTR: raise @@ -144,7 +142,7 @@ def message(tag, msg, explanatory_text=None, do_newline=False): if do_newline or explanatory_text is not None else '')) sys.stdout.flush() return - except IOError, e: + except IOError as e: if e.errno != errno.EINTR: raise diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index 83e09c09d0..243eef6827 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -14,15 +14,17 @@ # limitations under the License. """Manage TCP ports for unit tests; started by run_tests.py""" +from __future__ import print_function + import argparse -from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler +from six.moves.BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler +from six.moves.socketserver import ThreadingMixIn import hashlib import os import socket import sys import time import random -from SocketServer import ThreadingMixIn import threading import platform @@ -32,7 +34,7 @@ import platform _MY_VERSION = 20 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': - print _MY_VERSION + print(_MY_VERSION) sys.exit(0) argp = argparse.ArgumentParser(description='Server for httpcli_test') @@ -47,7 +49,7 @@ if args.logfile is not None: sys.stderr = open(args.logfile, 'w') sys.stdout = sys.stderr -print 'port server running on port %d' % args.port +print('port server running on port %d' % args.port) pool = [] in_use = {} @@ -74,7 +76,7 @@ def can_connect(port): try: s.connect(('localhost', port)) return True - except socket.error, e: + except socket.error as e: return False finally: s.close() @@ -86,7 +88,7 @@ def can_bind(port, proto): try: s.bind(('localhost', port)) return True - except socket.error, e: + except socket.error as e: return False finally: s.close() @@ -95,7 +97,7 @@ def can_bind(port, proto): def refill_pool(max_timeout, req): """Scan for ports not marked for being in use""" chk = [ - port for port in list(range(1025, 32766)) + port for port in range(1025, 32766) if port not in cronet_restricted_ports ] random.shuffle(chk) diff --git a/tools/run_tests/python_utils/report_utils.py b/tools/run_tests/python_utils/report_utils.py index b2a256ce29..8d8dedb929 100644 --- a/tools/run_tests/python_utils/report_utils.py +++ b/tools/run_tests/python_utils/report_utils.py @@ -13,8 +13,6 @@ # limitations under the License. """Generate XML and HTML test reports.""" -from __future__ import print_function - try: from mako.runtime import Context from mako.template import Template diff --git a/tools/run_tests/python_utils/start_port_server.py b/tools/run_tests/python_utils/start_port_server.py index 37995acbdf..0a32bf4418 100644 --- a/tools/run_tests/python_utils/start_port_server.py +++ b/tools/run_tests/python_utils/start_port_server.py @@ -12,8 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import urllib -import jobset +from __future__ import print_function + +from . import jobset + +import six.moves.urllib.request as request import logging import os import socket @@ -33,8 +36,8 @@ def start_port_server(): # otherwise, leave it up try: version = int( - urllib.urlopen('http://localhost:%d/version_number' % - _PORT_SERVER_PORT).read()) + request.urlopen('http://localhost:%d/version_number' % + _PORT_SERVER_PORT).read()) logging.info('detected port server running version %d', version) running = True except Exception as e: @@ -51,7 +54,7 @@ def start_port_server(): running = (version >= current_version) if not running: logging.info('port_server version mismatch: killing the old one') - urllib.urlopen( + request.urlopen( 'http://localhost:%d/quitquitquit' % _PORT_SERVER_PORT).read() time.sleep(1) if not running: @@ -92,7 +95,7 @@ def start_port_server(): # try one final time: maybe another build managed to start one time.sleep(1) try: - urllib.urlopen( + request.urlopen( 'http://localhost:%d/get' % _PORT_SERVER_PORT).read() logging.info( 'last ditch attempt to contact port server succeeded') @@ -101,11 +104,11 @@ def start_port_server(): logging.exception( 'final attempt to contact port server failed') port_log = open(logfile, 'r').read() - print port_log + print(port_log) sys.exit(1) try: port_server_url = 'http://localhost:%d/get' % _PORT_SERVER_PORT - urllib.urlopen(port_server_url).read() + request.urlopen(port_server_url).read() logging.info('port server is up and ready') break except socket.timeout: diff --git a/tools/run_tests/python_utils/watch_dirs.py b/tools/run_tests/python_utils/watch_dirs.py index d2ad303a07..f2f1c006df 100755 --- a/tools/run_tests/python_utils/watch_dirs.py +++ b/tools/run_tests/python_utils/watch_dirs.py @@ -15,13 +15,14 @@ import os import time +from six import string_types class DirWatcher(object): """Helper to watch a (set) of directories for modifications.""" def __init__(self, paths): - if isinstance(paths, basestring): + if isinstance(paths, string_types): paths = [paths] self._done = False self.paths = list(paths) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 44151f49fb..62bb6da7a7 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1512,7 +1512,7 @@ if args.travis: _FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'api'} if 'all' in args.language: - lang_list = _LANGUAGES.keys() + lang_list = list(_LANGUAGES.keys()) else: lang_list = args.language # We don't support code coverage on some languages @@ -1719,9 +1719,9 @@ def _has_epollexclusive(): try: subprocess.check_call(binary) return True - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: return False - except OSError, e: + except OSError as e: # For languages other than C and Windows the binary won't exist return False |