OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
agable
2014/07/26 00:47:52
Having both util_test and test_util is pretty lulz
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import shutil | |
6 import sys | |
7 import tempfile | |
8 | |
9 import testing_support | |
10 | |
11 from infra.libs import git2 | |
12 | |
13 | |
14 class TestBasis(testing_support.git.unittest_helpers.GitRepoReadWriteTestBase): | |
15 # TODO(iannucci): Make this covered by the other tests in this folder | |
16 | |
17 REPO_SCHEMA = """ | |
18 A B C D E F | |
19 D L M N O | |
20 O P Q R S | |
21 B G H I J K | |
22 H Z | |
23 O Z | |
24 """ | |
25 | |
26 @staticmethod | |
27 def capture_stdio(fn, *args, **kwargs): # pragma: no cover | |
28 stdout = sys.stdout | |
29 stderr = sys.stderr | |
30 try: | |
31 # "multiple statements on a line" pylint: disable=C0321 | |
32 with tempfile.TemporaryFile() as out, tempfile.TemporaryFile() as err: | |
33 sys.stdout = out | |
34 sys.stderr = err | |
35 fn(*args, **kwargs) | |
36 out.seek(0) | |
37 err.seek(0) | |
38 return out.read(), err.read() | |
39 finally: | |
40 sys.stdout = stdout | |
41 sys.stderr = stderr | |
42 | |
43 def setUp(self): # pragma: no cover | |
44 # "super on old-style class" pylint: disable=E1002 | |
45 self.repos_dir = tempfile.mkdtemp(suffix='.git_test') | |
46 super(TestBasis, self).setUp() | |
47 self.repo.git('branch', 'branch_O', self.repo['O']) | |
48 | |
49 def tearDown(self): # pragma: no cover | |
50 # "super on old-style class" pylint: disable=E1002 | |
51 shutil.rmtree(self.repos_dir) | |
52 super(TestBasis, self).tearDown() | |
53 | |
54 def mkRepo(self): # pragma: no cover | |
55 r = git2.Repo(self.repo.repo_path) | |
56 r.repos_dir = self.repos_dir | |
57 self.capture_stdio(r.reify) | |
58 return r | |
OLD | NEW |