From 0927b7eef86dd283507fda2fc71cc7b502aab23c Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Fri, 11 Nov 2011 16:06:22 +0000 Subject: [PATCH] Create a new testing_support module to move utility modules there It will simplify importing utility modules from other projects. Otherwise I was getting name conflicts with 'test'. Reenable W0403 that was disabled in the previous CL. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/8508015 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@109636 0039d316-1c4b-4281-b951-d872f2087c98 --- .gitignore | 2 +- PRESUBMIT.py | 4 ++-- pylintrc | 3 +-- testing_support/__init__.py | 0 {tests => testing_support}/fake_repos.py | 2 +- {tests => testing_support}/filesystem_mock.py | 0 {tests => testing_support}/local_rietveld.py | 1 - {tests => testing_support}/patches_data.py | 0 {tests => testing_support}/super_mox.py | 5 +++-- {tests => testing_support}/trial_dir.py | 0 tests/breakpad_unittest.py | 2 +- tests/checkout_test.py | 5 +++-- tests/gcl_unittest.py | 2 +- tests/gclient_scm_test.py | 4 ++-- tests/gclient_smoketest.py | 2 +- tests/gclient_test.py | 2 +- tests/gclient_utils_test.py | 4 ++-- tests/owners_unittest.py | 3 ++- tests/patch_test.py | 3 ++- tests/presubmit_unittest.py | 2 +- tests/rietveld_test.py | 3 ++- tests/scm_unittest.py | 4 ++-- tests/trychange_unittest.py | 2 +- tests/watchlists_unittest.py | 3 ++- 24 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 testing_support/__init__.py rename {tests => testing_support}/fake_repos.py (99%) rename {tests => testing_support}/filesystem_mock.py (100%) rename {tests => testing_support}/local_rietveld.py (98%) rename {tests => testing_support}/patches_data.py (100%) rename {tests => testing_support}/super_mox.py (98%) rename {tests => testing_support}/trial_dir.py (100%) diff --git a/.gitignore b/.gitignore index 05d36f9ce..6e0f3d757 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ /svn.bat /svn_bin /svnversion.bat -/tests/_rietveld +/depot_tools_testing_lib/_rietveld /tests/subversion_config/README.txt /tests/subversion_config/auth /tests/subversion_config/servers diff --git a/PRESUBMIT.py b/PRESUBMIT.py index b80c836c7..18a3d3833 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -29,7 +29,7 @@ def CommonChecks(input_api, output_api, tests_to_black_list): r'^cpplint_chromium\.py$', r'^python_bin[\/\\].+', r'^svn_bin[\/\\].+', - r'^tests[\/\\]\w+?[\/\\].+'] + r'^testing_support[\/\\]_rietveld[\/\\].+'] results.extend(input_api.canned_checks.RunPylint( input_api, output_api, @@ -59,7 +59,7 @@ def RunGitClTests(input_api, output_api): old_sys_path = sys.path try: sys.path = [input_api.PresubmitLocalPath()] + sys.path - from tests import local_rietveld # pylint: disable=W0403 + from testing_support import local_rietveld server = local_rietveld.LocalRietveld() finally: sys.path = old_sys_path diff --git a/pylintrc b/pylintrc index 74d1ec2bc..0412be85b 100644 --- a/pylintrc +++ b/pylintrc @@ -57,14 +57,13 @@ load-plugins= # W0141: Used builtin function '' # W0142: Used * or ** magic # W0402: Uses of a deprecated module 'string' -# W0403: Relative import 'X', should be 'Y.X' # W0404: 41: Reimport 'XX' (imported line NN) # W0511: TODO # W0603: Using the global statement # W0613: Unused argument '' # W0703: Catch "Exception" # W1201: Specify string format arguments as logging function parameters -disable=C0103,C0111,C0302,I0010,I0011,R0401,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,W0122,W0141,W0142,W0402,W0403,W0404,W0511,W0603,W0613,W0703,W1201 +disable=C0103,C0111,C0302,I0010,I0011,R0401,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,W0122,W0141,W0142,W0402,W0404,W0511,W0603,W0613,W0703,W1201 [REPORTS] diff --git a/testing_support/__init__.py b/testing_support/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/fake_repos.py b/testing_support/fake_repos.py similarity index 99% rename from tests/fake_repos.py rename to testing_support/fake_repos.py index 2828cba3f..a5af11fe3 100755 --- a/tests/fake_repos.py +++ b/testing_support/fake_repos.py @@ -18,7 +18,7 @@ import tempfile import time # trial_dir must be first for non-system libraries. -from tests import trial_dir +from testing_support import trial_dir import gclient_utils import scm import subprocess2 diff --git a/tests/filesystem_mock.py b/testing_support/filesystem_mock.py similarity index 100% rename from tests/filesystem_mock.py rename to testing_support/filesystem_mock.py diff --git a/tests/local_rietveld.py b/testing_support/local_rietveld.py similarity index 98% rename from tests/local_rietveld.py rename to testing_support/local_rietveld.py index 922a3d1ae..2a1c07af0 100755 --- a/tests/local_rietveld.py +++ b/testing_support/local_rietveld.py @@ -16,7 +16,6 @@ import socket import sys import time -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) import subprocess2 diff --git a/tests/patches_data.py b/testing_support/patches_data.py similarity index 100% rename from tests/patches_data.py rename to testing_support/patches_data.py diff --git a/tests/super_mox.py b/testing_support/super_mox.py similarity index 98% rename from tests/super_mox.py rename to testing_support/super_mox.py index 62113e210..433c675bf 100644 --- a/tests/super_mox.py +++ b/testing_support/super_mox.py @@ -90,8 +90,9 @@ class StdoutCheck(object): def setUp(self): # Override the mock with a StringIO, it's much less painful to test. self._old_stdout = sys.stdout - sys.stdout = StringIO.StringIO() - sys.stdout.flush = lambda: None + stdout = StringIO.StringIO() + stdout.flush = lambda: None + sys.stdout = stdout def tearDown(self): try: diff --git a/tests/trial_dir.py b/testing_support/trial_dir.py similarity index 100% rename from tests/trial_dir.py rename to testing_support/trial_dir.py diff --git a/tests/breakpad_unittest.py b/tests/breakpad_unittest.py index 44a3ba844..4d59c0b85 100755 --- a/tests/breakpad_unittest.py +++ b/tests/breakpad_unittest.py @@ -10,7 +10,7 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import SuperMoxTestBase +from testing_support.super_mox import SuperMoxTestBase import breakpad diff --git a/tests/checkout_test.py b/tests/checkout_test.py index 5de734a00..939c0b7c4 100755 --- a/tests/checkout_test.py +++ b/tests/checkout_test.py @@ -16,11 +16,12 @@ from xml.etree import ElementTree ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(ROOT_DIR)) +from testing_support import fake_repos +from testing_support.patches_data import GIT, RAW + import checkout import patch import subprocess2 -from tests import fake_repos -from tests.patches_data import GIT, RAW # pass -v to enable it. diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py index a2fde152c..2333bf3bd 100755 --- a/tests/gcl_unittest.py +++ b/tests/gcl_unittest.py @@ -12,7 +12,7 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import mox, SuperMoxTestBase +from testing_support.super_mox import mox, SuperMoxTestBase import gcl import presubmit_support diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 4c57c3d01..a44754f1d 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -21,8 +21,8 @@ import __builtin__ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import mox, StdoutCheck, SuperMoxTestBase -from super_mox import TestCaseUtils +from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase +from testing_support.super_mox import TestCaseUtils import gclient_scm import subprocess2 diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 41c49bcbc..db07be0af 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -20,7 +20,7 @@ import unittest ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, ROOT_DIR) -from fake_repos import join, write, FakeReposTestBase +from testing_support.fake_repos import join, write, FakeReposTestBase import subprocess2 diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 7067785dc..657b9815f 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -19,7 +19,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import gclient import gclient_utils -from tests import trial_dir +from testing_support import trial_dir def write(filename, content): diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index caf04b64f..023f7e979 100755 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -9,8 +9,8 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import SuperMoxTestBase -import trial_dir +from testing_support.super_mox import SuperMoxTestBase +from testing_support import trial_dir import gclient_utils import subprocess2 diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index aa623f544..c9a0f3f3d 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -11,8 +11,9 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from testing_support import filesystem_mock + import owners -from tests import filesystem_mock ben = 'ben@example.com' brett = 'brett@example.com' diff --git a/tests/patch_test.py b/tests/patch_test.py index 3286f6bb2..6cc829235 100755 --- a/tests/patch_test.py +++ b/tests/patch_test.py @@ -13,8 +13,9 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from testing_support.patches_data import GIT, RAW + import patch -from tests.patches_data import GIT, RAW class PatchTest(unittest.TestCase): diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 57660bb7d..83bbb6f2a 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -15,7 +15,7 @@ import time sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import mox, SuperMoxTestBase +from testing_support.super_mox import mox, SuperMoxTestBase import owners import presubmit_support as presubmit diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py index 84d5d6365..5f6bb0480 100755 --- a/tests/rietveld_test.py +++ b/tests/rietveld_test.py @@ -12,9 +12,10 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from testing_support.patches_data import GIT, RAW + import patch import rietveld -from tests.patches_data import GIT, RAW def _api(files): diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 2349beb2a..78d5d4dc9 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -13,9 +13,9 @@ import unittest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import SuperMoxTestBase +from testing_support import fake_repos +from testing_support.super_mox import SuperMoxTestBase -import fake_repos import scm import subprocess2 diff --git a/tests/trychange_unittest.py b/tests/trychange_unittest.py index c7330e13d..f483664a5 100755 --- a/tests/trychange_unittest.py +++ b/tests/trychange_unittest.py @@ -10,7 +10,7 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from super_mox import SuperMoxTestBase +from testing_support.super_mox import SuperMoxTestBase import subprocess2 import trychange diff --git a/tests/watchlists_unittest.py b/tests/watchlists_unittest.py index e72bb8bab..eac4fd809 100755 --- a/tests/watchlists_unittest.py +++ b/tests/watchlists_unittest.py @@ -12,7 +12,8 @@ import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import super_mox +from testing_support import super_mox + import watchlists