fork/mons
git clone https://git.julia.blue/fork/mons
e96fbdd
misc-fixes
1import os 2import shutil 3import zipfile 4 5import outputs 6import pytest 7 8import mons .commands .main 9from mons .mons import cli as mons_cli 10 11# mock data for Everest build list in ./_data/build_list 12 13GITHUB_REPO = "https://github.com/EverestAPI/Everest" 14 15 16@ pytest . fixture ( autouse = True ) 17def mock_installer (monkeypatch ): 18monkeypatch .setattr (mons .commands .main ,"download_artifact" ,lambda * args :None ) 19monkeypatch .setattr (mons .commands .main ,"run_installer" ,lambda * args :True ) 20 21 22def test_install_default (runner_result ,test_install ): 23# install preferred branch, set to a stable version by `test_install` fixture 24with runner_result (mons_cli , ["install" ,test_install ])as result : 25assert result .exit_code == 0 26assert outputs .INSTALL_SUCCESS in result .output 27 28 29def test_install_branch (runner_result ,test_install ): 30with runner_result (mons_cli , ["install" ,test_install ,"stable" ])as result : 31assert result .exit_code == 0 32assert outputs .INSTALL_SUCCESS in result .output 33 34 35def test_install_url (runner_result ,test_install ): 36url = f" { GITHUB_REPO } /releases/latest/download/main.zip" 37 38with runner_result (mons_cli , ["install" ,test_install ,url ])as result : 39assert result .exit_code == 0 40assert outputs .INSTALL_SUCCESS in result .output 41 42 43@ pytest . mark . data_file_download ( 44f" { GITHUB_REPO } /releases/latest/download/olympus-build.zip" , "olympus-build.zip" 45) 46def test_install_zip (runner_result ,test_install ,data_file_download ): 47with runner_result ( 48mons_cli , ["install" ,test_install ,data_file_download ] 49 )as result : 50assert result .exit_code == 0 51assert outputs .INSTALL_SUCCESS in result .output 52 53 54@ pytest . mark . data_file_download ( 55f" { GITHUB_REPO } /releases/latest/download/olympus-build.zip" , "olympus-build.zip" 56) 57def test_install_stdin (runner_result ,test_install ,data_file_download ): 58with open (data_file_download )as data : 59with runner_result ( 60mons_cli , ["install" ,test_install ,"-" ],input = data 61 )as result : 62assert result .exit_code == 0 63assert outputs .INSTALL_SUCCESS in result .output 64 65 66@ pytest . mark . xfail ( 67not ( shutil . which ( "dotnet" ) or shutil . which ( "msbuild" )), 68reason = "no .NET build tool found" , 69run = False , 70) 71@ pytest . mark . data_file_download ( 72f" { GITHUB_REPO } /archive/refs/heads/stable.zip" , "stable.zip" 73) 74def test_install_src (runner_result ,test_install ,cache ,data_file_download ): 75source_dir = os .path .join (cache .mkdir ("mons_test_install" ),"Everest-stable" ) 76if not os .path .exists (source_dir ): 77with zipfile .ZipFile (data_file_download ,"r" )as zip : 78zip .extractall (cache .mkdir ("mons_test_install" )) 79 80assert os .listdir (source_dir ),"Failed to download source artifact: " + source_dir 81 82with runner_result ( 83mons_cli , ["install" ,test_install ,"--src" ,source_dir ] 84 )as result : 85assert result .exit_code == 0 86assert outputs .INSTALL_SUCCESS in result .output 87assert "Building Everest source" in result .output 88 89# Previous command builds straight to `test_install.path`. 90# Build artifacts in in place so that `--no-build` is possible. 91mons .commands .main .build_source (source_dir ,None ,False ,None , []) 92with runner_result ( 93mons_cli , ["install" ,test_install ,"--src" ,source_dir ,"--no-build" ] 94 )as result : 95assert result .exit_code == 0 96assert outputs .INSTALL_SUCCESS in result .output 97assert "Copying build artifacts" in result .output