|
| 1 | +import os |
| 2 | +import sys |
| 3 | + |
| 4 | +import pygit2 |
1 | 5 | import pytest |
2 | | -from pytest_test_utils import TmpDir |
| 6 | +from pytest_test_utils import TempDirFactory, TmpDir |
3 | 7 |
|
4 | 8 | from scmrepo.git import Git |
5 | 9 |
|
6 | 10 |
|
7 | | -@pytest.fixture |
8 | | -def scm(tmp_dir: TmpDir, monkeypatch: pytest.MonkeyPatch): |
| 11 | +@pytest.fixture(autouse=True) |
| 12 | +def isolate(tmp_dir_factory: TempDirFactory, monkeypatch: pytest.MonkeyPatch): |
| 13 | + path = tmp_dir_factory.mktemp("mock") |
| 14 | + home_dir = path / "home" |
| 15 | + home_dir.mkdir() |
| 16 | + |
| 17 | + if sys.platform == "win32": |
| 18 | + home_drive, home_path = os.path.splitdrive(home_dir) |
| 19 | + monkeypatch.setenv("USERPROFILE", str(home_dir)) |
| 20 | + monkeypatch.setenv("HOMEDRIVE", home_drive) |
| 21 | + monkeypatch.setenv("HOMEPATH", home_path) |
| 22 | + else: |
| 23 | + monkeypatch.setenv("HOME", str(home_dir)) |
| 24 | + |
9 | 25 | monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1") |
10 | | - monkeypatch.setenv("GIT_AUTHOR_NAME", "DVC test user") |
11 | | - monkeypatch.setenv("GIT_AUTHOR_EMAIL", "dvctester@example.com") |
| 26 | + contents = b""" |
| 27 | +[user] |
| 28 | +name=DVC Tester |
| 29 | +email=dvctester@example.com |
| 30 | +[init] |
| 31 | +defaultBranch=master |
| 32 | +""" |
| 33 | + (home_dir / ".gitconfig").write_bytes(contents) |
| 34 | + pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir) |
12 | 35 |
|
| 36 | + |
| 37 | +@pytest.fixture |
| 38 | +def scm(tmp_dir: TmpDir): |
13 | 39 | git_ = Git.init(tmp_dir) |
| 40 | + sig = git_.pygit2.default_signature |
| 41 | + |
| 42 | + assert sig.email == "dvctester@example.com" |
| 43 | + assert sig.name == "DVC Tester" |
| 44 | + |
14 | 45 | yield git_ |
15 | 46 | git_.close() |
0 commit comments