Manages two VirtualSerialPort instances for dual-source testing.
| 98 | |
| 99 | |
| 100 | class DualSerialPorts: |
| 101 | """Manages two VirtualSerialPort instances for dual-source testing.""" |
| 102 | |
| 103 | def __init__( |
| 104 | self, |
| 105 | name_a: str = "PortAlpha", |
| 106 | name_b: str = "PortBravo", |
| 107 | ): |
| 108 | self.alpha = VirtualSerialPort(name_a) |
| 109 | self.bravo = VirtualSerialPort(name_b) |
| 110 | |
| 111 | @property |
| 112 | def device_path_a(self) -> str: |
| 113 | return self.alpha.device_path |
| 114 | |
| 115 | @property |
| 116 | def device_path_b(self) -> str: |
| 117 | return self.bravo.device_path |
| 118 | |
| 119 | def open(self) -> None: |
| 120 | """Open both PTY pairs.""" |
| 121 | self.alpha.open() |
| 122 | self.bravo.open() |
| 123 | |
| 124 | def close(self) -> None: |
| 125 | """Close both PTY pairs.""" |
| 126 | self.alpha.close() |
| 127 | self.bravo.close() |
| 128 | |
| 129 | def __enter__(self): |
| 130 | self.open() |
| 131 | return self |
| 132 | |
| 133 | def __exit__(self, *exc): |
| 134 | self.close() |