okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
2.7 KiB49 linesraw
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
5  shape_engine.ensure    tests/terminal/test_shape_engine.py     test_an_unreachable_feed_leaves_an_installed_engine_alone_and_says_nothing
6  drafting_fetch         tests/terminal/test_drafting_tuned.py   test_a_feed_nobody_answers_for_is_silent_offline_refused_or_never_answering
7  the 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):
23    def test_the_model_list_read_is_silent_and_keeps_what_it_has(self):
24        for kind in net_dead.KINDS:
25            with net_dead.dead_feed(kind) as dead, tempfile.TemporaryDirectory() as root:
26                lines = []
27                started = time.monotonic()
28                loaded = feed_models.load(dead, fetch=True, root=Path(root), trusted={"k": b"0" * 32}, say=lines.append)
29                self.assertEqual(list(loaded.models), [], kind)
30                self.assertEqual(lines, [], kind)                    # (the waiting line comes after 5 s; these end sooner)
31                self.assertLess(time.monotonic() - started, 5, kind)
32
33    def test_the_driver_floor_read_is_silent(self):
34        for kind in net_dead.KINDS:
35            with net_dead.dead_feed(kind) as dead:
36                self.assertIsNone(driver_floor.from_feed(dead, "linux-x86_64", seconds=5.0), kind)
37
38    def test_an_explicit_update_check_names_the_host_and_is_the_class_the_quiet_callers_catch(self):
39        for kind in net_dead.KINDS:
40            with net_dead.dead_feed(kind) as dead:
41                with self.assertRaises(feedmod.FeedError) as caught:
42                    feedmod.fetch(dead, {"k": b"0" * 32}, timeout=0.6)
43                self.assertIsInstance(caught.exception, feedmod.FeedUnreachable, kind)
44                self.assertEqual(caught.exception.exit_code, 6)
45                self.assertIn("so the update check could not run", str(caught.exception), kind)
46
47
48if __name__ == "__main__":
49    unittest.main()