@@ -552,12 +552,34 @@ def hg_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> No
552552 run (["hg" , "commit" , "-m" , "test file for hg repo" ], cwd = remote_repo_path )
553553
554554
555- @pytest .fixture
555+ @pytest .fixture (scope = "session" )
556+ def empty_hg_repo_path (libvcs_test_cache_path : pathlib .Path ) -> pathlib .Path :
557+ """Return temporary directory to use for master-copy of a hg repo."""
558+ return libvcs_test_cache_path / "empty_hg_repo"
559+
560+
561+ @pytest .fixture (scope = "session" )
562+ @skip_if_hg_missing
563+ def empty_hg_repo (
564+ empty_hg_repo_path : pathlib .Path ,
565+ ) -> pathlib .Path :
566+ """Return factory to create hg remote repo to for clone / push purposes."""
567+ if empty_hg_repo_path .exists () and (empty_hg_repo_path / ".hg" ).exists ():
568+ return empty_hg_repo_path
569+
570+ return _create_hg_remote_repo (
571+ remote_repos_path = empty_hg_repo_path .parent ,
572+ remote_repo_name = empty_hg_repo_path .stem ,
573+ remote_repo_post_init = None ,
574+ init_cmd_args = None ,
575+ )
576+
577+
578+ @pytest .fixture (scope = "session" )
556579@skip_if_hg_missing
557580def create_hg_remote_repo (
558581 remote_repos_path : pathlib .Path ,
559- hgconfig : pathlib .Path ,
560- set_home : pathlib .Path ,
582+ empty_hg_repo : pathlib .Path ,
561583) -> CreateRepoPytestFixtureFn :
562584 """Pre-made hg repo, bare, used as a file:// remote to checkout and commit to."""
563585
@@ -567,30 +589,34 @@ def fn(
567589 remote_repo_post_init : Optional [CreateRepoPostInitFn ] = None ,
568590 init_cmd_args : InitCmdArgs = None ,
569591 ) -> pathlib .Path :
570- return _create_hg_remote_repo (
571- remote_repos_path = remote_repos_path ,
572- remote_repo_name = remote_repo_name
573- if remote_repo_name is not None
574- else unique_repo_name (remote_repos_path = remote_repos_path ),
575- remote_repo_post_init = remote_repo_post_init ,
576- init_cmd_args = init_cmd_args ,
577- )
592+ if remote_repo_name is None :
593+ remote_repo_name = unique_repo_name (remote_repos_path = remote_repos_path )
594+ remote_repo_path = remote_repos_path / remote_repo_name
595+
596+ shutil .copytree (empty_hg_repo , remote_repo_path )
597+
598+ if remote_repo_post_init is not None and callable (remote_repo_post_init ):
599+ remote_repo_post_init (remote_repo_path = remote_repo_path )
600+
601+ assert empty_hg_repo .exists ()
602+
603+ assert remote_repo_path .exists ()
604+
605+ return remote_repo_path
578606
579607 return fn
580608
581609
582- @pytest .fixture
610+ @pytest .fixture ( scope = "session" )
583611@skip_if_hg_missing
584612def hg_remote_repo (
585613 remote_repos_path : pathlib .Path ,
586- hgconfig : pathlib . Path ,
614+ create_hg_remote_repo : CreateRepoPytestFixtureFn ,
587615) -> pathlib .Path :
588616 """Pre-made, file-based repo for push and pull."""
589- return _create_hg_remote_repo (
590- remote_repos_path = remote_repos_path ,
591- remote_repo_name = "dummyrepo" ,
592- remote_repo_post_init = hg_remote_repo_single_commit_post_init ,
593- )
617+ repo_path = create_hg_remote_repo ()
618+ hg_remote_repo_single_commit_post_init (remote_repo_path = repo_path )
619+ return repo_path
594620
595621
596622@pytest .fixture
@@ -640,6 +666,7 @@ def add_doctest_fixtures(
640666 tmp_path : pathlib .Path ,
641667 set_home : pathlib .Path ,
642668 gitconfig : pathlib .Path ,
669+ hgconfig : pathlib .Path ,
643670 create_git_remote_repo : CreateRepoPytestFixtureFn ,
644671 create_svn_remote_repo : CreateRepoPytestFixtureFn ,
645672 create_hg_remote_repo : CreateRepoPytestFixtureFn ,
@@ -667,6 +694,7 @@ def add_doctest_fixtures(
667694 remote_repo_post_init = svn_remote_repo_single_commit_post_init ,
668695 )
669696 if shutil .which ("hg" ):
697+ doctest_namespace ["hgconfig" ] = hgconfig
670698 doctest_namespace ["create_hg_remote_repo_bare" ] = create_hg_remote_repo
671699 doctest_namespace ["create_hg_remote_repo" ] = functools .partial (
672700 create_hg_remote_repo ,
0 commit comments