11import logging
22import json
33from pathlib import Path
4- from enum import StrEnum
4+ from enum import Enum , StrEnum , auto
55from typing import List , NamedTuple , TypeVar , Type , Dict , Any , Set , Tuple
66
77# Top level configuration keys
@@ -237,13 +237,6 @@ def from_file(cls: Type[T], config_file: str) -> T:
237237 proposals = [],
238238 )
239239
240- def args_env_dirs (self ) -> Tuple [List [str ], Dict [str , str ], List [Tuple [Path , str ]]]:
241- for op in self .operations :
242- match op :
243- case Run (args , env , dirs ):
244- return (args , env , dirs )
245- return ([], {}, [])
246-
247240 def proposals_as_str (self ) -> List [str ]:
248241 return [p .value for p in self .proposals ]
249242
@@ -381,45 +374,57 @@ def run(self) -> Result:
381374 return self .as_result ()
382375
383376
377+ class StreamType (Enum ):
378+ READABLE_PIPE = auto ()
379+ WRITABLE_PIPE = auto ()
380+ SOCKET = auto ()
381+
382+
384383class TestCaseValidator (TestCaseRunnerBase ):
385384 _config_path : str
386385 _has_proc : bool
387- _streams : Set [str ]
386+ _streams : Dict [str , StreamType ]
388387
389388 def __init__ (self , config : Config , config_path : str ) -> None :
390389 TestCaseRunnerBase .__init__ (self , config )
391390 self ._config_path = config_path
392391 self ._has_proc = False
393- self ._streams = set ()
392+ self ._streams = {}
394393
395394 def assert_proc (self , op : Any ) -> None :
396- assert self ._has_proc , f"{ op } : no process running"
395+ assert self ._has_proc , \
396+ f"{ self ._config_path } : { op } : no process running"
397397
398398 def assert_no_proc (self , op : Any ) -> None :
399- assert not self ._has_proc , f"{ op } : process still running"
399+ assert not self ._has_proc , \
400+ f"{ self ._config_path } : { op } : process still running"
400401
401- def assert_stream (self , op : Any , name : str ) -> None :
402- assert name in self ._streams , f"{ op } : no such stream: { name } "
402+ def assert_stream (self , op : Any , name : str , typ : StreamType ) -> None :
403+ assert name in self ._streams , \
404+ f"{ self ._config_path } : { op } : no such stream: { name } "
405+ t = self ._streams [name ]
406+ assert t == typ , \
407+ f"{ self ._config_path } : { op } : expected { typ } , but got { t } : { name } "
403408
404- def assert_no_stream (self , op : Any , name : str ) -> None :
405- assert name not in self ._streams , f"{ op } : stream exists: { name } "
409+ def add_stream (self , op : Any , name : str , typ : StreamType ) -> None :
410+ assert name not in self ._streams , \
411+ f"{ self ._config_path } : { op } : stream exists: { name } "
412+ self ._streams [name ] = typ
406413
407414 def do_run (self , run : Run ) -> None :
408415 self .assert_no_proc (run )
416+ self .add_stream (run , "stdin" , StreamType .WRITABLE_PIPE )
417+ self .add_stream (run , "stdout" , StreamType .READABLE_PIPE )
418+ self .add_stream (run , "stderr" , StreamType .READABLE_PIPE )
409419 self ._has_proc = True
410420
411421 def do_write (self , write : Write ) -> None :
412422 self .assert_proc (write )
413- match write .id :
414- case "stdin" : pass
415- case name : self .assert_stream (write , name )
423+ self .assert_stream (write , write .id , StreamType .WRITABLE_PIPE )
416424
417425 def do_read (self , read : Read ) -> None :
418426 self .assert_proc (read )
419- match read .id :
420- case "stdout" : pass
421- case "stderr" : pass
422- case name : self .assert_stream (read , name )
427+ self .assert_stream (read , read .id , StreamType .READABLE_PIPE )
423428
424429 def do_wait (self , wait : Wait ) -> None :
425430 self .assert_proc (wait )
@@ -428,18 +433,17 @@ def do_wait(self, wait: Wait) -> None:
428433
429434 def do_connect (self , conn : Connect ) -> None :
430435 self .assert_proc (conn )
431- self .assert_no_stream (conn , conn .id )
432436 assert conn .protocol_type == ProtocolType .TCP , \
433- f"{ conn } : { conn .protocol_type } not supported"
434- self ._streams . add (conn .id )
437+ f"{ self . _config_path } : { conn } : { conn .protocol_type } not supported"
438+ self .add_stream (conn , conn .id , StreamType . SOCKET )
435439
436440 def do_send (self , send : Send ) -> None :
437441 self .assert_proc (send )
438- self .assert_stream (send , send .id )
442+ self .assert_stream (send , send .id , StreamType . SOCKET )
439443
440444 def do_recv (self , recv : Recv ) -> None :
441445 self .assert_proc (recv )
442- self .assert_stream (recv , recv .id )
446+ self .assert_stream (recv , recv .id , StreamType . SOCKET )
443447
444448 def do_cleanup (self , successful : bool ) -> None :
445449 if successful :
0 commit comments