fork/mons
git clone https://git.julia.blue/fork/mons
c43b1d6
fixes
1import errno 2import os 3import pathlib 4import sys 5from importlib import reload 6 7import pytest 8 9import mons .install 10from mons .mons import cli as mons_cli 11from mons .version import Version 12 13 14def pytest_collection_modifyitems (session ,config ,items ): 15module = pathlib .Path (os .path .dirname (__file__ )) 16for item in items : 17if module == item .path .parent : 18item .add_marker (pytest .mark .slow_integration_test ) 19 20 21# We only need to log this warning once for each test run 22log_test_install_warning = True 23 24 25@ pytest . fixture ( scope = "function" ) 26def test_install_path (pytestconfig :pytest .Config ,cache :pytest .Cache ): 27# prioritize cmdline arg so that it can be changed 28install_path :str = pytestconfig .getoption ("mons_test_install" ,cache .get ("mons/test_install" ,None ))# type: ignore 29 30if not install_path : 31global log_test_install_warning 32if log_test_install_warning : 33log_test_install_warning = True 34pytest .skip ( 35"Test install not configured. Use the `--mons-test-install` cmdline flag to provide a test install." 36 ) 37pytest .skip () 38 39if os .path .exists (install_path ): 40install_path = os .path .abspath (install_path ) 41cache .set ("mons/test_install" ,install_path ) 42return install_path 43else : 44raise FileNotFoundError (errno .ENOENT ,os .strerror (errno .ENOENT ),install_path ) 45 46 47@ pytest . fixture ( scope = "function" ) 48def test_install (runner ,test_name ,test_install_path ,monkeypatch ): 49# use a stable version number for default branch detection 50monkeypatch .setattr ( 51mons .install , 52"parse_exe" , 53lambda * args : (Version (1 ,4 ,0 ,0 ),Version (1 ,4030 ,0 ),"FNA" ), 54 ) 55 56install_name = f"_pytest_ { test_name } " 57result = runner .invoke (mons_cli , ["add" ,install_name ,test_install_path ]) 58if result .exit_code != 0 : 59pytest .skip (result .output ) 60return install_name 61 62 63@ pytest . fixture ( autouse = True ) 64def set_env (monkeypatch ): 65monkeypatch .setenv ("MONS_DEBUG" ,"true" ) 66 67 68@ pytest . fixture ( autouse = True ) 69def isolated_filesystem (monkeypatch :pytest .MonkeyPatch ,tmp_path ): 70"""Isolate all referenced files to temp folder""" 71user_dirs = ["config" ,"cache" ,"data" ] 72ret = dict () 73for dir in user_dirs : 74monkeypatch .setattr ( 75f"mons.config.PlatformDirs.user_ { dir } _dir" ,os .path .join (tmp_path ,dir ) 76 ) 77ret [f" { dir } _dir" ]= os .path .join (tmp_path ,dir ) 78# reload the config module to re-assign global constants 79reload (sys .modules ["mons.config" ]) 80return ret