OLD | NEW |
(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 |
| 18 |
| 19 class Basic(git_test_utils.GitRepoReadWriteTestBase): |
| 20 REPO = """ |
| 21 A B C D E |
| 22 B F E |
| 23 X Y E |
| 24 """ |
| 25 |
| 26 @classmethod |
| 27 def setUpClass(cls): |
| 28 super(Basic, cls).setUpClass() |
| 29 import git_number |
| 30 cls.gn = git_number |
| 31 cls.old_POOL_KIND = cls.gn.POOL_KIND |
| 32 cls.gn.POOL_KIND = 'threads' |
| 33 |
| 34 @classmethod |
| 35 def tearDownClass(cls): |
| 36 cls.gn.POOL_KIND = cls.old_POOL_KIND |
| 37 super(Basic, cls).tearDownClass() |
| 38 |
| 39 def tearDown(self): |
| 40 self.gn.clear_caches() |
| 41 super(Basic, self).tearDown() |
| 42 |
| 43 def _git_number(self, refs, cache=False): |
| 44 refs = map(binascii.unhexlify, refs) |
| 45 self.repo.run(self.gn.load_generation_numbers, refs) |
| 46 if cache: |
| 47 self.repo.run(self.gn.finalize, refs) |
| 48 return map(self.gn.get_num, refs) |
| 49 |
| 50 def testBasic(self): |
| 51 self.assertEqual([0], self._git_number([self.repo['A']])) |
| 52 self.assertEqual([2], self._git_number([self.repo['F']])) |
| 53 self.assertEqual([0], self._git_number([self.repo['X']])) |
| 54 self.assertEqual([4], self._git_number([self.repo['E']])) |
| 55 |
| 56 def testInProcessCache(self): |
| 57 self.assertEqual( |
| 58 None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])) |
| 59 ) |
| 60 self.assertEqual([4], self._git_number([self.repo['E']])) |
| 61 self.assertEqual( |
| 62 0, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])) |
| 63 ) |
| 64 |
| 65 def testOnDiskCache(self): |
| 66 self.assertEqual( |
| 67 None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])) |
| 68 ) |
| 69 self.assertEqual([4], self._git_number([self.repo['E']], cache=True)) |
| 70 self.assertEqual([4], self._git_number([self.repo['E']], cache=True)) |
| 71 self.gn.clear_caches() |
| 72 self.assertEqual( |
| 73 0, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])) |
| 74 ) |
| 75 self.gn.clear_caches() |
| 76 self.repo.run(self.gn.clear_caches, True) |
| 77 self.assertEqual( |
| 78 None, self.repo.run(self.gn.get_num, binascii.unhexlify(self.repo['A'])) |
| 79 ) |
| 80 |
| 81 |
| 82 if __name__ == '__main__': |
| 83 sys.exit(coverage_utils.covered_main( |
| 84 os.path.join(DEPOT_TOOLS_ROOT, 'git_number.py') |
| 85 )) |
OLD | NEW |