OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 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_cache.py""" | |
7 | |
8 import os | |
9 import shutil | |
10 import sys | |
11 import tempfile | |
12 import unittest | |
13 | |
14 DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
15 sys.path.insert(0, DEPOT_TOOLS_ROOT) | |
16 | |
17 from testing_support import coverage_utils | |
18 import git_cache | |
19 | |
20 class GitCacheTest(unittest.TestCase): | |
iannucci
2015/09/22 22:56:57
yay! :D
| |
21 @classmethod | |
22 def setUpClass(cls): | |
23 cls.cache_dir = tempfile.mkdtemp(prefix='git_cache_test_') | |
24 git_cache.Mirror.SetCachePath(cls.cache_dir) | |
25 | |
26 @classmethod | |
27 def tearDownClass(cls): | |
28 shutil.rmtree(cls.cache_dir, ignore_errors=True) | |
29 | |
30 def testParseFetchSpec(self): | |
31 testData = [ | |
32 ([], []), | |
33 (['master'], [('+refs/heads/master:refs/heads/master', | |
34 r'\+refs/heads/master:.*')]), | |
35 (['master/'], [('+refs/heads/master:refs/heads/master', | |
36 r'\+refs/heads/master:.*')]), | |
37 (['+master'], [('+refs/heads/master:refs/heads/master', | |
38 r'\+refs/heads/master:.*')]), | |
39 (['refs/heads/*'], [('+refs/heads/*:refs/heads/*', | |
40 r'\+refs/heads/\*:.*')]), | |
41 (['foo/bar/*', 'baz'], [('+refs/heads/foo/bar/*:refs/heads/foo/bar/*', | |
42 r'\+refs/heads/foo/bar/\*:.*'), | |
43 ('+refs/heads/baz:refs/heads/baz', | |
44 r'\+refs/heads/baz:.*')]), | |
45 (['refs/foo/*:refs/bar/*'], [('+refs/foo/*:refs/bar/*', | |
46 r'\+refs/foo/\*:.*')]) | |
47 ] | |
48 | |
49 mirror = git_cache.Mirror('test://phony.example.biz') | |
50 for fetch_specs, expected in testData: | |
51 mirror = git_cache.Mirror('test://phony.example.biz', refs=fetch_specs) | |
52 self.assertItemsEqual(mirror.fetch_specs, expected) | |
53 | |
54 if __name__ == '__main__': | |
55 sys.exit(coverage_utils.covered_main(( | |
56 os.path.join(DEPOT_TOOLS_ROOT, 'git_cache.py') | |
57 ), required_percentage=0)) | |
OLD | NEW |