Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: tests/presubmit_unittest.py

Issue 113964: Make AffectedFile member variables private. (Closed)
Patch Set: 80cols Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index 7f5d57191cbe0fdb953150916445746552226065..921697139a969cb560ecf15d0ead2098f865d66e 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -12,16 +12,19 @@ import unittest
import warnings
# Local imports
+import __init__
import gcl
import gclient
import presubmit_support as presubmit
import presubmit_canned_checks
+mox = __init__.mox
class PresubmitTestsBase(unittest.TestCase):
"""Setups and tear downs the mocks but doesn't test anything as-is."""
def setUp(self):
self._warnings_stack = warnings.catch_warnings()
+ self.mox = mox.Mox()
warnings.simplefilter("ignore", DeprecationWarning)
self.original_IsFile = os.path.isfile
def MockIsFile(f):
@@ -87,6 +90,10 @@ def CheckChangeOnUpload(input_api, output_api):
gcl.GetRepositoryRoot = MockGetRepositoryRoot
self._sys_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
+ self._os_path_exists = os.path.exists
+ os.path.exists = self.mox.CreateMockAnything()
+ self._os_path_isdir = os.path.isdir
+ os.path.isdir = self.mox.CreateMockAnything()
def tearDown(self):
os.path.isfile = self.original_IsFile
@@ -95,6 +102,8 @@ def CheckChangeOnUpload(input_api, output_api):
gcl.ReadFile = self.original_ReadFile
gcl.GetRepositoryRoot = self.original_GetRepositoryRoot
sys.stdout = self._sys_stdout
+ os.path.exists = self._os_path_exists
+ os.path.isdir = self._os_path_isdir
self._warnings_stack = None
@staticmethod
@@ -160,7 +169,15 @@ class PresubmitUnittest(PresubmitTestsBase):
['M', 'flop/notfound.txt'], # not found in SVN, still exists locally
['D', 'boo/flap.h'],
]
-
+ os.path.exists(os.path.join('foo', 'blat.cc')).AndReturn(True)
+ os.path.isdir(os.path.join('foo', 'blat.cc')).AndReturn(False)
+ os.path.exists('binary.dll').AndReturn(True)
+ os.path.isdir('binary.dll').AndReturn(False)
+ os.path.exists('isdir').AndReturn(True)
+ os.path.isdir('isdir').AndReturn(True)
+ os.path.exists(os.path.join('flop', 'notfound.txt')).AndReturn(False)
+ os.path.exists(os.path.join('boo', 'flap.h')).AndReturn(False)
+ self.mox.ReplayAll()
ci = gcl.ChangeInfo(name='mychange',
description='\n'.join(description_lines),
files=files)
@@ -218,6 +235,7 @@ class PresubmitUnittest(PresubmitTestsBase):
self.failUnless(rhs_lines[3][0].LocalPath() == files[3][1])
self.failUnless(rhs_lines[3][1] == 2)
self.failUnless(rhs_lines[3][2] == 'two:%s' % files[3][1])
+ self.mox.VerifyAll()
def testExecPresubmitScript(self):
description_lines = ('Hello there',
@@ -387,6 +405,11 @@ def CheckChangeOnCommit(input_api, output_api):
['A', 'isdir'],
['A', 'isdir\\blat.cc'],
]
+ os.path.exists('isdir').AndReturn(True)
+ os.path.isdir('isdir').AndReturn(True)
+ os.path.exists(os.path.join('isdir', 'blat.cc')).AndReturn(True)
+ os.path.isdir(os.path.join('isdir', 'blat.cc')).AndReturn(False)
+ self.mox.ReplayAll()
ci = gcl.ChangeInfo(name='mychange',
description='foo',
files=files)
@@ -395,7 +418,7 @@ def CheckChangeOnCommit(input_api, output_api):
affected_files = change.AffectedFiles(include_dirs=False)
self.failUnless(len(affected_files) == 1)
self.failUnless(affected_files[0].LocalPath().endswith('blat.cc'))
-
+ self.mox.VerifyAll()
affected_files_and_dirs = change.AffectedFiles(include_dirs=True)
self.failUnless(len(affected_files_and_dirs) == 2)
@@ -510,6 +533,16 @@ class InputApiUnittest(PresubmitTestsBase):
['A', 'boo/flap.h'],
]
+ os.path.exists(os.path.join('foo', 'blat.cc')).AndReturn(True)
+ os.path.isdir(os.path.join('foo', 'blat.cc')).AndReturn(False)
+ os.path.exists(os.path.join('foo', 'blat', 'binary.dll')).AndReturn(True)
+ os.path.isdir(os.path.join('foo', 'blat', 'binary.dll')).AndReturn(False)
+ os.path.exists(os.path.join('foo', 'mat', 'beingdeleted.txt')).AndReturn(
+ False)
+ os.path.exists(os.path.join('flop', 'notfound.txt')).AndReturn(False)
+ os.path.exists(os.path.join('boo', 'flap.h')).AndReturn(True)
+ os.path.isdir(os.path.join('boo', 'flap.h')).AndReturn(False)
+ self.mox.ReplayAll()
ci = gcl.ChangeInfo(name='mychange',
description='\n'.join(description_lines),
files=files)
@@ -532,6 +565,7 @@ class InputApiUnittest(PresubmitTestsBase):
self.failUnless(len(rhs_lines) == 2)
self.assertEqual(rhs_lines[0][0].LocalPath(),
presubmit.normpath('foo/blat.cc'))
+ self.mox.VerifyAll()
def testGetAbsoluteLocalPath(self):
# Regression test for bug of presubmit stuff that relies on invoking
@@ -629,10 +663,8 @@ class OuputApiUnittest(PresubmitTestsBase):
class AffectedFileUnittest(PresubmitTestsBase):
def testMembersChanged(self):
members = [
- 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile',
- 'LocalPath', 'NewContents',
- 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', 'action',
- 'is_directory', 'path', 'properties', 'repository_root', 'server_path',
+ 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath',
+ 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath',
]
# If this test fails, you should add the relevant test.
self.compareMembers(presubmit.AffectedFile('a', 'b'), members)
@@ -640,11 +672,14 @@ class AffectedFileUnittest(PresubmitTestsBase):
def testAffectedFile(self):
af = presubmit.SvnAffectedFile('foo/blat.cc', 'M')
+ os.path.exists(os.path.join('foo', 'blat.cc')).AndReturn(False)
+ self.mox.ReplayAll()
self.failUnless(af.ServerPath() == 'svn:/foo/foo/blat.cc')
self.failUnless(af.LocalPath() == presubmit.normpath('foo/blat.cc'))
self.failUnless(af.Action() == 'M')
self.failUnless(af.NewContents() == ['one:%s' % af.LocalPath(),
'two:%s' % af.LocalPath()])
+ self.mox.VerifyAll()
af = presubmit.AffectedFile('notfound.cc', 'A')
self.failUnless(af.ServerPath() == '')
@@ -654,6 +689,25 @@ class AffectedFileUnittest(PresubmitTestsBase):
self.failUnless(affected_file.Property('svn:secret-property') ==
'secret-property-value')
+ def testIsDirectoryNotExists(self):
+ # Verify cache coherency
+ os.path.exists('foo.cc').AndReturn(False)
+ self.mox.ReplayAll()
+ affected_file = presubmit.SvnAffectedFile('foo.cc', 'A')
+ self.failIf(affected_file.IsDirectory())
+ self.failIf(affected_file.IsDirectory())
Jói Sigurðsson 2009/05/28 21:30:51 duplicate?
M-A Ruel 2009/05/29 00:59:55 Yes, that's to verify the cache coherency. I've mo
+ self.mox.VerifyAll()
+
+ def testIsDirectory(self):
+ # Verify cache coherency
+ os.path.exists('foo.cc').AndReturn(True)
+ os.path.isdir('foo.cc').AndReturn(True)
+ self.mox.ReplayAll()
+ affected_file = presubmit.SvnAffectedFile('foo.cc', 'A')
+ self.failUnless(affected_file.IsDirectory())
+ self.failUnless(affected_file.IsDirectory())
Jói Sigurðsson 2009/05/28 21:30:51 duplicate?
+ self.mox.VerifyAll()
+
class CannedChecksUnittest(PresubmitTestsBase):
"""Tests presubmit_canned_checks.py."""
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698