fork/mons
git clone https://git.julia.blue/fork/mons
4540ca1
misc-fixes
1import logging 2 3import pytest 4from click import ClickException 5 6from mons .commands import main 7from mons .version import Version 8 9 10@ pytest . mark . parametrize ( 11"mock_filesystem" , 12[ 13pytest . param ({}, id = "empty_fs" ), 14pytest . param ( 15{ "proj_1" : [ "unrelated.py" , "different.csproj" , "bin/" ]}, 16id = "no_matching_csproj" , 17), 18], 19indirect = True , 20) 21def test_determine_configuration_no_projects (mock_filesystem ): 22with pytest .raises (ClickException ,match = "No projects found" ): 23main .determine_configuration (mock_filesystem ) 24 25 26# These both result in the same error, but from different places 27@ pytest . mark . parametrize ( 28"mock_filesystem" , 29[ 30pytest . param ( 31{ 32"proj_1" : [ 33"proj_1.csproj" , 34] 35}, 36id = "no bin/" , 37), 38pytest . param ({ "proj_1" : [ "proj_1.csproj" , "bin/" ]}, id = "empty bin/" ), 39], 40indirect = True , 41) 42def test_determine_configuration_no_artifacts (mock_filesystem ): 43with pytest .raises (ClickException ,match = "No build artifacts" ): 44main .determine_configuration (mock_filesystem ) 45 46 47@ pytest . mark . mock_filesystem ( 48{ 49"proj_1" : [ "proj_1.csproj" , { "bin" : { "DEBUG" : { "net452" : "assembly.dll" }}}], 50"proj_2" : [ "proj_2.csproj" , { "bin" : { "DEBUG" : { "core" : "assembly.dll" }}}], 51} 52) 53def test_determine_configuration_no_common (caplog ,mock_filesystem ): 54assert main .determine_configuration (mock_filesystem )is None 55assert "No common output" in caplog .text 56 57 58@ pytest . mark . mock_filesystem ( 59{ 60"proj_1" : [ 61"proj_1.csproj" , 62{ 63"bin" : { 64"DEBUG" : { 65"common" : "assembly.dll" , 66"other" : "assembly.dll" , 67}, 68"RELEASE" : { "net452" : "assembly.dll" }, 69} 70}, 71], 72"proj_2" : [ 73"proj_2.csproj" , 74{ 75"bin" : { 76"DEBUG" : { "common" : "assembly.dll" }, 77"RELEASE" : { 78"net452" : "assembly.dll" , 79"other" : "assembly.dll" , 80}, 81} 82}, 83], 84} 85) 86def test_determine_configuration_most_recent (caplog ,mock_filesystem ): 87with caplog .at_level (logging .DEBUG ,main .__name__ ): 88assert main .determine_configuration (mock_filesystem )== "RELEASE/net452" 89assert "Most recent" in caplog .text 90 91 92@ pytest . mark . mock_filesystem ( 93{ 94"proj_1" : [ 95"proj_1.csproj" , 96{ 97"bin" : { 98"DEBUG" : { 99"common" : "assembly.dll" , 100"other" : "assembly.dll" , 101}, 102"RELEASE" : { "net452" : "assembly.dll" }, 103} 104}, 105], 106"proj_2" : [ 107"proj_2.csproj" , 108{ 109"bin" : { 110"DEBUG" : { "common" : "assembly.dll" }, 111"RELEASE" : { 112"other" : "assembly.dll" , 113}, 114} 115}, 116], 117} 118) 119def test_determine_configuration_one_shared (caplog ,mock_filesystem ): 120with caplog .at_level (logging .DEBUG ,main .__name__ ): 121assert main .determine_configuration (mock_filesystem )== "DEBUG/common" 122assert "Only one" in caplog .text 123 124 125def fetch_build_list (* args ): 126builds = [ 127 {"branch" :"dev" ,"version" :36 }, 128 {"branch" :"beta" ,"version" :35 }, 129 {"branch" :"dev" ,"version" :27 }, 130 {"branch" :"dev" ,"version" :26 }, 131 {"branch" :"beta" ,"version" :25 }, 132 {"branch" :"stable" ,"version" :20 }, 133 {"branch" :"dev" ,"version" :11 }, 134 {"branch" :"stable" ,"version" :10 }, 135 ] 136for build in builds : 137build ["mainDownload" ]= "" 138build ["mainFileSize" ]= 0 139return builds 140 141 142def fetch_latest_build_azure (source ): 143if source == "refs/unknown" : 144return None 145return 5 146 147 148def fetch_build_artifact_azure (build ): 149return "" 150 151 152def build (build :int ): 153return Version (1 ,build ,0 ) 154 155 156@ pytest . mark . parametrize ( 157( "source" , "result" ), 158[ 159pytest . param (build( 20 ), build( 20 ), id = "stable version" ), 160pytest . param (build( 25 ), build( 35 ), id = "beta version" ), 161# This test should pass, but currently only the minor version number is 162# checked anyways. 163pytest . param (Version( 1 , 20 , 0 , Tag = "-beta+azure" ), build( 20 )), 164pytest . param ( "http://test.domain/file.zip" , None , id = "url" ), 165pytest . param ( None , build( 36 ), id = "latest" ), 166pytest . param ( "refs/heads/stable" , build( 5 ), id = "azure" ), 167pytest . param ( "stable" , build( 20 )), 168pytest . param ( "beta" , build( 35 )), 169pytest . param ( "27" , build( 27 )), 170pytest . param ( "1.20.0" , build( 20 )), 171], 172) 173def test_fetch_artifact_source (ctx ,source ,result ): 174version ,_ = main .fetch_artifact_source (ctx ,source ) 175assert version == result 176 177 178@ pytest . mark . parametrize ( 179"source" , 180[ 181# Currently only the minor version number is checked. 182pytest . param (Version( 2 , 10 , 7 , 2 ), marks = pytest . mark . xfail ( strict = True )), 183( "refs/unknown" ), 184( "unknown_string" ), 185( "99" ), 186( "NOVERSION" ), 187# See above 188pytest . param ( "4.25.8+github" , marks = pytest . mark . xfail ( strict = True )), 189], 190) 191def test_fetch_artifact_source_fail (ctx ,source ): 192with pytest .raises (NotImplementedError ): 193main .fetch_artifact_source (ctx ,source ) 194 195 196# This occurrs when no VERSIONSPEC is supplied and the current 197# Everest branch cannot be determined 198def test_fetch_artifact_source_unknown_branch (ctx ): 199with pytest .raises (ClickException ,match = "Could not determine" ): 200main .fetch_artifact_source (ctx ,build (99 ))