okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c7938c2d3
main
1"""Terminal polish (0.2.1): "already downloaded" instead of a fake download, and `strata monitor` finding a running launch.""" 2 3import io 4import json 5import os 6import unittest 7from contextlib import redirect_stdout 8from unittest import mock 9 10from strata_cli .cli import main 11from strata_cli .launch .runner import download_text 12 13 14class AlreadyDownloaded (unittest .TestCase ): 15def test_a_model_on_disk_is_not_called_a_download (self ): 16dl = {"done_gb" :58.5 ,"total_gb" :58.5 ,"percent" :100.0 } 17self .assertEqual (download_text (dl ,True ),"The model files are already on this computer (58.5 GB); checking them" ) 18 19def test_a_real_download_keeps_its_numbers (self ): 20dl = {"done_gb" :12.0 ,"total_gb" :58.5 ,"percent" :20.5 } 21self .assertEqual (download_text (dl ,False ),"Downloading 12.0 of 58.5 GB" ) 22self .assertEqual (download_text (dl ,False ,"Downloading the draft layer" ),"Downloading the draft layer: 12.0 of 58.5 GB" ) 23 24 25class MonitorFindsLaunch (unittest .TestCase ): 26def _run (self ,argv ,info ,env = None ): 27with mock .patch .dict (os .environ ,env or {},clear = False ), \ 28mock .patch ("strata_cli.launch.cmd.launch_info" ,return_value = info ), \ 29mock .patch ("strata_cli.monitor_commands.Endpoint" )as endpoint : 30os .environ .pop ("STRATA_URL" ,None )if not env else None 31endpoint .return_value .snapshot .return_value = {"schema_version" :1 } 32out = io .StringIO () 33with redirect_stdout (out ): 34main (argv ) 35return endpoint 36 37def test_no_url_uses_the_running_launch_and_its_key (self ): 38info = {"running" :True ,"url" :"http://127.0.0.1:8080" ,"key" :"launch-key" } 39with mock .patch .dict (os .environ , {},clear = False ): 40os .environ .pop ("STRATA_API_KEY" ,None ) 41endpoint = self ._run (["monitor" ,"--once" ,"--quiet" ],info ) 42args = endpoint .call_args [0 ] 43self .assertEqual (args [0 ],"http://127.0.0.1:8080" ) 44self .assertEqual (args [1 ],"launch-key" ) 45 46def test_an_explicit_url_wins (self ): 47info = {"running" :True ,"url" :"http://127.0.0.1:8080" ,"key" :"k" } 48endpoint = self ._run (["monitor" ,"--once" ,"--quiet" ,"--url" ,"http://127.0.0.1:9999" ],info ) 49self .assertEqual (endpoint .call_args [0 ][0 ],"http://127.0.0.1:9999" ) 50 51def test_nothing_running_keeps_the_default_address (self ): 52endpoint = self ._run (["monitor" ,"--once" ,"--quiet" ],None ) 53self .assertEqual (endpoint .call_args [0 ][0 ],"http://127.0.0.1:8095" ) 54 55 56if __name__ == "__main__" : 57unittest .main ()