11import pytest
22import tempfile
3+ import os
34
45from importlib_resources import files
56from pytest import mark as m
67from pathlib import Path
7- from pins .tests .helpers import BoardBuilder , RscBoardBuilder , Snapshot
8+ from pins .tests .helpers import BoardBuilder , RscBoardBuilder , Snapshot , rm_env
9+
10+ PATH_TO_EXAMPLE_BOARD = files ("pins" ) / "tests/pins-compat"
11+
812
913# Based on https://github.com/machow/siuba/blob/main/siuba/tests/helpers.py
1014BACKEND_MARKS = ["fs_s3" , "fs_file" , "fs_rsc" ]
1115
12- param_rsc = pytest .param (lambda : RscBoardBuilder ("rsc" ), id = "rsc" , marks = m .fs_rsc )
13-
14- params_backend = [
16+ # parameters that can be used more than once per session
17+ params_safe = [
1518 pytest .param (lambda : BoardBuilder ("file" ), id = "file" , marks = m .fs_file ),
1619 pytest .param (lambda : BoardBuilder ("s3" ), id = "s3" , marks = m .fs_s3 ),
17- param_rsc ,
1820]
1921
22+ # rsc should only be used once, because users are created at docker setup time
23+ param_rsc = pytest .param (lambda : RscBoardBuilder ("rsc" ), id = "rsc" , marks = m .fs_rsc )
24+
25+ params_backend = [* params_safe , param_rsc ]
26+
2027
2128@pytest .fixture (params = params_backend , scope = "session" )
2229def backend (request ):
@@ -25,6 +32,15 @@ def backend(request):
2532 backend .teardown ()
2633
2734
35+ @pytest .fixture (scope = "session" )
36+ def http_example_board_path ():
37+ # backend = BoardBuilder("s3")
38+ # yield backend.create_tmp_board(str(PATH_TO_EXAMPLE_BOARD.absolute())).board
39+ # backend.teardown()
40+ # TODO: could putting it in a publically available bucket folder
41+ return "https://raw.githubusercontent.com/machow/pins-python/main/pins/tests/pins-compat"
42+
43+
2844@pytest .fixture
2945def snapshot (request ):
3046 p_snap = files ("pins" ) / "tests/_snapshots" / request .node .originalname
@@ -49,6 +65,22 @@ def tmp_dir2():
4965 yield Path (tmp_dir )
5066
5167
68+ @pytest .fixture
69+ def tmp_cache (tmp_dir2 ):
70+ with rm_env ("PINS_CACHE_DIR" ):
71+ os .environ ["PINS_CACHE_DIR" ] = str (tmp_dir2 )
72+
73+ yield tmp_dir2
74+
75+
76+ @pytest .fixture
77+ def tmp_data_dir (tmp_dir2 ):
78+ with rm_env ("PINS_DATA_DIR" ):
79+ os .environ ["PINS_DATA_DIR" ] = str (tmp_dir2 )
80+
81+ yield tmp_dir2
82+
83+
5284def pytest_addoption (parser ):
5385 parser .addoption ("--snapshot-update" , action = "store_true" )
5486
0 commit comments