Coverage for src/engines/pexpect.py: 100.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-22 10:53 +0000

1#!/usr/bin/env python3 

2 

3# Coverage 

4# pragma: linux cover file 

5 

6# Modules libraries 

7from pexpect import EOF, spawn, TIMEOUT # pylint: disable=import-error 

8 

9# Components 

10from .base import Base 

11 

12# Pexpect class 

13class Pexpect(Base): 

14 

15 # Constructor 

16 def __init__(self, command: str) -> None: # pylint: disable=super-init-not-called 

17 

18 # Spawn command 

19 self._child = spawn('sh', ['-c', command]) 

20 

21 # Read 

22 def _read(self) -> bytes | str: 

23 

24 # Acquire output, pylint: disable=duplicate-code 

25 assert self._child is not None 

26 try: 

27 result = self._child.read_nonblocking(size=1024, timeout=1) 

28 assert isinstance(result, (bytes, str)) 

29 return result 

30 except (AttributeError, EOF, TIMEOUT): 

31 pass 

32 

33 # Empty output 

34 return ''