|
18 | 18 | from libvcs.sync.hg import HgSync |
19 | 19 | from libvcs.sync.svn import SvnSync |
20 | 20 |
|
| 21 | +# Async support - conditional import |
| 22 | +try: |
| 23 | + import pytest_asyncio |
| 24 | + |
| 25 | + from libvcs.sync._async.git import AsyncGitSync |
| 26 | + |
| 27 | + HAS_PYTEST_ASYNCIO = True |
| 28 | +except ImportError: |
| 29 | + HAS_PYTEST_ASYNCIO = False |
| 30 | + |
21 | 31 |
|
22 | 32 | class MaxUniqueRepoAttemptsExceeded(exc.LibVCSException): |
23 | 33 | """Raised when exceeded threshold of attempts to find a unique repo destination.""" |
@@ -780,6 +790,49 @@ def svn_repo( |
780 | 790 | return svn_repo |
781 | 791 |
|
782 | 792 |
|
| 793 | +# ============================================================================= |
| 794 | +# Async Fixtures |
| 795 | +# ============================================================================= |
| 796 | + |
| 797 | +if HAS_PYTEST_ASYNCIO: |
| 798 | + |
| 799 | + @pytest_asyncio.fixture |
| 800 | + @skip_if_git_missing |
| 801 | + async def async_git_repo( |
| 802 | + remote_repos_path: pathlib.Path, |
| 803 | + projects_path: pathlib.Path, |
| 804 | + git_remote_repo: pathlib.Path, |
| 805 | + set_gitconfig: pathlib.Path, |
| 806 | + ) -> t.AsyncGenerator[AsyncGitSync, None]: |
| 807 | + """Pre-made async git clone of remote repo checked out to user's projects dir. |
| 808 | +
|
| 809 | + Async equivalent of :func:`git_repo` fixture. |
| 810 | +
|
| 811 | + Examples |
| 812 | + -------- |
| 813 | + >>> @pytest.mark.asyncio |
| 814 | + ... async def test_git_operations(async_git_repo): |
| 815 | + ... revision = await async_git_repo.get_revision() |
| 816 | + ... assert revision is not None |
| 817 | + """ |
| 818 | + remote_repo_name = unique_repo_name(remote_repos_path=projects_path) |
| 819 | + new_checkout_path = projects_path / remote_repo_name |
| 820 | + |
| 821 | + repo = AsyncGitSync( |
| 822 | + url=f"file://{git_remote_repo}", |
| 823 | + path=new_checkout_path, |
| 824 | + remotes={ |
| 825 | + "origin": GitRemote( |
| 826 | + name="origin", |
| 827 | + push_url=f"file://{git_remote_repo}", |
| 828 | + fetch_url=f"file://{git_remote_repo}", |
| 829 | + ), |
| 830 | + }, |
| 831 | + ) |
| 832 | + await repo.obtain() |
| 833 | + yield repo |
| 834 | + |
| 835 | + |
783 | 836 | @pytest.fixture |
784 | 837 | def add_doctest_fixtures( |
785 | 838 | request: pytest.FixtureRequest, |
|
0 commit comments