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

Unified Diff: tests/gcl_unittest.py

Issue 113650: Fix error printing in gcl.GetRepositoryRoot() and fix its unit tests. (Closed)
Patch Set: 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 | « gcl.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/gcl_unittest.py
diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py
index 3517b7ece50675f4306c7d02b26254ff8ea2226f..32201d4cbeb2601ad521fc0b212e309255ed4f86 100755
--- a/tests/gcl_unittest.py
+++ b/tests/gcl_unittest.py
@@ -19,13 +19,20 @@ mox = __init__.mox
class GclTestsBase(unittest.TestCase):
"""Setups and tear downs the mocks but doesn't test anything as-is."""
def setUp(self):
+ self.mox = mox.Mox()
def RunShellMock(filename):
return filename
self._RunShell = gcl.RunShell
gcl.RunShell = RunShellMock
+ self._gcl_gclient_CaptureSVNInfo = gcl.gclient.CaptureSVNInfo
+ gcl.gclient.CaptureSVNInfo = self.mox.CreateMockAnything()
+ self._gcl_os_getcwd = gcl.os.getcwd
+ gcl.os.getcwd = self.mox.CreateMockAnything()
def tearDown(self):
gcl.RunShell = self._RunShell
+ gcl.gclient.CaptureSVNInfo = self._gcl_gclient_CaptureSVNInfo
+ gcl.os.getcwd = self._gcl_os_getcwd
def compareMembers(self, object, members):
"""If you add a member, be sure to add the relevant test!"""
@@ -75,15 +82,31 @@ class GclUnittest(GclTestsBase):
finally:
gcl.sys.stdout = old_stdout
- def testGetRepositoryRoot(self):
- try:
- def RunShellMock(filename):
- return '<?xml version="1.0"?>\n<info>'
- gcl.RunShell = RunShellMock
- gcl.GetRepositoryRoot()
- except Exception,e:
- self.assertEquals(e.args[0], "gcl run outside of repository")
- pass
+ def testGetRepositoryRootNone(self):
+ gcl.repository_root = None
+ gcl.os.getcwd().AndReturn("/bleh/prout")
+ result = {
+ "Repository Root": ""
+ }
+ gcl.gclient.CaptureSVNInfo("/bleh/prout", print_error=False).AndReturn(result)
Nicolas Sylvain 2009/05/20 18:26:57 80 chars
+ self.mox.ReplayAll()
+ self.assertRaises(Exception, gcl.GetRepositoryRoot)
+ self.mox.VerifyAll()
+
+ def testGetRepositoryRootGood(self):
+ gcl.repository_root = None
+ root_path = os.path.join('bleh', 'prout', 'pouet')
+ gcl.os.getcwd().AndReturn(root_path)
+ result1 = { "Repository Root": "Some root" }
+ gcl.gclient.CaptureSVNInfo(root_path, print_error=False).AndReturn(result1)
+ gcl.os.getcwd().AndReturn(root_path)
+ results2 = { "Repository Root": "A different root" }
+ gcl.gclient.CaptureSVNInfo(
+ os.path.dirname(root_path),
+ print_error=False).AndReturn(results2)
+ self.mox.ReplayAll()
+ self.assertEquals(gcl.GetRepositoryRoot(), root_path)
+ self.mox.VerifyAll()
class ChangeInfoUnittest(GclTestsBase):
@@ -110,13 +133,10 @@ class ChangeInfoUnittest(GclTestsBase):
class UploadCLUnittest(GclTestsBase):
def setUp(self):
GclTestsBase.setUp(self)
- self.mox = mox.Mox()
self._os_chdir = gcl.os.chdir
gcl.os.chdir = self.mox.CreateMockAnything()
self._os_close = gcl.os.close
gcl.os.close = self.mox.CreateMockAnything()
- self._os_getcwd = gcl.os.getcwd
- gcl.os.getcwd = self.mox.CreateMockAnything()
self._os_remove = gcl.os.remove
gcl.os.remove = self.mox.CreateMockAnything()
self._os_write = gcl.os.write
@@ -142,7 +162,6 @@ class UploadCLUnittest(GclTestsBase):
GclTestsBase.tearDown(self)
gcl.os.chdir = self._os_chdir
gcl.os.close = self._os_close
- gcl.os.getcwd = self._os_getcwd
gcl.os.remove = self._os_remove
gcl.os.write = self._os_write
gcl.tempfile = self._tempfile
« no previous file with comments | « gcl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698