|
9 | 9 | from git import *
|
10 | 10 | from git.utils import join_path_native
|
11 | 11 | import tempfile
|
| 12 | +import shutil |
12 | 13 |
|
13 | 14 | class TestRepo(TestBase):
|
14 | 15 |
|
@@ -90,17 +91,33 @@ def test_trees(self):
|
90 | 91 | assert num_trees == mc
|
91 | 92 |
|
92 | 93 |
|
93 |
| - @patch_object(Repo, '__init__') |
94 |
| - @patch_object(Git, '_call_process') |
95 |
| - def test_init(self, git, repo): |
96 |
| - git.return_value = True |
97 |
| - repo.return_value = None |
98 |
| - |
99 |
| - r = Repo.init("repos/foo/bar.git", bare=True) |
100 |
| - assert isinstance(r, Repo) |
101 |
| - |
102 |
| - assert_true(git.called) |
103 |
| - assert_true(repo.called) |
| 94 | + def test_init(self): |
| 95 | + prev_cwd = os.getcwd() |
| 96 | + os.chdir(tempfile.gettempdir()) |
| 97 | + git_dir_rela = "repos/foo/bar.git" |
| 98 | + del_dir_abs = os.path.abspath("repos") |
| 99 | + git_dir_abs = os.path.abspath(git_dir_rela) |
| 100 | + try: |
| 101 | + # with specific path |
| 102 | + for path in (git_dir_rela, git_dir_abs): |
| 103 | + r = Repo.init(path=path, bare=True) |
| 104 | + assert isinstance(r, Repo) |
| 105 | + assert r.bare == True |
| 106 | + assert os.path.isdir(r.git_dir) |
| 107 | + shutil.rmtree(git_dir_abs) |
| 108 | + # END for each path |
| 109 | + |
| 110 | + os.makedirs(git_dir_rela) |
| 111 | + os.chdir(git_dir_rela) |
| 112 | + r = Repo.init(bare=False) |
| 113 | + r.bare == False |
| 114 | + finally: |
| 115 | + try: |
| 116 | + shutil.rmtree(del_dir_abs) |
| 117 | + except OSError: |
| 118 | + pass |
| 119 | + os.chdir(prev_cwd) |
| 120 | + # END restore previous state |
104 | 121 |
|
105 | 122 | def test_bare_property(self):
|
106 | 123 | self.rorepo.bare
|
|
0 commit comments