okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1306424be
main
1"""#4675: a child process that writes non-UTF-8 bytes (a GBK display adapter name) must not kill Step 1. 2 3python -m unittest tools.test_setup_gbk_adapters 4""" 5from __future__import annotations 6 7import sys 8import unittest 9from pathlib import Path 10 11ROOT = Path (__file__ ).resolve ().parents [1 ] 12sys .path .insert (0 ,str (ROOT )) 13import setup # noqa: E402 14 15GBK_LINE = b"Microsoft \xbb\xf9\xb1\xbe\xcf\xd4\xca\xbe\xca\xca\xc5\xe4\xc6\xf7|PCI/VEN_10DE&DEV_0A60&SUBSYS|0\r\n" 16 17 18class GbkOutput (unittest .TestCase ): 19def test_out_survives_bytes_that_are_not_utf8 (self ): 20code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE ,) 21text = setup .out ([sys .executable ,"-X" ,"utf8" ,"-c" ,code ]) 22self .assertIsInstance (text ,str ) 23self .assertIn ("Microsoft" ,text ) 24self .assertIn ("VEN_10DE" ,text ) 25 26def test_adapter_list_never_gets_none (self ): 27from unittest import mock 28with mock .patch .object (setup ,"out" ,return_value = None ): 29self .assertEqual (setup ._win_display_adapters (), []) 30with mock .patch .object (setup ,"out" ,return_value = GBK_LINE .decode ("utf-8" ,"replace" )): 31found = setup ._win_display_adapters () 32self .assertEqual (len (found ),1 ) 33self .assertIn ("VEN_10DE" ,found [0 ]["pnp" ]) 34 35def test_the_tuning_probe_keeps_what_a_child_printed_with_odd_bytes (self ): 36# #4629: the reader thread's UnicodeDecodeError left stdout None 37from strata_control import tune_machine 38code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE ,) 39text = tune_machine ._run ([sys .executable ,"-X" ,"utf8" ,"-c" ,code ]) 40self .assertIsInstance (text ,str ) 41self .assertIn ("VEN_10DE" ,text ) 42 43def test_a_mangled_name_still_matches_its_registry_entry_by_pci_id (self ): 44adapters = [{"name" :"AMD Radeon(TM) Graphics �" ,"pnp" :"PCI/VEN_1002&DEV_744C&SUBSYS" ,"ram" :0 }] 45registry = [{"DriverDesc" :"AMD Radeon RX 7900 XTX" ,"MatchingDeviceId" :"PCI/VEN_1002&DEV_744C" , 46"qwMemorySize" :24 << 30 }] 47g = setup .amd_gpus_windows (adapters ,registry ) 48self .assertEqual (len (g ),1 ) 49 50 51if __name__ == "__main__" : 52unittest .main ()