Implement OCSP stapling in Windows BoringSSL port.
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / tests / build_version_test.py
blobf8f60a26ce359d3576b04c2bca832fdf2f032210
1 #!/usr/bin/env python
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.
6 import os
7 import sys
8 import collections
9 import unittest
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)
18 import mock
20 sys.path.append(BUILD_TOOLS_DIR)
21 import build_version
23 ProcInfo = collections.namedtuple('ProcInfo', ['returncode', 'output'])
25 class TestCase(unittest.TestCase):
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()
31 self.fetch_svn.return_value = None
32 self.fetch_git_svn.return_value = None
34 def tearDown(self):
35 mock.patch.stopall()
37 def mockGitCommand(self, *args):
38 side_effects = []
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):
50 output = """\
51 6a8b61d6be4656e682eba005a1dd7f129789129c
52 [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README.
54 BUG=none
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):
63 output0 = """\
64 ae4b444a0aa09a1fa73e59b180d7d957b9a36bf2
65 ."""
67 output1 = """\
68 6a8b61d6be4656e682eba005a1dd7f129789129c
69 [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README.
71 BUG=none
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()
100 self.assertEqual(
101 result,
102 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}')
104 def testChromeCommitPositionDepthTwo(self):
105 self.mockDepthTwoGitCommand()
106 result = build_version.ChromeCommitPosition()
107 self.assertEqual(
108 result,
109 '6a8b61d6be4656e682eba005a1dd7f129789129c-refs/heads/master@{#292480}')
112 if __name__ == '__main__':
113 unittest.main()