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

Side by Side Diff: tests/git_number_test.py

Issue 26109002: Add git-number script to calculate generation numbers for commits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address comments Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« testing_support/git_test_utils.py ('K') | « tests/git_common_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2013 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.
5
6 """Unit tests for git_number.py"""
7
8 import binascii
9 import os
10 import sys
11
12 DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13 sys.path.insert(0, DEPOT_TOOLS_ROOT)
14
15 from testing_support import git_test_utils
16 from testing_support import coverage_utils
17
M-A Ruel 2013/11/08 19:32:23 2 lines
iannucci 2013/11/11 22:59:24 Done.
18 class Basic(git_test_utils.GitRepoReadWriteTestBase):
19 REPO = """
20 A B C D E
21 B F E
22 X Y E
23 """
24
25 @classmethod
26 def setUpClass(cls):
27 super(Basic, cls).setUpClass()
28 import git_number
29 cls.gn = git_number
30 cls.gn.POOL_KIND = 'threads'
31
32 @classmethod
33 def tearDownClass(cls):
34 cls.gn.POOL_KIND = 'procs'
M-A Ruel 2013/11/08 19:32:23 I'd prefer you to cache the old value before line
iannucci 2013/11/11 22:59:24 Done.
35 super(Basic, cls).tearDownClass()
36
37 def tearDown(self):
38 self.gn.clear_caches()
39 super(Basic, self).tearDown()
40
41 def _git_number(self, refs, reset=False, cache=False):
42 return self.repo.run(
43 self.gn.git_number,
44 reset, cache, refs
45 )
46
47 def testBasic(self):
48 self.assertEqual(self._git_number([self.repo['A']]), [0])
49 self.assertEqual(self._git_number([self.repo['F']]), [2])
50 self.assertEqual(self._git_number([self.repo['X']]), [0])
51 self.assertEqual(self._git_number([self.repo['E']]), [4])
52
53 def testInProcessCache(self):
54 self.assertEqual(
55 self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), None
56 )
57 self.assertEqual(self._git_number([self.repo['E']]), [4])
58 self.assertEqual(
59 self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), 0
60 )
61
62 def testOnDiskCache(self):
63 self.assertEqual(
64 self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), None
65 )
66 self.assertEqual(self._git_number([self.repo['E']], cache=True), [4])
67 self.assertEqual(self._git_number([self.repo['E']], cache=True), [4])
68 self.gn.clear_caches()
69 self.assertEqual(
70 self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), 0
71 )
72 self.gn.clear_caches()
73 self._git_number([], reset=True)
74 self.assertEqual(
75 self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), None
M-A Ruel 2013/11/08 19:32:23 I personally prefer putting the expected value fir
76 )
77
78
79 if __name__ == '__main__':
80 sys.exit(coverage_utils.covered_main(
81 os.path.join(DEPOT_TOOLS_ROOT, 'git_number.py')
82 ))
OLDNEW
« testing_support/git_test_utils.py ('K') | « tests/git_common_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698