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..771b703796cece01fcc7fb4c127d9762f608c976 |
--- /dev/null |
+++ b/tests/git_number_test.py |
@@ -0,0 +1,81 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
M-A Ruel
2013/11/07 20:59:11
# Copyright 2013 The Chromium Authors. All rights
iannucci
2013/11/07 21:44:57
Oops. Done.
|
+# 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 |
+ |
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
+ |
+from testing_support import git_test_utils |
+ |
+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' |
M-A Ruel
2013/11/07 20:59:11
Why not do it in setUp()?
iannucci
2013/11/07 21:44:57
Doesn't need to be done for every test
|
+ |
+ @classmethod |
+ def tearDownClass(cls): |
+ super(Basic, cls).tearDownClass() |
M-A Ruel
2013/11/07 20:59:11
You wan to call the super class after the function
iannucci
2013/11/07 21:44:57
Good point. Fixed everywhere.
|
+ cls.gn.POOL_KIND = 'procs' |
+ |
+ def tearDown(self): |
+ super(Basic, self).tearDown() |
M-A Ruel
2013/11/07 20:59:11
same
iannucci
2013/11/07 21:44:57
Done.
|
+ self.gn.clear_caches() |
+ |
+ 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 |
+ ) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(git_test_utils.covered_main( |
+ os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), |
+ 'git_number.py') |
+ )) |