| OLD | NEW | 
|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python | 
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 import re | 6 import re | 
| 7 import StringIO | 7 import StringIO | 
| 8 | 8 | 
| 9 import gclient_utils | 9 import gclient_utils | 
| 10 from super_mox import SuperMoxTestBase | 10 from super_mox import SuperMoxTestBase | 
| 11 | 11 | 
|  | 12 | 
|  | 13 class GclientUtilsUnittest(SuperMoxTestBase): | 
|  | 14   """General gclient_utils.py tests.""" | 
|  | 15   def testMembersChanged(self): | 
|  | 16     members = [ | 
|  | 17         'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite', | 
|  | 18         'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText', | 
|  | 19         'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML', | 
|  | 20         'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', | 
|  | 21         'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'os', 're', | 
|  | 22         'stat', 'subprocess', 'sys', 'time', 'xml', | 
|  | 23     ] | 
|  | 24     # If this test fails, you should add the relevant test. | 
|  | 25     self.compareMembers(gclient_utils, members) | 
|  | 26 | 
|  | 27 | 
|  | 28 class CheckCallTestCase(SuperMoxTestBase): | 
|  | 29   def testCheckCallSuccess(self): | 
|  | 30     command = ['boo', 'foo', 'bar'] | 
|  | 31     process = self.mox.CreateMockAnything() | 
|  | 32     process.retcode = 0 | 
|  | 33     gclient_utils.subprocess.Popen( | 
|  | 34         command, cwd=None, | 
|  | 35         stdout=gclient_utils.subprocess.PIPE, | 
|  | 36         shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 
|  | 37     process.communicate().AndReturn(['bleh']) | 
|  | 38     self.mox.ReplayAll() | 
|  | 39     gclient_utils.CheckCall(command) | 
|  | 40 | 
|  | 41   def testCheckCallFailure(self): | 
|  | 42     command = ['boo', 'foo', 'bar'] | 
|  | 43     process = self.mox.CreateMockAnything() | 
|  | 44     process.retcode = 42 | 
|  | 45     gclient_utils.subprocess.Popen( | 
|  | 46         command, cwd=None, | 
|  | 47         stdout=gclient_utils.subprocess.PIPE, | 
|  | 48         shell=gclient_utils.sys.platform.startswith('win')).AndReturn(process) | 
|  | 49     process.communicate().AndReturn(['bleh']) | 
|  | 50     self.mox.ReplayAll() | 
|  | 51     try: | 
|  | 52       gclient_utils.CheckCall(command) | 
|  | 53       self.fail() | 
|  | 54     except gclient_utils.CheckCallError, e: | 
|  | 55       self.assertEqual(e.command, command) | 
|  | 56       self.assertEqual(e.cwd, None) | 
|  | 57       self.assertEqual(e.retcode, 42) | 
|  | 58       self.assertEqual(e.stdout, 'bleh') | 
|  | 59 | 
|  | 60 | 
| 12 class SubprocessCallAndFilterTestCase(SuperMoxTestBase): | 61 class SubprocessCallAndFilterTestCase(SuperMoxTestBase): | 
| 13   def testSubprocessCallAndFilter(self): | 62   def testSubprocessCallAndFilter(self): | 
| 14     command = ['boo', 'foo', 'bar'] | 63     command = ['boo', 'foo', 'bar'] | 
| 15     in_directory = 'bleh' | 64     in_directory = 'bleh' | 
| 16     fail_status = None | 65     fail_status = None | 
| 17     pattern = 'a(.*)b' | 66     pattern = 'a(.*)b' | 
| 18     test_string = 'ahah\naccb\nallo\naddb\n' | 67     test_string = 'ahah\naccb\nallo\naddb\n' | 
| 19     class Mock(object): | 68     class Mock(object): | 
| 20       stdout = StringIO.StringIO(test_string) | 69       stdout = StringIO.StringIO(test_string) | 
| 21       def wait(self): | 70       def wait(self): | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96     base_url = 'svn://a/b/c/d' | 145     base_url = 'svn://a/b/c/d' | 
| 97     full_url = gclient_utils.FullUrlFromRelative2(base_url, '/crap') | 146     full_url = gclient_utils.FullUrlFromRelative2(base_url, '/crap') | 
| 98     self.assertEqual(full_url, 'svn://a/b/c/crap') | 147     self.assertEqual(full_url, 'svn://a/b/c/crap') | 
| 99 | 148 | 
| 100 | 149 | 
| 101 if __name__ == '__main__': | 150 if __name__ == '__main__': | 
| 102   import unittest | 151   import unittest | 
| 103   unittest.main() | 152   unittest.main() | 
| 104 | 153 | 
| 105 # vim: ts=2:sw=2:tw=80:et: | 154 # vim: ts=2:sw=2:tw=80:et: | 
| OLD | NEW | 
|---|