okami.mom/strata

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

Niko1221Trial2 merge f-0291-pr-nv (97b3d614f)1306424be

main
2.1 KiB52 linesraw
1"""#4675: a child process that writes non-UTF-8 bytes (a GBK display adapter name) must not kill Step 1.
2
3    python -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):
19    def test_out_survives_bytes_that_are_not_utf8(self):
20        code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE,)
21        text = setup.out([sys.executable, "-X", "utf8", "-c", code])
22        self.assertIsInstance(text, str)
23        self.assertIn("Microsoft", text)
24        self.assertIn("VEN_10DE", text)
25
26    def test_adapter_list_never_gets_none(self):
27        from unittest import mock
28        with mock.patch.object(setup, "out", return_value=None):
29            self.assertEqual(setup._win_display_adapters(), [])
30        with mock.patch.object(setup, "out", return_value=GBK_LINE.decode("utf-8", "replace")):
31            found = setup._win_display_adapters()
32        self.assertEqual(len(found), 1)
33        self.assertIn("VEN_10DE", found[0]["pnp"])
34
35    def test_the_tuning_probe_keeps_what_a_child_printed_with_odd_bytes(self):
36        # #4629: the reader thread's UnicodeDecodeError left stdout None
37        from strata_control import tune_machine
38        code = "import sys; sys.stdout.buffer.write(%r)" % (GBK_LINE,)
39        text = tune_machine._run([sys.executable, "-X", "utf8", "-c", code])
40        self.assertIsInstance(text, str)
41        self.assertIn("VEN_10DE", text)
42
43    def test_a_mangled_name_still_matches_its_registry_entry_by_pci_id(self):
44        adapters = [{"name": "AMD Radeon(TM) Graphics �", "pnp": "PCI/VEN_1002&DEV_744C&SUBSYS", "ram": 0}]
45        registry = [{"DriverDesc": "AMD Radeon RX 7900 XTX", "MatchingDeviceId": "PCI/VEN_1002&DEV_744C",
46                     "qwMemorySize": 24 << 30}]
47        g = setup.amd_gpus_windows(adapters, registry)
48        self.assertEqual(len(g), 1)
49
50
51if __name__ == "__main__":
52    unittest.main()