@@ -248,66 +248,12 @@ async def telnet_client() -> str:
248248 assert server .returncode == 0
249249
250250
251- def run_frontend_ssh_server (rom_path_str : str , input_file_str : str ) -> None :
252- import argparse
253- from concurrent .futures import ThreadPoolExecutor
254- import gambaterm .ssh as gambaterm_ssh
255- from gambaterm .console import GameboyColor
256- from gambaterm .main import AppConfig
257- from gambaterm .remote_terminal import RemoteTerminal , KeyboardSupportDetection
258-
259- rom = Path (rom_path_str )
260-
261- def test_frontend (
262- terminal : RemoteTerminal ,
263- app_config : AppConfig ,
264- keyboard_support_detection : KeyboardSupportDetection ,
265- ) -> AppConfig :
266- terminal .stream .write ("TEST_FRONTEND_ACTIVE\n " )
267- terminal .stream .flush ()
268- return app_config
269-
270- namespace = argparse .Namespace (
271- romfile = rom ,
272- input_file = Path (input_file_str ),
273- skip_inputs = 188 ,
274- color_mode = None ,
275- frame_advance = 1 ,
276- break_after = 10 ,
277- speed = 1.0 ,
278- cpr_sync = False ,
279- save_directory = None ,
280- force_gameboy = False ,
281- )
282-
283- async def main () -> None :
284- with ThreadPoolExecutor (max_workers = 4 ) as executor :
285- async with gambaterm_ssh .run_ssh_server (
286- bind = "127.0.0.1" ,
287- port = 8022 ,
288- authentication = gambaterm_ssh .NoAuthentication (),
289- console_cls = GameboyColor ,
290- namespace = namespace ,
291- command_parser = lambda cmd , ns , write : ns ,
292- users_directory = Path ("." ),
293- executor = executor ,
294- frontend = test_frontend ,
295- ):
296- await asyncio .Future ()
297-
298- try :
299- asyncio .run (main ())
300- except KeyboardInterrupt :
301- pass
302-
303-
304251def test_gambaterm_ssh_frontend (ssh_config : Path , gambaterm_config : Path ) -> None :
305252 assert TEST_ROM .exists ()
306253
307254 command = [
308255 sys .executable ,
309- "-c" ,
310- "import sys; from tests.test_gambaterm import run_frontend_ssh_server; run_frontend_ssh_server(sys.argv[1], sys.argv[2])" ,
256+ str (Path (__file__ ).parent / "_frontend_ssh_server.py" ),
311257 str (TEST_ROM ),
312258 "/dev/null" ,
313259 ]
@@ -336,12 +282,13 @@ async def ssh_client() -> str:
336282 known_hosts = None ,
337283 username = "user" ,
338284 ) as conn :
339- async with conn .create_process (
340- term_type = "xterm-256color" , term_size = (80 , 24 )
341- ) as proc :
342- stdout : str
343- stdout , _ = await asyncio .wait_for (proc .communicate (), timeout = 10.0 )
344- return stdout
285+ result = await conn .run (
286+ "" ,
287+ term_type = "xterm-256color" ,
288+ term_size = (80 , 24 ),
289+ )
290+ assert isinstance (result .stdout , str )
291+ return result .stdout
345292
346293 client_stdout = asyncio .run (ssh_client ())
347294 assert "TEST_FRONTEND_ACTIVE" in client_stdout
@@ -358,67 +305,12 @@ async def ssh_client() -> str:
358305 assert server .returncode == 0
359306
360307
361- def run_frontend_telnet_server (rom_path_str : str , input_file_str : str ) -> None :
362- import argparse
363- from concurrent .futures import ThreadPoolExecutor
364- import gambaterm .telnet as gambaterm_telnet
365- from gambaterm .console import GameboyColor
366- from gambaterm .main import AppConfig
367- from gambaterm .remote_terminal import RemoteTerminal , KeyboardSupportDetection
368-
369- rom = Path (rom_path_str )
370-
371- def test_frontend (
372- terminal : RemoteTerminal ,
373- app_config : AppConfig ,
374- keyboard_support_detection : KeyboardSupportDetection ,
375- ) -> AppConfig :
376- terminal .stream .write ("TEST_FRONTEND_ACTIVE\n " )
377- terminal .stream .flush ()
378- return app_config
379-
380- namespace = argparse .Namespace (
381- romfile = rom ,
382- input_file = Path (input_file_str ),
383- skip_inputs = 188 ,
384- color_mode = None ,
385- frame_advance = 1 ,
386- break_after = 10 ,
387- speed = 1.0 ,
388- cpr_sync = False ,
389- save_directory = None ,
390- force_gameboy = False ,
391- )
392-
393- async def main () -> None :
394- with ThreadPoolExecutor (max_workers = 4 ) as executor :
395- async with gambaterm_telnet .run_telnet_server (
396- bind = "127.0.0.1" ,
397- port = 8023 ,
398- robot_check = False ,
399- max_players = 0 ,
400- idle_timeout = None ,
401- console_cls = GameboyColor ,
402- namespace = namespace ,
403- users_directory = Path ("." ),
404- executor = executor ,
405- frontend = test_frontend ,
406- ):
407- await asyncio .Future ()
408-
409- try :
410- asyncio .run (main ())
411- except KeyboardInterrupt :
412- pass
413-
414-
415308def test_gambaterm_telnet_frontend (gambaterm_config : Path ) -> None :
416309 assert TEST_ROM .exists ()
417310
418311 command = [
419312 sys .executable ,
420- "-c" ,
421- "import sys; from tests.test_gambaterm import run_frontend_telnet_server; run_frontend_telnet_server(sys.argv[1], sys.argv[2])" ,
313+ str (Path (__file__ ).parent / "_frontend_telnet_server.py" ),
422314 str (TEST_ROM ),
423315 "/dev/null" ,
424316 ]
0 commit comments