okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2fb096b93
main
1import subprocess 2import sys 3import tempfile 4import unittest 5from pathlib import Path 6 7sys .path .insert (0 ,str (Path (__file__ ).resolve ().parent )) 8import check_lookup_window_serve as C 9 10FAKE = r'''import sys 11mode = sys.argv[-1] 12print("READY 4096 stop", flush=True) 13for line in sys.stdin: 14if line.startswith("GEN"): 15print("T 5", flush=True) 16if mode == "refuse": 17print("ERR metal window: window size out of range", flush=True) 18break 19print("DONE 1 78 1.0 1.0 length 3 6 0 0 0 0 0 0.0 78 0", flush=True) 20elif line.startswith("QUIT"): 21break 22''' 23 24 25class LookupWindowGate (unittest .TestCase ): 26def run_fake (self ,mode ,** kw ): 27with tempfile .TemporaryDirectory ()as d : 28f = Path (d )/ "fake.py" 29f .write_text (FAKE ) 30real = subprocess .Popen 31try :# the gate starts [exe, --serve, *args]; the fake is run as python fake.py --serve <mode> 32subprocess .Popen = lambda cmd ,** k :real ([cmd [0 ],str (f ),* cmd [1 :],mode ],** k ) 33return C .check (sys .executable , [], [1 ,2 ,3 ],start_timeout = 20 ,request_timeout = 20 ,** kw ) 34finally : 35subprocess .Popen = real 36 37def test_pass_and_drafts (self ): 38ok ,lines = self .run_fake ("ok" ,need_drafts = True ) 39self .assertTrue (ok ,lines ) 40self .assertEqual (len (lines ),2 ) 41 42def test_refused_window_fails_the_gate (self ): 43ok ,lines = self .run_fake ("refuse" ) 44self .assertFalse (ok ) 45self .assertIn ("window size out of range" ,lines [0 ]) 46 47 48if __name__ == "__main__" : 49unittest .main ()