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
4 # found in the LICENSE file.
11 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
12 BUILD_TOOLS_DIR
= os
.path
.dirname(SCRIPT_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")
16 # For the mock library
17 sys
.path
.append(MOCK_DIR
)
20 sys
.path
.append(BUILD_TOOLS_DIR
)
23 ProcInfo
= collections
.namedtuple('ProcInfo', ['returncode', 'output'])
25 class TestCase(unittest
.TestCase
):
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()
31 self
.fetch_svn
.return_value
= None
32 self
.fetch_git_svn
.return_value
= None
37 def mockGitCommand(self
, *args
):
39 for proc_info
in args
:
40 mock_proc
= mock
.MagicMock()
41 mock_proc
.returncode
= proc_info
.returncode
42 comm_result
= mock_proc
.MagicMock()
43 comm_result
.__getitem
__.return_value
= proc_info
.output
44 mock_proc
.communicate
.return_value
= comm_result
45 side_effects
.append(mock_proc
)
47 self
.run_git
.side_effect
= side_effects
49 def mockDefaultGitCommand(self
):
51 6a8b61d6be4656e682eba005a1dd7f129789129c
52 [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README.
55 R=bradnelson@google.com, bradnelson@chromium.org
57 Review URL: https://codereview.chromium.org/495423010
59 Cr-Commit-Position: refs/heads/master@{#292480}"""
60 self
.mockGitCommand(ProcInfo(0, output
))
62 def mockDepthTwoGitCommand(self
):
64 ae4b444a0aa09a1fa73e59b180d7d957b9a36bf2
68 6a8b61d6be4656e682eba005a1dd7f129789129c
69 [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README.
72 R=bradnelson@google.com, bradnelson@chromium.org
74 Review URL: https://codereview.chromium.org/495423010
76 Cr-Commit-Position: refs/heads/master@{#292480}"""
77 self
.mockGitCommand(ProcInfo(0, output0
), ProcInfo(0, output1
))
80 def assertGitShowCalled(self
, depth
=0):
81 cmd
= ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % depth
]
82 self
.run_git
.assert_called_with(None, cmd
)
84 def testChromeVersion(self
):
85 self
.mockDefaultGitCommand()
86 result
= build_version
.ChromeVersion()
87 self
.assertGitShowCalled()
88 self
.assertEqual(result
, 'trunk.292480')
90 def testChromeRevision(self
):
91 self
.mockDefaultGitCommand()
92 result
= build_version
.ChromeRevision()
93 self
.assertGitShowCalled()
94 self
.assertEqual(result
, '292480')
96 def testChromeCommitPosition(self
):
97 self
.mockDefaultGitCommand()
98 result
= build_version
.ChromeCommitPosition()
99 self
.assertGitShowCalled()
102 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}')
104 def testChromeCommitPositionDepthTwo(self
):
105 self
.mockDepthTwoGitCommand()
106 result
= build_version
.ChromeCommitPosition()
109 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}')
112 if __name__
== '__main__':