Coverage for tests/test_helpers.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-24 11:53 -0300

1# test_helpers.py 

2 

3from typing import NamedTuple 

4from typing import Type 

5from typing import Union 

6 

7import pytest 

8from pyselector import helpers 

9from pyselector.interfaces import ExecutableNotFoundError 

10 

11 

12class Case(NamedTuple): 

13 input: Union[str, bytes] 

14 expected: Union[str, int, Type[ExecutableNotFoundError]] 

15 

16 

17def test_check_command_success() -> None: 

18 case = Case(input="cat", expected="/bin/cat") 

19 command = helpers.check_command( 

20 name=case.input, 

21 reference="...", 

22 ) 

23 assert command == case.expected 

24 

25 

26def test_check_command_failure() -> None: 

27 case = Case(input="i_dont_exists", expected=ExecutableNotFoundError) 

28 with pytest.raises(case.expected): 

29 helpers.check_command(name=case.input, reference=case.input) 

30 

31 

32@pytest.mark.parametrize( 

33 "input", 

34 ( 

35 b"Testing line", 

36 b"Another line", 

37 ), 

38) 

39def test_parse_single_bytes_line(input) -> None: 

40 line = helpers.parse_bytes_line(input) 

41 assert isinstance(input, bytes) 

42 assert isinstance(line, str) 

43 

44 

45@pytest.mark.parametrize( 

46 ("input", "expected"), 

47 ( 

48 Case(input=b"Testing", expected=1), 

49 Case(input=b"Testing\nLines\nAnother", expected=3), 

50 Case(input=b"Testing\nFour\nLines\nAnother", expected=4), 

51 ), 

52) 

53def test_parse_mutitple_bytes_lines(input, expected) -> None: 

54 lines = helpers.parse_multiple_bytes_lines(input) 

55 assert isinstance(lines, list) 

56 assert len(lines) == expected