okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""Lane NET: the callers of the update feed that run by themselves (a launch, setup's start) say nothing when the feed cannot be reached, in each of the 2three ways: no network at all, a refused port, a server that never answers (tests/terminal/net_dead.py). The callers that need a fixture of their own 3have their test beside their other tests: 4 5shape_engine.ensure tests/terminal/test_shape_engine.py test_an_unreachable_feed_leaves_an_installed_engine_alone_and_says_nothing 6drafting_fetch tests/terminal/test_drafting_tuned.py test_a_feed_nobody_answers_for_is_silent_offline_refused_or_never_answering 7the daily check tests/terminal/test_update_notice.py test_dns_is_blocked / test_a_proxy_that_refuses / test_a_connection_that_never_answers 8 9and here: feed_models.load (the model list at setup's start) and driver_floor.from_feed. A run that DOES explicit work (`strata update`) keeps its 10sentence: feed.FeedUnreachable carries the approved words, and no caller decides by those words (only by the class).""" 11from __future__import annotations 12 13import tempfile 14import time 15import unittest 16from pathlib import Path 17 18from strata_control import driver_floor ,feed as feedmod ,feed_models 19from tests .terminal import net_dead 20 21 22class QuietCallers (unittest .TestCase ): 23def test_the_model_list_read_is_silent_and_keeps_what_it_has (self ): 24for kind in net_dead .KINDS : 25with net_dead .dead_feed (kind )as dead ,tempfile .TemporaryDirectory ()as root : 26lines = [] 27started = time .monotonic () 28loaded = feed_models .load (dead ,fetch = True ,root = Path (root ),trusted = {"k" :b"0" * 32 },say = lines .append ) 29self .assertEqual (list (loaded .models ), [],kind ) 30self .assertEqual (lines , [],kind )# (the waiting line comes after 5 s; these end sooner) 31self .assertLess (time .monotonic ()- started ,5 ,kind ) 32 33def test_the_driver_floor_read_is_silent (self ): 34for kind in net_dead .KINDS : 35with net_dead .dead_feed (kind )as dead : 36self .assertIsNone (driver_floor .from_feed (dead ,"linux-x86_64" ,seconds = 5.0 ),kind ) 37 38def test_an_explicit_update_check_names_the_host_and_is_the_class_the_quiet_callers_catch (self ): 39for kind in net_dead .KINDS : 40with net_dead .dead_feed (kind )as dead : 41with self .assertRaises (feedmod .FeedError )as caught : 42feedmod .fetch (dead , {"k" :b"0" * 32 },timeout = 0.6 ) 43self .assertIsInstance (caught .exception ,feedmod .FeedUnreachable ,kind ) 44self .assertEqual (caught .exception .exit_code ,6 ) 45self .assertIn ("so the update check could not run" ,str (caught .exception ),kind ) 46 47 48if __name__ == "__main__" : 49unittest .main ()