2
2
import functools
3
3
import getpass
4
4
import pathlib
5
+ import random
5
6
import shutil
6
7
import textwrap
7
8
from typing import Any , Optional , Protocol
10
11
11
12
from _pytest .doctest import DoctestItem
12
13
from _pytest .fixtures import SubRequest
13
- from faker import Faker
14
14
15
15
from libvcs ._internal .run import run
16
16
from libvcs .sync .git import GitRemote , GitSync
28
28
)
29
29
30
30
31
+ class RandomStrSequence :
32
+ def __init__ (
33
+ self , characters : str = "abcdefghijklmnopqrstuvwxyz0123456789_"
34
+ ) -> None :
35
+ self .characters : str = characters
36
+
37
+ def __iter__ (self ) -> "RandomStrSequence" :
38
+ return self
39
+
40
+ def __next__ (self ) -> str :
41
+ return "" .join (random .sample (self .characters , k = 8 ))
42
+
43
+
44
+ namer = RandomStrSequence ()
45
+
46
+
31
47
def pytest_ignore_collect (collection_path : pathlib .Path , config : pytest .Config ) -> bool :
32
48
if not shutil .which ("svn" ) and any (
33
49
needle in str (collection_path ) for needle in ["svn" , "subversion" ]
@@ -153,16 +169,14 @@ def clean() -> None:
153
169
return dir
154
170
155
171
156
- def unique_repo_name (
157
- faker : Faker , remote_repos_path : pathlib .Path , max_retries : int = 15
158
- ) -> str :
172
+ def unique_repo_name (remote_repos_path : pathlib .Path , max_retries : int = 15 ) -> str :
159
173
attempts = 1
160
174
while True :
161
175
if attempts > max_retries :
162
176
raise Exception (
163
177
f"Could not find unused repo destination (attempts: { attempts } )"
164
178
)
165
- remote_repo_name : str = faker . slug ( )
179
+ remote_repo_name : str = next ( namer )
166
180
suggestion = remote_repos_path / remote_repo_name
167
181
if suggestion .exists ():
168
182
attempts += 1
@@ -202,7 +216,7 @@ def _create_git_remote_repo(
202
216
@pytest .fixture
203
217
@skip_if_git_missing
204
218
def create_git_remote_repo (
205
- remote_repos_path : pathlib .Path , faker : Faker
219
+ remote_repos_path : pathlib .Path ,
206
220
) -> CreateProjectCallbackFixtureProtocol :
207
221
"""Factory. Create git remote repo to for clone / push purposes"""
208
222
@@ -215,7 +229,7 @@ def fn(
215
229
remote_repos_path = remote_repos_path ,
216
230
remote_repo_name = remote_repo_name
217
231
if remote_repo_name is not None
218
- else unique_repo_n
8000
ame (faker = faker , remote_repos_path = remote_repos_path ),
232
+ else unique_repo_name (remote_repos_path = remote_repos_path ),
219
233
remote_repo_post_init = remote_repo_post_init ,
220
234
)
221
235
@@ -260,7 +274,7 @@ def _create_svn_remote_repo(
260
274
@pytest .fixture
261
275
@skip_if_svn_missing
262
276
def create_svn_remote_repo (
263
- remote_repos_path : pathlib .Path , faker : Faker
277
+ remote_repos_path : pathlib .Path ,
264
278
) -> CreateProjectCallbackFixtureProtocol :
265
279
"""Pre-made svn repo, bare, used as a file:// remote to checkout and commit to."""
266
280
@@ -273,7 +287,7 @@ def fn(
273
287
remote_repos_path = remote_repos_path ,
274
288
remote_repo_name = remote_repo_name
275
289
if remote_repo_name is not None
276
- else unique_repo_name (faker = faker , remote_repos_path = remote_repos_path ),
290
+ else unique_repo_name (remote_repos_path = remote_repos_path ),
277
291
remote_repo_post_init = remote_repo_post_init ,
278
292
)
279
293
@@ -320,7 +334,6 @@ def hg_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> No
320
334
@skip_if_hg_missing
321
335
def create_hg_remote_repo (
322
336
remote_repos_path : pathlib .Path ,
323
- faker : Faker ,
324
337
hgconfig : pathlib .Path ,
325
338
set_home : pathlib .Path ,
326
339
) -> CreateProjectCallbackFixtureProtocol :
@@ -335,7 +348,7 @@ def fn(
335
348
remote_repos_path = remote_repos_path ,
336
349
remote_repo_name = remote_repo_name
337
350
if remote_repo_name is not None
338
- else unique_repo_name (faker = faker , remote_repos_path = remote_repos_path ),
351
+ else unique_repo_name (remote_repos_path = remote_repos_path ),
339
352
remote_repo_post_init = remote_repo_post_init ,
340
353
)
341
354
0 commit comments