1
+ import getpass
1
2
import pathlib
3
+ import shutil
4
+ import textwrap
2
5
3
6
import pytest
4
7
7
10
from libvcs .util import run
8
11
9
12
13
+ @pytest .fixture (autouse = True , scope = "session" )
14
+ def home_path (tmp_path_factory : pytest .TempPathFactory ):
15
+ return tmp_path_factory .mktemp ("home" )
16
+
17
+
18
+ @pytest .fixture (autouse = True , scope = "session" )
19
+ def user_path (home_path : pathlib .Path ):
20
+ p = home_path / getpass .getuser ()
21
+ p .mkdir ()
22
+ return p
23
+
24
+
10
25
@pytest .fixture (scope = "function" )
11
- def tmpdir_repoparent ( tmp_path : pathlib .Path ):
26
+ def repos_path ( user_path : pathlib .Path , request : pytest . FixtureRequest ):
12
27
"""Return temporary directory for repository checkout guaranteed unique."""
13
- fn = tmp_path
14
- return fn
28
+ dir = user_path / "repos"
29
+ dir .mkdir (exist_ok = True )
30
+
31
+ def clean ():
32
+ shutil .rmtree (dir )
33
+
34
+ request .addfinalizer (clean )
35
+ return dir
15
36
16
37
17
38
@pytest .fixture
18
- def git_repo_kwargs (tmpdir_repoparent : pathlib .Path , git_dummy_repo_dir ):
39
+ def git_repo_kwargs (repos_path : pathlib .Path , git_dummy_repo_dir ):
19
40
"""Return kwargs for :func:`create_repo_from_pip_url`."""
20
- repo_name = "repo_clone"
21
41
return {
22
42
"url" : "git+file://" + git_dummy_repo_dir ,
23
- "parent_dir" : str (tmpdir_repoparent ),
24
- "name" : repo_name ,
43
+ "parent_dir" : str (repos_path ),
44
+ "name" : " repo_name" ,
25
45
}
26
46
27
47
28
48
@pytest .fixture
29
49
def git_repo (git_repo_kwargs ) -> GitRepo :
30
50
"""Create an git repository for tests. Return repo."""
31
- git_repo = create_repo_from_pip_url (** git_repo_kwargs )
32
- git_repo .obtain (quiet = True )
33
- return git_repo
51
+ repo = create_repo_from_pip_url (** git_repo_kwargs )
52
+ repo .obtain (quiet = True )
53
+ return repo
34
54
35
55
36
56
@pytest .fixture
37
- def create_git_dummy_repo (tmpdir_repoparent : pathlib .Path ) -> pathlib .Path :
57
+ def create_git_dummy_repo (repos_path : pathlib .Path ) -> pathlib .Path :
38
58
def fn (repo_name , testfile_filename = "testfile.test" ):
39
- repo_path = str (tmpdir_repoparent / repo_name )
59
+ repo_path = str (repos_path / repo_name )
40
60
41
- run (["git" , "init" , repo_name ], cwd = str (tmpdir_repoparent ))
61
+ run (["git" , "init" , repo_name ], cwd = str (repos_path ))
42
62
43
63
run (["touch" , testfile_filename ], cwd = repo_path )
44
64
run (["git" , "add" , testfile_filename ], cwd = repo_path )
@@ -50,20 +70,53 @@ def fn(repo_name, testfile_filename="testfile.test"):
50
70
51
71
52
72
@pytest .fixture
53
- def git_dummy_repo_dir (tmpdir_repoparent : pathlib .Path , create_git_dummy_repo ):
73
+ def git_dummy_repo_dir (repos_path : pathlib .Path , create_git_dummy_repo ):
54
74
"""Create a git repo with 1 commit, used as a remote."""
55
75
return create_git_dummy_repo ("dummyrepo" )
56
76
57
77
58
78
@pytest .fixture (scope = "function" )
59
- def home_path (tmp_path : pathlib .Path , monkeypatch : pytest .MonkeyPatch ) -> pathlib .Path :
60
- monkeypatch .setenv ("HOME" , str (tmp_path ))
61
- tmp_path .mkdir (exist_ok = True )
62
- return tmp_path
79
+ def config_path (home_path : pathlib .Path , request : pytest .FixtureRequest ):
80
+ conf_path = home_path / ".vcspull"
81
+ conf_path .mkdir (exist_ok = True )
63
82
83
+ def clean ():
84
+ shutil .rmtree (conf_path )
64
85
65
- @pytest .fixture (scope = "function" )
66
- def config_path (home_path : pathlib .Path ):
67
- conf_path = home_path / ".vcspull"
68
- conf_path .mkdir ()
86
+ request .addfinalizer (clean )
69
87
return conf_path
88
+
89
+
90
+ @pytest .fixture (autouse = True , scope = "session" )
91
+ def hgrc (user_path : pathlib .Path ):
92
+ hgrc = user_path / ".hgrc"
93
+ hgrc .write_text (
94
+ textwrap .dedent (
95
+ f"""
96
+ [ui]
97
+ username = vcspull tests <vcspull@git-pull.com>
98
+ merge = internal:merge
99
+
100
+ [trusted]
101
+ users = { getpass .getuser ()}
102
+ """
103
+ ),
104
+ encoding = "utf-8" ,
105
+ )
106
+ return hgrc
107
+
108
+
109
+ @pytest .fixture (autouse = True , scope = "module" )
110
+ def gitconfig (user_path : pathlib .Path ):
111
+ gitconfig = user_path / ".gitconfig"
112
+ gitconfig .write_text (
113
+ textwrap .dedent (
114
+ f"""
115
+ [user]
116
+ email = libvcs@git-pull.com
117
+ name = { getpass .getuser ()}
118
+ """
119
+ ),
120
+ encoding = "utf-8" ,
121
+ )
122
+ return gitconfig
0 commit comments