-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconftest.py
More file actions
50 lines (35 loc) · 1.37 KB
/
conftest.py
File metadata and controls
50 lines (35 loc) · 1.37 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import pytest
import runez
from runez.conftest import cli, ClickRunner, logged # noqa: F401, fixtures
from runez.pyenv import PythonDepot
from pickley import bstrap
from pickley.cli import CFG, main
def mocked_expanduser(path):
if path and path.startswith("~/"):
path = path[2:]
return path
ClickRunner.default_main = main
PythonDepot.use_path = False
bstrap.expanduser = mocked_expanduser
TEST_UV = bstrap.UvBootstrap(runez.to_path(runez.DEV.project_path("build/test-uv")))
TEST_UV.auto_bootstrap_uv()
class TemporaryBase(runez.TempFolder):
def __enter__(self):
super(TemporaryBase, self).__enter__()
os.environ["PICKLEY_ROOT"] = self.tmp_folder
# Provide a `uv` binary out-of-the-box so that tests don't have to bootstrap uv over and over
runez.copy(TEST_UV.uv_path, os.path.join(self.tmp_folder, "uv"), logger=None)
runez.touch(os.path.join(self.tmp_folder, ".pk/.cache/uv.cooldown"), logger=None)
runez.save_json({"vpickley": "0.0.0"}, ".pk/.manifest/.bootstrap.json", logger=None)
CFG.reset()
return self.tmp_folder
def __exit__(self, *_):
super(TemporaryBase, self).__exit__(*_)
del os.environ["PICKLEY_ROOT"]
ClickRunner.context_wrapper = TemporaryBase
@pytest.fixture
def temp_cfg():
with TemporaryBase() as base:
CFG.set_base(base)
yield CFG