| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 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 os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import collections | 8 import collections |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 11 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 12 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) | 12 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) |
| 13 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR))) | 13 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR))) |
| 14 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock') | 14 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock') |
| 15 | 15 |
| 16 # For the mock library | 16 # For the mock library |
| 17 sys.path.append(MOCK_DIR) | 17 sys.path.append(MOCK_DIR) |
| 18 import mock | 18 import mock |
| 19 | 19 |
| 20 sys.path.append(BUILD_TOOLS_DIR) | 20 sys.path.append(BUILD_TOOLS_DIR) |
| 21 import build_version | 21 import build_version |
| 22 | 22 |
| 23 ProcInfo = collections.namedtuple('ProcInfo', ['returncode', 'output']) | 23 ProcInfo = collections.namedtuple('ProcInfo', ['returncode', 'output']) |
| 24 | 24 |
| 25 class TestCase(unittest.TestCase): | 25 class TestCase(unittest.TestCase): |
| 26 def setUp(self): | 26 def setUp(self): |
| 27 self.fetch_svn = mock.patch('lastchange.FetchSVNRevision').start() | |
| 28 self.fetch_git_svn = mock.patch('lastchange.FetchGitSVNRevision').start() | |
| 29 self.run_git = mock.patch('lastchange.RunGitCommand').start() | 27 self.run_git = mock.patch('lastchange.RunGitCommand').start() |
| 30 | 28 |
| 31 self.fetch_svn.return_value = None | |
| 32 self.fetch_git_svn.return_value = None | |
| 33 | |
| 34 def tearDown(self): | 29 def tearDown(self): |
| 35 mock.patch.stopall() | 30 mock.patch.stopall() |
| 36 | 31 |
| 37 def mockGitCommand(self, *args): | 32 def mockGitCommand(self, *args): |
| 38 side_effects = [] | 33 side_effects = [] |
| 39 for proc_info in args: | 34 for proc_info in args: |
| 40 mock_proc = mock.MagicMock() | 35 mock_proc = mock.MagicMock() |
| 41 mock_proc.returncode = proc_info.returncode | 36 mock_proc.returncode = proc_info.returncode |
| 42 comm_result = mock_proc.MagicMock() | 37 comm_result = mock_proc.MagicMock() |
| 43 comm_result.__getitem__.return_value = proc_info.output | 38 comm_result.__getitem__.return_value = proc_info.output |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 def testChromeCommitPositionDepthTwo(self): | 99 def testChromeCommitPositionDepthTwo(self): |
| 105 self.mockDepthTwoGitCommand() | 100 self.mockDepthTwoGitCommand() |
| 106 result = build_version.ChromeCommitPosition() | 101 result = build_version.ChromeCommitPosition() |
| 107 self.assertEqual( | 102 self.assertEqual( |
| 108 result, | 103 result, |
| 109 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}') | 104 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}') |
| 110 | 105 |
| 111 | 106 |
| 112 if __name__ == '__main__': | 107 if __name__ == '__main__': |
| 113 unittest.main() | 108 unittest.main() |
| OLD | NEW |