From 45d8db04f9926e6a0edcd223e0b3e4e485641150 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 31 Mar 2011 20:43:56 +0000 Subject: [PATCH] Add more python 2.5 compatibility. Makes all the tests runnable on python 2.5. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/6690034 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80068 0039d316-1c4b-4281-b951-d872f2087c98 --- subprocess2.py | 1 + tests/fake_repos.py | 14 ++++++++------ tests/filesystem_mock.py | 2 +- tests/fix_encoding_test.py | 2 +- tests/gcl_unittest.py | 4 ++-- tests/gclient_scm_test.py | 4 ++-- tests/gclient_smoketest.py | 4 ++-- tests/gclient_utils_test.py | 4 ++-- tests/owners_unittest.py | 6 +++++- tests/presubmit_unittest.py | 2 +- tests/scm_unittest.py | 11 ++++++++--- tests/super_mox.py | 3 +-- tests/trial_dir.py | 4 ++-- tests/trychange_unittest.py | 4 ++-- tests/watchlists_unittest.py | 4 ++-- 15 files changed, 40 insertions(+), 29 deletions(-) diff --git a/subprocess2.py b/subprocess2.py index d59035b487..ed34d3e98e 100644 --- a/subprocess2.py +++ b/subprocess2.py @@ -7,6 +7,7 @@ In theory you shouldn't need anything else in subprocess, or this module failed. """ +from __future__ import with_statement import logging import os import subprocess diff --git a/tests/fake_repos.py b/tests/fake_repos.py index 09d873c8e8..e5abef3498 100755 --- a/tests/fake_repos.py +++ b/tests/fake_repos.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. @@ -187,7 +187,7 @@ def wait_for_port_to_bind(host, port, process): sock.connect((host, port)) logging.debug('%d is now bound' % port) return - except EnvironmentError: + except (socket.error, EnvironmentError): pass logging.debug('%d is still not bound' % port) finally: @@ -206,7 +206,7 @@ def wait_for_port_to_free(host, port): sock = socket.socket() sock.connect((host, port)) logging.debug('%d was bound, waiting to free' % port) - except EnvironmentError: + except (socket.error, EnvironmentError): logging.debug('%d now free' % port) return finally: @@ -364,7 +364,8 @@ class FakeReposBase(object): return True try: check_call(['svnadmin', 'create', self.svn_repo]) - except OSError: + except OSError, e: + logging.debug('Failed with : %s' % e) return False write(join(self.svn_repo, 'conf', 'svnserve.conf'), '[general]\n' @@ -383,6 +384,7 @@ class FakeReposBase(object): # Start the daemon. self.svn_port = find_free_port(self.host, 10000) + logging.debug('Using port %d' % self.svn_port) cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir, '--listen-port=%d' % self.svn_port] if self.host == '127.0.0.1': @@ -452,7 +454,7 @@ class FakeReposBase(object): sock.connect((self.host, port)) # It worked, throw. assert False, '%d shouldn\'t be bound' % port - except EnvironmentError: + except (socket.error, EnvironmentError): pass finally: sock.close() diff --git a/tests/filesystem_mock.py b/tests/filesystem_mock.py index f8a3a1d87d..270b2244a0 100644 --- a/tests/filesystem_mock.py +++ b/tests/filesystem_mock.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright (c) 2011 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. @@ -8,6 +7,7 @@ import os import re import StringIO + def _RaiseNotFound(path): raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) diff --git a/tests/fix_encoding_test.py b/tests/fix_encoding_test.py index a6ee186271..d4f49f4d13 100755 --- a/tests/fix_encoding_test.py +++ b/tests/fix_encoding_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # coding=utf8 # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py index c2dbbbed24..b31aa45b43 100755 --- a/tests/gcl_unittest.py +++ b/tests/gcl_unittest.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 1c1b204579..d7d93b6789 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 3fbff36517..04bbffd157 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index 8027675b0e..b00db3c80e 100755 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index 92029bc60f..93b72fe5ad 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -1,12 +1,16 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 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. """Unit tests for owners.py.""" +import os +import sys import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + import owners from tests import filesystem_mock diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 76e5b2f401..65984ec9c0 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.5 +#!/usr/bin/env python # Copyright (c) 2011 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. diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 917e0e3bef..155d11ae7e 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -1,11 +1,15 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. """Unit tests for scm.py.""" # pylint: disable=E1101,W0403 +from __future__ import with_statement +import logging +import sys +import unittest # Fixes include path. from super_mox import SuperMoxTestBase @@ -325,7 +329,8 @@ class RealSvnTest(fake_repos.FakeReposTestBase): if __name__ == '__main__': - import unittest + if '-v' in sys.argv: + logging.basicConfig(level=logging.DEBUG) unittest.main() # vim: ts=2:sw=2:tw=80:et: diff --git a/tests/super_mox.py b/tests/super_mox.py index b1989c2954..1a18303ea0 100644 --- a/tests/super_mox.py +++ b/tests/super_mox.py @@ -1,5 +1,4 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 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. diff --git a/tests/trial_dir.py b/tests/trial_dir.py index d75c5d71b9..975a775883 100644 --- a/tests/trial_dir.py +++ b/tests/trial_dir.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/trychange_unittest.py b/tests/trychange_unittest.py index f2b52633e5..f7ba76da71 100755 --- a/tests/trychange_unittest.py +++ b/tests/trychange_unittest.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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. diff --git a/tests/watchlists_unittest.py b/tests/watchlists_unittest.py index edad68b288..7721f8471b 100755 --- a/tests/watchlists_unittest.py +++ b/tests/watchlists_unittest.py @@ -1,5 +1,5 @@ -#!/usr/bin/python -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +#!/usr/bin/env python +# Copyright (c) 2011 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.