Coverage for tests/unit_tests/commands/test_apio_drivers.py: 60%

45 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 05:08 +0000

1# This file is part of the Apio project 

2# (C) 2016-present FPGAwars 

3# Project authors: 

4# * Jesús Arroyo (Jesus89) (2016-2019) 

5# * Juan Gonzalez (obijuan) (2019-2024) 

6# * The Apio Team (2024-present) 

7# License: GPLv2 

8 

9"""Test for the "apio drivers" command.""" 

10 

11import pytest 

12from tests.conftest import ApioRunner 

13from apio.common import apio_platforms 

14from apio.commands.apio import apio_top_cli as apio 

15 

16# TODO: add a test for ubuntu 

17# TODO: add a (dummy) test for windows 

18 

19 

20def test_drivers_darwin_only(apio_runner: ApioRunner): 

21 """Tests the 'apio drivers' commands on darwin platform.""" 

22 # -- Skip this test if not running on a darwin platform 

23 if not apio_platforms.get_apio_platform().is_darwin: 23 ↛ 26line 23 didn't jump to line 26 because the condition on line 23 was always true

24 pytest.skip("Darwin only") 

25 

26 with apio_runner.in_sandbox() as sb: 

27 

28 # -- Run 'apio drivers install ftdi' 

29 result = sb.invoke_apio_cmd(apio, ["drivers", "install", "ftdi"]) 

30 sb.assert_result_ok(result) 

31 assert ( 

32 "No driver installation is required on this platform" 

33 in result.output 

34 ) 

35 

36 # -- Run 'apio drivers uninstall ftdi' 

37 result = sb.invoke_apio_cmd(apio, ["drivers", "uninstall", "ftdi"]) 

38 sb.assert_result_ok(result) 

39 assert ( 

40 "No driver installation is required on this platform" 

41 in result.output 

42 ) 

43 

44 # -- Run 'apio drivers install serial' 

45 result = sb.invoke_apio_cmd(apio, ["drivers", "install", "serial"]) 

46 sb.assert_result_ok(result) 

47 assert ( 

48 "No driver installation is required on this platform" 

49 in result.output 

50 ) 

51 

52 # -- Run 'apio drivers uninstall serial' 

53 result = sb.invoke_apio_cmd(apio, ["drivers", "uninstall", "serial"]) 

54 sb.assert_result_ok(result) 

55 assert ( 

56 "No driver installation is required on this platform" 

57 in result.output 

58 ) 

59 

60 

61def test_drivers_github_linux_only(apio_runner: ApioRunner): 

62 """Tests the 'apio drivers' commands on linux platform.""" 

63 

64 # -- Skip this test if not running on a linux platform 

65 if not apio_platforms.get_apio_platform().is_linux: 65 ↛ 66line 65 didn't jump to line 66 because the condition on line 65 was never true

66 pytest.skip("Linux only") 

67 

68 # -- Skip this test if not running on a github workflow. We need 

69 # -- the github password-less sudo for this test to succeed. 

70 if not apio_runner.is_on_github_workflow(): 70 ↛ 71line 70 didn't jump to line 71 because the condition on line 70 was never true

71 pytest.skip("Github workflow only test") 

72 

73 with apio_runner.in_sandbox() as sb: 

74 

75 # -- Run 'apio drivers install ftdi' 

76 result = sb.invoke_apio_cmd(apio, ["drivers", "install", "ftdi"]) 

77 sb.assert_result_ok(result) 

78 print(result.output) 

79 assert "FTDI drivers installed" in result.output 

80 

81 # -- Run 'apio drivers uninstall ftdi' 

82 result = sb.invoke_apio_cmd(apio, ["drivers", "uninstall", "ftdi"]) 

83 sb.assert_result_ok(result) 

84 print(result.output) 

85 assert "FTDI drivers uninstalled" in result.output 

86 

87 # -- Run 'apio drivers install serial' 

88 result = sb.invoke_apio_cmd(apio, ["drivers", "install", "serial"]) 

89 sb.assert_result_ok(result) 

90 assert "Serial drivers installed" in result.output 

91 

92 # -- Run 'apio drivers uninstall serial' 

93 result = sb.invoke_apio_cmd(apio, ["drivers", "uninstall", "serial"]) 

94 sb.assert_result_ok(result) 

95 assert "Serial drivers uninstalled" in result.output 

96 

97 

98def test_drivers_windows_only(apio_runner: ApioRunner): 

99 """Tests the 'apio drivers' commands on a windows platform.""" 

100 

101 # -- Skip this test if not running on a windows platform 

102 if not apio_platforms.get_apio_platform().is_windows: 102 ↛ 105line 102 didn't jump to line 105 because the condition on line 102 was always true

103 pytest.skip("Windows only") 

104 

105 with apio_runner.in_sandbox(): 

106 

107 # TODO: Find a creative way to test 'something' here. Maybe using 

108 # a 'dry-run' option that will skip dispatching zadig and the 

109 # serial installer and will just print the instructions to the 

110 # user. 

111 pass