File: test_utils.py

package info (click to toggle)
pytest-codspeed 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,608 kB
  • sloc: ansic: 9,792; python: 2,066; sh: 41; makefile: 14
file content (34 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import tempfile
from contextlib import contextmanager
from pathlib import Path

from pytest_codspeed.utils import get_git_relative_path, get_git_relative_uri_and_name


@contextmanager
def TemporaryGitRepo():
    with tempfile.TemporaryDirectory() as tmpdirname:
        (Path(tmpdirname) / ".git").mkdir(parents=True)
        yield tmpdirname


def test_get_git_relative_path_found():
    with TemporaryGitRepo() as tmp_repo:
        path = Path(tmp_repo) / "folder/nested_folder"
        assert get_git_relative_path(path) == Path("folder/nested_folder")


def test_get_git_relative_path_not_found():
    with tempfile.TemporaryDirectory() as tmp_dir:
        path = Path(tmp_dir) / "folder"
        assert get_git_relative_path(path) == path


def test_get_git_relative_uri():
    with TemporaryGitRepo() as tmp_repo:
        pytest_rootdir = Path(tmp_repo) / "pytest_root"
        uri = "testing/test_excinfo.py::TestFormattedExcinfo::test_fn"
        assert get_git_relative_uri_and_name(uri, pytest_rootdir) == (
            "pytest_root/testing/test_excinfo.py::TestFormattedExcinfo::test_fn",
            "TestFormattedExcinfo::test_fn",
        )