Commit 428342a0 authored by maruel@chromium.org's avatar maruel@chromium.org

Standardize the sys.path fix up and fix a few pylint warnings.

Disable temporarily W0403, will be reenabled on the next CL

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/8508017

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@109435 0039d316-1c4b-4281-b951-d872f2087c98
parent 8e2bb16a
...@@ -278,7 +278,7 @@ class ChangeInfo(object): ...@@ -278,7 +278,7 @@ class ChangeInfo(object):
rietveld: rietveld server for this change rietveld: rietveld server for this change
""" """
# Kept for unit test support. This is for the old format, it's deprecated. # Kept for unit test support. This is for the old format, it's deprecated.
_SEPARATOR = "\n-----\n" SEPARATOR = "\n-----\n"
def __init__(self, name, issue, patchset, description, files, local_root, def __init__(self, name, issue, patchset, description, files, local_root,
rietveld_url, needs_upload): rietveld_url, needs_upload):
...@@ -576,15 +576,15 @@ class ChangeInfo(object): ...@@ -576,15 +576,15 @@ class ChangeInfo(object):
def _LoadOldFormat(content): def _LoadOldFormat(content):
# The info files have the following format: # The info files have the following format:
# issue_id, patchset\n (, patchset is optional) # issue_id, patchset\n (, patchset is optional)
# _SEPARATOR\n # SEPARATOR\n
# filepath1\n # filepath1\n
# filepath2\n # filepath2\n
# . # .
# . # .
# filepathn\n # filepathn\n
# _SEPARATOR\n # SEPARATOR\n
# description # description
split_data = content.split(ChangeInfo._SEPARATOR, 2) split_data = content.split(ChangeInfo.SEPARATOR, 2)
if len(split_data) != 3: if len(split_data) != 3:
raise ValueError('Bad change format') raise ValueError('Bad change format')
values = { values = {
......
...@@ -662,7 +662,7 @@ class Change(object): ...@@ -662,7 +662,7 @@ class Change(object):
_AFFECTED_FILES = AffectedFile _AFFECTED_FILES = AffectedFile
# Matches key/value (or "tag") lines in changelist descriptions. # Matches key/value (or "tag") lines in changelist descriptions.
_TAG_LINE_RE = re.compile( TAG_LINE_RE = re.compile(
'^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$') '^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
scm = '' scm = ''
...@@ -683,7 +683,7 @@ class Change(object): ...@@ -683,7 +683,7 @@ class Change(object):
description_without_tags = [] description_without_tags = []
self.tags = {} self.tags = {}
for line in self._full_description.splitlines(): for line in self._full_description.splitlines():
m = self._TAG_LINE_RE.match(line) m = self.TAG_LINE_RE.match(line)
if m: if m:
self.tags[m.group('key')] = m.group('value') self.tags[m.group('key')] = m.group('value')
else: else:
......
...@@ -57,13 +57,14 @@ load-plugins= ...@@ -57,13 +57,14 @@ load-plugins=
# W0141: Used builtin function '' # W0141: Used builtin function ''
# W0142: Used * or ** magic # W0142: Used * or ** magic
# W0402: Uses of a deprecated module 'string' # W0402: Uses of a deprecated module 'string'
# W0403: Relative import 'X', should be 'Y.X'
# W0404: 41: Reimport 'XX' (imported line NN) # W0404: 41: Reimport 'XX' (imported line NN)
# W0511: TODO # W0511: TODO
# W0603: Using the global statement # W0603: Using the global statement
# W0613: Unused argument '' # W0613: Unused argument ''
# W0703: Catch "Exception" # W0703: Catch "Exception"
# W1201: Specify string format arguments as logging function parameters # 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,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,W0403,W0404,W0511,W0603,W0613,W0703,W1201
[REPORTS] [REPORTS]
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
"""Unit tests for breakpad.py.""" """Unit tests for breakpad.py."""
# pylint: disable=W0403 import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Fixes include path.
from super_mox import SuperMoxTestBase from super_mox import SuperMoxTestBase
import breakpad import breakpad
......
...@@ -14,8 +14,7 @@ import unittest ...@@ -14,8 +14,7 @@ import unittest
from xml.etree import ElementTree from xml.etree import ElementTree
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.join(ROOT_DIR, '..') sys.path.insert(0, os.path.dirname(ROOT_DIR))
sys.path.insert(0, BASE_DIR)
import checkout import checkout
import patch import patch
......
...@@ -10,8 +10,7 @@ import os ...@@ -10,8 +10,7 @@ import os
import sys import sys
import unittest import unittest
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, ROOT_DIR)
import fix_encoding import fix_encoding
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
"""Unit tests for gcl.py.""" """Unit tests for gcl.py."""
# pylint is too confused. # pylint: disable=E1103,E1101,E1120
# pylint: disable=E1101,E1103,E1120,W0212,W0403
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Fixes include path.
from super_mox import mox, SuperMoxTestBase from super_mox import mox, SuperMoxTestBase
import gcl import gcl
...@@ -180,6 +183,7 @@ class ChangeInfoUnittest(GclTestsBase): ...@@ -180,6 +183,7 @@ class ChangeInfoUnittest(GclTestsBase):
'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames',
'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests',
'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld', 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld',
'SEPARATOR',
'UpdateRietveldDescription', 'UpdateRietveldDescription',
'description', 'issue', 'name', 'description', 'issue', 'name',
'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld',
...@@ -217,7 +221,7 @@ class ChangeInfoUnittest(GclTestsBase): ...@@ -217,7 +221,7 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
gcl.os.path.exists('bleeeh').AndReturn(True) gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.gclient_utils.FileRead('bleeeh').AndReturn( gcl.gclient_utils.FileRead('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) gcl.ChangeInfo.SEPARATOR.join(["42, 53", "G b.cc"] + description))
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
# Does an upgrade. # Does an upgrade.
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
...@@ -229,7 +233,7 @@ class ChangeInfoUnittest(GclTestsBase): ...@@ -229,7 +233,7 @@ class ChangeInfoUnittest(GclTestsBase):
self.assertEquals(change_info.issue, 42) self.assertEquals(change_info.issue, 42)
self.assertEquals(change_info.patchset, 53) self.assertEquals(change_info.patchset, 53)
self.assertEquals(change_info.description, self.assertEquals(change_info.description,
gcl.ChangeInfo._SEPARATOR.join(description)) gcl.ChangeInfo.SEPARATOR.join(description))
self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')])
def testLoadEmpty(self): def testLoadEmpty(self):
...@@ -237,7 +241,7 @@ class ChangeInfoUnittest(GclTestsBase): ...@@ -237,7 +241,7 @@ class ChangeInfoUnittest(GclTestsBase):
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
gcl.os.path.exists('bleeeh').AndReturn(True) gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.gclient_utils.FileRead('bleeeh').AndReturn( gcl.gclient_utils.FileRead('bleeeh').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) gcl.ChangeInfo.SEPARATOR.join(["", "", ""]))
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
# Does an upgrade. # Does an upgrade.
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
...@@ -566,6 +570,7 @@ class CMDCommitUnittest(GclTestsBase): ...@@ -566,6 +570,7 @@ class CMDCommitUnittest(GclTestsBase):
self.assertEquals(retval, 0) self.assertEquals(retval, 0)
self.assertEquals(change_info.description, 'deescription') self.assertEquals(change_info.description, 'deescription')
# pylint: disable=W0212
self.assertFalse(change_info._deleted) self.assertFalse(change_info._deleted)
self.assertFalse(change_info._closed) self.assertFalse(change_info._closed)
...@@ -581,6 +586,7 @@ class CMDCommitUnittest(GclTestsBase): ...@@ -581,6 +586,7 @@ class CMDCommitUnittest(GclTestsBase):
self.assertEquals(retval, 0) self.assertEquals(retval, 0)
self.assertEquals(change_info.description, self.assertEquals(change_info.description,
'deescription\n\nCommitted: http://view/12345') 'deescription\n\nCommitted: http://view/12345')
# pylint: disable=W0212
self.assertTrue(change_info._deleted) self.assertTrue(change_info._deleted)
self.assertTrue(change_info._closed) self.assertTrue(change_info._closed)
......
...@@ -5,21 +5,25 @@ ...@@ -5,21 +5,25 @@
"""Unit tests for gclient_scm.py.""" """Unit tests for gclient_scm.py."""
# pylint: disable=E1101,E1103,W0403 # pylint: disable=E1103
# Import before super_mox to keep valid references. # Import before super_mox to keep valid references.
from os import rename from os import rename
from shutil import rmtree from shutil import rmtree
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import logging
import os
import sys
import tempfile import tempfile
import unittest import unittest
import __builtin__ import __builtin__
# Fixes include path. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase
from super_mox import mox, StdoutCheck, SuperMoxTestBase
from super_mox import TestCaseUtils
import logging
import sys
import gclient_scm import gclient_scm
import subprocess2 import subprocess2
...@@ -30,6 +34,7 @@ join = gclient_scm.os.path.join ...@@ -30,6 +34,7 @@ join = gclient_scm.os.path.join
class GCBaseTestCase(object): class GCBaseTestCase(object):
def assertRaisesError(self, msg, fn, *args, **kwargs): def assertRaisesError(self, msg, fn, *args, **kwargs):
"""Like unittest's assertRaises() but checks for Gclient.Error.""" """Like unittest's assertRaises() but checks for Gclient.Error."""
# pylint: disable=E1101
try: try:
fn(*args, **kwargs) fn(*args, **kwargs)
except gclient_scm.gclient_utils.Error, e: except gclient_scm.gclient_utils.Error, e:
...@@ -252,9 +257,8 @@ class SVNWrapperTestCase(BaseTestCase): ...@@ -252,9 +257,8 @@ class SVNWrapperTestCase(BaseTestCase):
gclient_scm.os.path.islink(file_path).AndReturn(False) gclient_scm.os.path.islink(file_path).AndReturn(False)
gclient_scm.os.path.isdir(file_path).AndReturn(True) gclient_scm.os.path.isdir(file_path).AndReturn(True)
gclient_scm.gclient_utils.RemoveDirectory(file_path) gclient_scm.gclient_utils.RemoveDirectory(file_path)
gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
# The mock is unbound so self is not necessary.
# pylint: disable=E1120 # pylint: disable=E1120
gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
gclient_scm.SVNWrapper.update(options, [], ['.']) gclient_scm.SVNWrapper.update(options, [], ['.'])
self.mox.ReplayAll() self.mox.ReplayAll()
......
...@@ -10,8 +10,6 @@ Shell out 'gclient' and run basic conformance tests. ...@@ -10,8 +10,6 @@ Shell out 'gclient' and run basic conformance tests.
This test assumes GClientSmokeBase.URL_BASE is valid. This test assumes GClientSmokeBase.URL_BASE is valid.
""" """
# pylint: disable=E1103,W0403
import logging import logging
import os import os
import re import re
...@@ -19,12 +17,14 @@ import subprocess ...@@ -19,12 +17,14 @@ import subprocess
import sys import sys
import unittest import unittest
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.dirname(ROOT_DIR)) sys.path.insert(0, ROOT_DIR)
from tests.fake_repos import join, write, FakeReposTestBase
from fake_repos import join, write, FakeReposTestBase
import subprocess2 import subprocess2
GCLIENT_PATH = os.path.join(os.path.dirname(ROOT_DIR), 'gclient') GCLIENT_PATH = os.path.join(ROOT_DIR, 'gclient')
COVERAGE = False COVERAGE = False
...@@ -50,6 +50,7 @@ class GClientSmokeBase(FakeReposTestBase): ...@@ -50,6 +50,7 @@ class GClientSmokeBase(FakeReposTestBase):
(stdout, stderr) = process.communicate() (stdout, stderr) = process.communicate()
logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout)) logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout))
logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr)) logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr))
# pylint: disable=E1103
return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'), return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'),
process.returncode) process.returncode)
......
...@@ -15,8 +15,7 @@ import os ...@@ -15,8 +15,7 @@ import os
import sys import sys
import unittest import unittest
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.dirname(BASE_DIR))
import gclient import gclient
import gclient_utils import gclient_utils
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# pylint: disable=E1101,W0403
import os import os
import StringIO import StringIO
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Fixes include path.
from super_mox import SuperMoxTestBase from super_mox import SuperMoxTestBase
import trial_dir import trial_dir
...@@ -57,6 +57,7 @@ class CheckCallAndFilterTestCase(GclientUtilBase): ...@@ -57,6 +57,7 @@ class CheckCallAndFilterTestCase(GclientUtilBase):
'\n________ running \'boo foo bar\' in \'bleh\'\n') '\n________ running \'boo foo bar\' in \'bleh\'\n')
for i in test_string: for i in test_string:
gclient_utils.sys.stdout.write(i) gclient_utils.sys.stdout.write(i)
# pylint: disable=E1101
subprocess2.Popen( subprocess2.Popen(
args, args,
cwd=cwd, cwd=cwd,
......
...@@ -9,7 +9,7 @@ import os ...@@ -9,7 +9,7 @@ import os
import sys import sys
import unittest import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import owners import owners
from tests import filesystem_mock from tests import filesystem_mock
......
...@@ -11,8 +11,7 @@ import posixpath ...@@ -11,8 +11,7 @@ import posixpath
import sys import sys
import unittest import unittest
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
import patch import patch
from tests.patches_data import GIT, RAW from tests.patches_data import GIT, RAW
...@@ -92,8 +91,6 @@ class PatchTest(unittest.TestCase): ...@@ -92,8 +91,6 @@ class PatchTest(unittest.TestCase):
p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1) p, 'foo', GIT.NEW, is_new=True, is_git_diff=True, patchlevel=1)
def testValidSvn(self): def testValidSvn(self):
# pylint: disable=R0201
# Method could be a function
# Should not throw. # Should not throw.
p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, []) p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, [])
lines = RAW.PATCH.splitlines(True) lines = RAW.PATCH.splitlines(True)
......
...@@ -5,20 +5,22 @@ ...@@ -5,20 +5,22 @@
"""Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" """Unit tests for presubmit_support.py and presubmit_canned_checks.py."""
# pylint is too confused. # pylint: disable=E1101,E1103
# pylint: disable=E1101,E1103,R0201,W0212,W0403
import logging import logging
import os
import StringIO import StringIO
import sys import sys
import time import time
# Fixes include path. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from super_mox import mox, SuperMoxTestBase from super_mox import mox, SuperMoxTestBase
import owners import owners
import presubmit_support as presubmit import presubmit_support as presubmit
import rietveld import rietveld
# Shortcut. # Shortcut.
presubmit_canned_checks = presubmit.presubmit_canned_checks presubmit_canned_checks = presubmit.presubmit_canned_checks
...@@ -233,7 +235,7 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -233,7 +235,7 @@ class PresubmitUnittest(PresubmitTestsBase):
def testTagLineRe(self): def testTagLineRe(self):
self.mox.ReplayAll() self.mox.ReplayAll()
m = presubmit.Change._TAG_LINE_RE.match(' BUG =1223, 1445 \t') m = presubmit.Change.TAG_LINE_RE.match(' BUG =1223, 1445 \t')
self.failUnless(m) self.failUnless(m)
self.failUnlessEqual(m.group('key'), 'BUG') self.failUnlessEqual(m.group('key'), 'BUG')
self.failUnlessEqual(m.group('value'), '1223, 1445') self.failUnlessEqual(m.group('value'), '1223, 1445')
...@@ -1346,6 +1348,7 @@ class ChangeUnittest(PresubmitTestsBase): ...@@ -1346,6 +1348,7 @@ class ChangeUnittest(PresubmitTestsBase):
'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
'TAG_LINE_RE',
'author_email', 'issue', 'patchset', 'scm', 'tags', 'author_email', 'issue', 'patchset', 'scm', 'tags',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
...@@ -1372,10 +1375,8 @@ class ChangeUnittest(PresubmitTestsBase): ...@@ -1372,10 +1375,8 @@ class ChangeUnittest(PresubmitTestsBase):
class CannedChecksUnittest(PresubmitTestsBase): class CannedChecksUnittest(PresubmitTestsBase):
"""Tests presubmit_canned_checks.py.""" """Tests presubmit_canned_checks.py."""
def setUp(self):
PresubmitTestsBase.setUp(self)
def MockInputApi(self, change, committing): def MockInputApi(self, change, committing):
# pylint: disable=R0201
input_api = self.mox.CreateMock(presubmit.InputApi) input_api = self.mox.CreateMock(presubmit.InputApi)
input_api.cStringIO = presubmit.cStringIO input_api.cStringIO = presubmit.cStringIO
input_api.json = presubmit.json input_api.json = presubmit.json
...@@ -1684,6 +1685,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1684,6 +1685,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(len(results1), 1) self.assertEquals(len(results1), 1)
self.assertEquals(results1[0].__class__, self.assertEquals(results1[0].__class__,
presubmit.OutputApi.PresubmitPromptWarning) presubmit.OutputApi.PresubmitPromptWarning)
# pylint: disable=W0212
self.assertEquals(results1[0]._long_text, self.assertEquals(results1[0]._long_text,
'makefile.foo, line 46') 'makefile.foo, line 46')
...@@ -1973,6 +1975,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1973,6 +1975,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.assertEquals(len(results), 1) self.assertEquals(len(results), 1)
self.assertEquals(results[0].__class__, self.assertEquals(results[0].__class__,
presubmit.OutputApi.PresubmitNotifyResult) presubmit.OutputApi.PresubmitNotifyResult)
# pylint: disable=W0212
self.assertEquals('test_module failed!\nfoo', results[0]._message) self.assertEquals('test_module failed!\nfoo', results[0]._message)
def testRunPythonUnitTestsFailureCommitting(self): def testRunPythonUnitTestsFailureCommitting(self):
...@@ -1987,6 +1990,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1987,6 +1990,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api, presubmit.OutputApi, ['test_module']) input_api, presubmit.OutputApi, ['test_module'])
self.assertEquals(len(results), 1) self.assertEquals(len(results), 1)
self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
# pylint: disable=W0212
self.assertEquals('test_module failed!\nfoo', results[0]._message) self.assertEquals('test_module failed!\nfoo', results[0]._message)
def testRunPythonUnitTestsSuccess(self): def testRunPythonUnitTestsSuccess(self):
...@@ -2227,6 +2231,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -2227,6 +2231,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
project_name=None, project_name=None,
owners_check=True) owners_check=True)
self.assertEqual(1, len(results)) self.assertEqual(1, len(results))
# pylint: disable=W0212
self.assertEqual( self.assertEqual(
'Found line ending with white spaces in:', results[0]._message) 'Found line ending with white spaces in:', results[0]._message)
self.checkstdout('') self.checkstdout('')
......
...@@ -10,16 +10,12 @@ import os ...@@ -10,16 +10,12 @@ import os
import sys import sys
import unittest import unittest
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
import patch import patch
import rietveld import rietveld
from tests.patches_data import GIT, RAW from tests.patches_data import GIT, RAW
# Access to a protected member XX of a client class
# pylint: disable=W0212
def _api(files): def _api(files):
"""Mock a rietveld api request.""" """Mock a rietveld api request."""
...@@ -40,12 +36,16 @@ def _file( ...@@ -40,12 +36,16 @@ def _file(
class RietveldTest(unittest.TestCase): class RietveldTest(unittest.TestCase):
def setUp(self): def setUp(self):
super(RietveldTest, self).setUp()
# Access to a protected member XX of a client class
# pylint: disable=W0212
self.rietveld = rietveld.Rietveld('url', 'email', 'password') self.rietveld = rietveld.Rietveld('url', 'email', 'password')
self.rietveld._send = self._rietveld_send self.rietveld._send = self._rietveld_send
self.requests = [] self.requests = []
def tearDown(self): def tearDown(self):
self.assertEquals([], self.requests) self.assertEquals([], self.requests)
super(RietveldTest, self).tearDown()
def _rietveld_send(self, url, *args, **kwargs): def _rietveld_send(self, url, *args, **kwargs):
self.assertTrue(self.requests, url) self.assertTrue(self.requests, url)
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
"""Unit tests for scm.py.""" """Unit tests for scm.py."""
# pylint: disable=E1101,W0403
from __future__ import with_statement from __future__ import with_statement
import logging import logging
import os
import sys import sys
import unittest import unittest
# Fixes include path. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from super_mox import SuperMoxTestBase from super_mox import SuperMoxTestBase
import fake_repos import fake_repos
...@@ -102,11 +103,11 @@ class SVNTestCase(BaseSCMTestCase): ...@@ -102,11 +103,11 @@ class SVNTestCase(BaseSCMTestCase):
self.compareMembers(scm.SVN, members) self.compareMembers(scm.SVN, members)
def testGetCheckoutRoot(self): def testGetCheckoutRoot(self):
# pylint: disable=E1103
self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo')
self.mox.StubOutWithMock(scm, 'GetCasedPath') self.mox.StubOutWithMock(scm, 'GetCasedPath')
scm.os.path.abspath = lambda x: x scm.os.path.abspath = lambda x: x
scm.GetCasedPath = lambda x: x scm.GetCasedPath = lambda x: x
# pylint: disable=E1103
scm.SVN.CaptureInfo(self.root_dir + '/foo/bar').AndReturn({ scm.SVN.CaptureInfo(self.root_dir + '/foo/bar').AndReturn({
'Repository Root': 'svn://svn.chromium.org/chrome', 'Repository Root': 'svn://svn.chromium.org/chrome',
'URL': 'svn://svn.chromium.org/chrome/trunk/src', 'URL': 'svn://svn.chromium.org/chrome/trunk/src',
......
...@@ -11,14 +11,10 @@ import sys ...@@ -11,14 +11,10 @@ import sys
import time import time
import unittest import unittest
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, ROOT_DIR)
import subprocess2 import subprocess2
# Method could be a function
# pylint: disable=R0201
class Subprocess2Test(unittest.TestCase): class Subprocess2Test(unittest.TestCase):
# Can be mocked in a test. # Can be mocked in a test.
TO_SAVE = { TO_SAVE = {
...@@ -62,7 +58,8 @@ class Subprocess2Test(unittest.TestCase): ...@@ -62,7 +58,8 @@ class Subprocess2Test(unittest.TestCase):
assert not results assert not results
results.update(kwargs) results.update(kwargs)
results['args'] = args results['args'] = args
def communicate(self): @staticmethod
def communicate():
return None, None return None, None
subprocess2.Popen = fake_Popen subprocess2.Popen = fake_Popen
return results return results
...@@ -76,7 +73,8 @@ class Subprocess2Test(unittest.TestCase): ...@@ -76,7 +73,8 @@ class Subprocess2Test(unittest.TestCase):
assert not results assert not results
results.update(kwargs) results.update(kwargs)
results['args'] = args results['args'] = args
def communicate(self): @staticmethod
def communicate():
return None, None return None, None
subprocess2.subprocess.Popen = fake_Popen subprocess2.subprocess.Popen = fake_Popen
return results return results
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
"""Unit tests for trychange.py.""" """Unit tests for trychange.py."""
# pylint: disable=E1103,W0403 import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Fixes include path.
from super_mox import SuperMoxTestBase from super_mox import SuperMoxTestBase
import subprocess2 import subprocess2
...@@ -91,6 +93,7 @@ class GITUnittest(TryChangeTestsBase): ...@@ -91,6 +93,7 @@ class GITUnittest(TryChangeTestsBase):
self.compareMembers(trychange.GIT, members) self.compareMembers(trychange.GIT, members)
def testBasic(self): def testBasic(self):
# pylint: disable=E1103
trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root) trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere') trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere')
......
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
"""Unit tests for watchlists.py.""" """Unit tests for watchlists.py."""
# pylint is too confused. # pylint: disable=E1103,E1120,W0212
# pylint: disable=E1103,E1120,W0212,W0403
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import super_mox import super_mox
import watchlists import watchlists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment