@@ -72,6 +72,7 @@ def gitconfig(user_path: pathlib.Path, home_default: pathlib.Path):
7272
7373
7474@pytest .fixture (autouse = True , scope = "session" )
75+ @pytest .mark .usefixtures ("home_default" )
7576@skip_if_hg_missing
7677def hgconfig (user_path : pathlib .Path ):
7778 hgrc = user_path / ".hgrc"
@@ -169,7 +170,6 @@ def fn(
169170
170171def git_remote_repo_single_commit_post_init (remote_repo_path : pathlib .Path ):
171172 testfile_filename = "testfile.test"
172-
173173 run (["touch" , testfile_filename ], cwd = remote_repo_path )
174174 run (["git" , "add" , testfile_filename ], cwd = remote_repo_path )
175175 run (["git" , "commit" , "-m" , "test file for dummyrepo" ], cwd = remote_repo_path )
@@ -238,22 +238,60 @@ def svn_remote_repo(remote_repos_path: pathlib.Path) -> pathlib.Path:
238238 return remote_repo_path
239239
240240
241+ def _create_hg_remote_repo (
242+ remote_repos_path : pathlib .Path ,
243+ remote_repo_name : str ,
244+ remote_repo_post_init : Optional [CreateRepoCallbackProtocol ] = None ,
245+ ) -> pathlib .Path :
246+ """Create a test hg repo to for checkout / commit purposes"""
247+ remote_repo_path = remote_repos_path / remote_repo_name
248+ run (["hg" , "init" , remote_repo_name ], cwd = remote_repos_path )
249+
250+ if remote_repo_post_init is not None and callable (remote_repo_post_init ):
251+ remote_repo_post_init (remote_repo_path = remote_repo_path )
252+
253+ return remote_repo_path
254+
255+
256+ def hg_remote_repo_single_commit_post_init (remote_repo_path : pathlib .Path ):
257+ testfile_filename = "testfile.test"
258+ run (["touch" , testfile_filename ], cwd = remote_repo_path )
259+ run (["hg" , "add" , testfile_filename ], cwd = remote_repo_path )
260+ run (["hg" , "commit" , "-m" , "test file for hg repo" ], cwd = remote_repo_path )
261+
262+
241263@pytest .fixture
264+ @pytest .mark .usefixtures ("hgconfig" )
242265@skip_if_hg_missing
243- def hg_remote_repo (projects_path ):
244- """Pre-made, file-based repo for push and pull."""
245- name = "test_hg_repo"
246- repo_path = projects_path / name
266+ def create_hg_remote_repo (remote_repos_path : pathlib .Path , faker : Faker ):
267+ """Pre-made hg repo, bare, used as a file:// remote to checkout and commit to."""
247268
248- run (["hg" , "init" , name ], cwd = projects_path )
269+ def fn (
270+ remote_repos_path : pathlib .Path = remote_repos_path ,
271+ remote_repo_name : Optional [str ] = None ,
272+ remote_repo_post_init : Optional [CreateRepoCallbackProtocol ] = None ,
273+ ):
274+ return _create_hg_remote_repo (
275+ remote_repos_path = remote_repos_path ,
276+ remote_repo_name = remote_repo_name
277+ if remote_repo_name is not None
278+ else faker .word (),
279+ remote_repo_post_init = remote_repo_post_init ,
280+ )
249281
250- testfile_filename = "testfile.test"
282+ return fn
251283
252- run (["touch" , testfile_filename ], cwd = repo_path )
253- run (["hg" , "add" , testfile_filename ], cwd = repo_path )
254- run (["hg" , "commit" , "-m" , "test file for %s" % name ], cwd = repo_path )
255284
256- return repo_path
285+ @pytest .fixture
286+ @pytest .mark .usefixtures ("hgconfig" )
287+ @skip_if_hg_missing
288+ def hg_remote_repo (remote_repos_path : pathlib .Path ):
289+ """Pre-made, file-based repo for push and pull."""
290+ return _create_hg_remote_repo (
291+ remote_repos_path = remote_repos_path ,
292+ remote_repo_name = "dummyrepo" ,
293+ remote_repo_post_init = hg_remote_repo_single_commit_post_init ,
294+ )
257295
258296
259297@pytest .fixture
@@ -283,6 +321,7 @@ def add_doctest_fixtures(
283321 gitconfig : pathlib .Path ,
284322 create_git_remote_repo : CreateRepoCallbackFixtureProtocol ,
285323 create_svn_remote_repo : CreateRepoCallbackFixtureProtocol ,
324+ create_hg_remote_repo : CreateRepoCallbackFixtureProtocol ,
286325):
287326 doctest_namespace ["tmp_path" ] = tmp_path
288327 if which ("git" ):
@@ -292,3 +331,7 @@ def add_doctest_fixtures(
292331 )
293332 if which ("svn" ):
294333 doctest_namespace ["svn_remote_repo" ] = create_svn_remote_repo ()
334+ if which ("hg" ):
335+ doctest_namespace ["hg_remote_repo" ] = create_hg_remote_repo (
336+ remote_repo_post_init = hg_remote_repo_single_commit_post_init
337+ )
0 commit comments