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

Unified 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 side-by-side diff with in-line comments
Download patch
« testing_support/git_test_utils.py ('K') | « tests/git_common_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/git_number_test.py
diff --git a/tests/git_number_test.py b/tests/git_number_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..c7922e9b15ac3172a056c875929dc4239acf8d51
--- /dev/null
+++ b/tests/git_number_test.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for git_number.py"""
+
+import binascii
+import os
+import sys
+
+DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+sys.path.insert(0, DEPOT_TOOLS_ROOT)
+
+from testing_support import git_test_utils
+from testing_support import coverage_utils
+
M-A Ruel 2013/11/08 19:32:23 2 lines
iannucci 2013/11/11 22:59:24 Done.
+class Basic(git_test_utils.GitRepoReadWriteTestBase):
+ REPO = """
+ A B C D E
+ B F E
+ X Y E
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ super(Basic, cls).setUpClass()
+ import git_number
+ cls.gn = git_number
+ cls.gn.POOL_KIND = 'threads'
+
+ @classmethod
+ def tearDownClass(cls):
+ 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.
+ super(Basic, cls).tearDownClass()
+
+ def tearDown(self):
+ self.gn.clear_caches()
+ super(Basic, self).tearDown()
+
+ def _git_number(self, refs, reset=False, cache=False):
+ return self.repo.run(
+ self.gn.git_number,
+ reset, cache, refs
+ )
+
+ def testBasic(self):
+ self.assertEqual(self._git_number([self.repo['A']]), [0])
+ self.assertEqual(self._git_number([self.repo['F']]), [2])
+ self.assertEqual(self._git_number([self.repo['X']]), [0])
+ self.assertEqual(self._git_number([self.repo['E']]), [4])
+
+ def testInProcessCache(self):
+ self.assertEqual(
+ self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), None
+ )
+ self.assertEqual(self._git_number([self.repo['E']]), [4])
+ self.assertEqual(
+ self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), 0
+ )
+
+ def testOnDiskCache(self):
+ self.assertEqual(
+ self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), None
+ )
+ self.assertEqual(self._git_number([self.repo['E']], cache=True), [4])
+ self.assertEqual(self._git_number([self.repo['E']], cache=True), [4])
+ self.gn.clear_caches()
+ self.assertEqual(
+ self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])), 0
+ )
+ self.gn.clear_caches()
+ self._git_number([], reset=True)
+ self.assertEqual(
+ 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
+ )
+
+
+if __name__ == '__main__':
+ sys.exit(coverage_utils.covered_main(
+ os.path.join(DEPOT_TOOLS_ROOT, 'git_number.py')
+ ))
« 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