FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/test/test_clone.py at main · QuantStack/git2cpp · GitHub
QuantStack
git2cpp
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
git2cpp
/
test
/
test_clone.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
263 lines (200 loc) · 10.4 KB
Breadcrumbs
git2cpp
/
test
/
test_clone.py
Copy path
File metadata and controls
263 lines (200 loc) · 10.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import
subprocess
import
pytest
from
.
conftest
import
GIT2CPP_TEST_WASM
,
get_filemode_lines
,
set_filemode
xsimd_url
=
"https://github.com/xtensor-stack/xsimd.git"
xtl_url
=
"https://github.com/xtensor-stack/xtl.git"
def
test_clone
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xtl"
).
exists
()
assert
(
tmp_path
/
"xtl/include"
).
exists
()
def
test_clone_is_bare
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
"--bare"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xtl"
).
is_dir
()
status_cmd
=
[
git2cpp_path
,
"status"
]
p_status
=
subprocess
.
run
(
status_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
/
"xtl"
,
text
=
True
)
assert
p_status
.
returncode
!=
0
assert
"This operation is not allowed against bare repositories"
in
p_status
.
stderr
branch_cmd
=
[
git2cpp_path
,
"branch"
]
p_branch
=
subprocess
.
run
(
branch_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
/
"xtl"
,
text
=
True
)
assert
p_branch
.
returncode
==
0
assert
p_branch
.
stdout
.
strip
()
==
"* master"
def
test_clone_shallow
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
"--depth"
,
"1"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xtl"
).
exists
()
xtl_path
=
tmp_path
/
"xtl"
cmd_log
=
[
git2cpp_path
,
"log"
]
p_log
=
subprocess
.
run
(
cmd_log
,
capture_output
=
True
,
cwd
=
xtl_path
,
text
=
True
)
assert
p_log
.
returncode
==
0
assert
p_log
.
stdout
.
count
(
"Author"
)
==
1
@
pytest
.
mark
.
parametrize
(
"protocol"
, [
"http"
,
"https"
])
def
test_clone_private_repo
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
private_test_repo
,
protocol
):
# Succeeds with correct credentials.
# Note that http succeeds by redirecting to https.
username
=
"abc"
# Can be any non-empty string.
password
=
private_test_repo
[
"token"
]
input
=
f"
{
username
}
\n
{
password
}
\n
"
repo_path
=
tmp_path
/
private_test_repo
[
"repo_name"
]
url
=
private_test_repo
[
"https_url"
if
protocol
==
"https"
else
"http_url"
]
clone_cmd
=
[
git2cpp_path
,
"clone"
,
url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
text
=
True
,
input
=
input
)
assert
p_clone
.
returncode
==
0
assert
repo_path
.
exists
()
# Single request for username and password.
assert
p_clone
.
stdout
.
count
(
"Username:"
)
==
1
assert
p_clone
.
stdout
.
count
(
"Password:"
)
==
1
status_cmd
=
[
git2cpp_path
,
"status"
]
p_status
=
subprocess
.
run
(
status_cmd
,
cwd
=
repo_path
,
capture_output
=
True
,
text
=
True
)
assert
p_status
.
returncode
==
0
assert
"On branch main"
in
p_status
.
stdout
assert
"Your branch is up to date with 'origin/main'"
in
p_status
.
stdout
def
test_clone_private_repo_fails_then_succeeds
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
private_test_repo
):
# Fails with wrong credentials, then succeeds with correct ones.
username
=
"xyz"
# Can be any non-empty string.
password
=
private_test_repo
[
"token"
]
input
=
f"wrong1
\n
wrong2
\n
{
username
}
\n
{
password
}
"
repo_path
=
tmp_path
/
private_test_repo
[
"repo_name"
]
clone_cmd
=
[
git2cpp_path
,
"clone"
,
private_test_repo
[
"https_url"
]]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
text
=
True
,
input
=
input
)
assert
p_clone
.
returncode
==
0
assert
repo_path
.
exists
()
# Two requests for username and password.
assert
p_clone
.
stdout
.
count
(
"Username:"
)
==
2
assert
p_clone
.
stdout
.
count
(
"Password:"
)
==
2
status_cmd
=
[
git2cpp_path
,
"status"
]
p_status
=
subprocess
.
run
(
status_cmd
,
cwd
=
repo_path
,
capture_output
=
True
,
text
=
True
)
assert
p_status
.
returncode
==
0
assert
"On branch main"
in
p_status
.
stdout
assert
"Your branch is up to date with 'origin/main'"
in
p_status
.
stdout
def
test_clone_private_repo_fails_on_no_username
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
private_test_repo
):
input
=
"
\n
"
repo_path
=
tmp_path
/
private_test_repo
[
"repo_name"
]
clone_cmd
=
[
git2cpp_path
,
"clone"
,
private_test_repo
[
"https_url"
]]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
text
=
True
,
input
=
input
)
assert
p_clone
.
returncode
!=
0
assert
"No username specified"
in
p_clone
.
stderr
assert
not
repo_path
.
exists
()
assert
p_clone
.
stdout
.
count
(
"Username:"
)
==
1
assert
p_clone
.
stdout
.
count
(
"Password:"
)
==
0
def
test_clone_private_repo_fails_on_no_password
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
private_test_repo
):
input
=
"username
\n
\n
"
# Note no password between the \n
repo_path
=
tmp_path
/
private_test_repo
[
"repo_name"
]
clone_cmd
=
[
git2cpp_path
,
"clone"
,
private_test_repo
[
"https_url"
]]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
text
=
True
,
input
=
input
)
assert
p_clone
.
returncode
!=
0
assert
"No password specified"
in
p_clone
.
stderr
assert
not
repo_path
.
exists
()
assert
p_clone
.
stdout
.
count
(
"Username:"
)
==
1
assert
p_clone
.
stdout
.
count
(
"Password:"
)
==
1
def
test_clone_private_repo_fails_with_no_credential_callback
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
disable_credential_callback
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
"https://github.com/QuantStack/git2cpp-test-private"
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
text
=
True
)
assert
p_clone
.
returncode
!=
0
assert
"Cloning into 'git2cpp-test-private'..."
in
p_clone
.
stdout
assert
"error: remote authentication required but no callback set"
in
p_clone
.
stderr
@
pytest
.
mark
.
parametrize
(
"protocol"
, [
"http"
,
"https"
])
def
test_clone_gitlab
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
,
protocol
):
repo_url
=
f"
{
protocol
}
://gitlab.quantstack.net/ianthomas23_group/cockle-playground"
clone_cmd
=
[
git2cpp_path
,
"clone"
,
repo_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
repo_path
=
tmp_path
/
"cockle-playground"
assert
repo_path
.
is_dir
()
assert
(
repo_path
/
"src"
).
is_dir
()
status_cmd
=
[
git2cpp_path
,
"status"
]
p_status
=
subprocess
.
run
(
status_cmd
,
capture_output
=
True
,
cwd
=
repo_path
,
text
=
True
)
assert
p_status
.
returncode
==
0
assert
"On branch main"
in
p_status
.
stdout
assert
"Your branch is up to date with 'origin/main'"
in
p_status
.
stdout
@
pytest
.
mark
.
skipif
(
not
GIT2CPP_TEST_WASM
,
reason
=
"Only test in WebAssembly"
)
def
test_clone_timeout
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
# Set very short timeout.
subprocess
.
run
([
"export"
,
"GIT_HTTP_TIMEOUT=0.001"
],
check
=
True
)
# Check timeout is set.
check_env_cmd
=
[
"env"
]
p_check_env
=
subprocess
.
run
(
check_env_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
"GIT_HTTP_TIMEOUT=0.001"
in
p_check_env
.
stdout
# Clone fails with timeout.
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
!=
0
assert
"network request timed out connecting to"
in
p_clone
.
stderr
assert
(
"set a longer timeout in seconds using the environment variable GIT_HTTP_TIMEOUT"
in
p_clone
.
stderr
)
assert
"the current value is 0.001 seconds"
in
p_clone
.
stderr
# Set more reasonable timeout.
subprocess
.
run
([
"export"
,
"GIT_HTTP_TIMEOUT=10"
],
check
=
True
)
# Check timeout is set.
p_check_env
=
subprocess
.
run
(
check_env_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
"GIT_HTTP_TIMEOUT=10"
in
p_check_env
.
stdout
# Clone succeeds.
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xtl"
).
exists
()
assert
(
tmp_path
/
"xtl/include"
).
exists
()
@
pytest
.
mark
.
skipif
(
not
GIT2CPP_TEST_WASM
,
reason
=
"Only test in WebAssembly"
)
def
test_clone_negative_timeout_ignored
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
# Set negative timeout.
subprocess
.
run
([
"export"
,
"GIT_HTTP_TIMEOUT=-1"
],
check
=
True
)
# Check timeout is set.
check_env_cmd
=
[
"env"
]
p_check_env
=
subprocess
.
run
(
check_env_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
"GIT_HTTP_TIMEOUT=-1"
in
p_check_env
.
stdout
# Clone succeeds, ignoring invalid timeout.
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xtl"
).
exists
()
assert
(
tmp_path
/
"xtl/include"
).
exists
()
assert
(
"environment variable GIT_HTTP_TIMEOUT must be a positive number of seconds"
in
p_clone
.
stdout
)
def
test_clone_large_repo
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xsimd_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
assert
(
tmp_path
/
"xsimd"
).
exists
()
assert
(
tmp_path
/
"xsimd/include"
).
exists
()
assert
(
tmp_path
/
"xsimd/xsimdConfig.cmake.in"
).
exists
()
def
test_clone_filemode
(
git2cpp_path
,
tmp_path
,
run_in_tmp_path
):
clone_cmd
=
[
git2cpp_path
,
"clone"
,
xtl_url
]
p_clone
=
subprocess
.
run
(
clone_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_clone
.
returncode
==
0
xtl_path
=
tmp_path
/
"xtl"
filemode_lines
=
get_filemode_lines
(
git2cpp_path
,
xtl_path
)
if
GIT2CPP_TEST_WASM
:
# In WebAssembly core.filemode=false is set by an in-memory config override that has higher
# priority than the repository's config file, so is listed after it.
assert
filemode_lines
==
[
"core.filemode=true"
,
"core.filemode=false"
]
else
:
assert
filemode_lines
==
[
"core.filemode=true"
]
# Setting writes to the repository's config file, not the in-memory override.
set_filemode
(
git2cpp_path
,
xtl_path
,
"true"
)
filemode_lines
=
get_filemode_lines
(
git2cpp_path
,
xtl_path
)
if
GIT2CPP_TEST_WASM
:
assert
filemode_lines
==
[
"core.filemode=true"
,
"core.filemode=false"
]
else
:
assert
filemode_lines
==
[
"core.filemode=true"
]
set_filemode
(
git2cpp_path
,
xtl_path
,
"false"
)
filemode_lines
=
get_filemode_lines
(
git2cpp_path
,
xtl_path
)
if
GIT2CPP_TEST_WASM
:
assert
filemode_lines
==
[
"core.filemode=false"
,
"core.filemode=false"
]
else
:
assert
filemode_lines
==
[
"core.filemode=false"
]
Back
|
FazBrowse Home
|
New Git URL