4
4
import os
5
5
import subprocess
6
6
from ishtp import (
7
- get_release_version ,
8
- is_module_loaded ,
7
+ get_module_list ,
9
8
check_modules ,
10
9
check_devices ,
11
10
)
12
11
13
12
14
13
class TestISHTP (unittest .TestCase ):
15
14
16
- @patch ("subprocess.check_output" , return_value = "24.04\n " )
17
- def test_get_release_version (self , mock_subproc ):
18
- self .assertEqual (get_release_version (), 24 )
19
-
20
- @patch ("subprocess.check_output" , return_value = "somethingwrong\n " )
21
- def test_get_release_version_value_error (self , mock_subproc ):
22
- with self .assertRaises (SystemExit ) as cm :
23
- get_release_version ()
24
- self .assertEqual (cm .exception .code , 1 )
25
-
26
- @patch ("subprocess.check_output" , return_value = "intel_ishtp 123 0\n " )
27
- def test_is_module_loaded (self , mock_subproc ):
28
- self .assertTrue (is_module_loaded ("intel_ishtp" ))
29
-
30
- @patch ("subprocess.check_output" , return_value = "" )
31
- def test_is_module_not_loaded (self , mock_subproc ):
32
- self .assertFalse (is_module_loaded ("intel_ishtp" ))
33
-
34
15
@patch (
35
- "subprocess.check_output" ,
36
- side_effect = subprocess .CalledProcessError (1 , "lsmod" ),
16
+ "subprocess.check_output" , return_value = "module1\n nodule2\n module3\n "
37
17
)
38
- def test_is_module_loaded_error (self , mock_subproc ):
39
- self .assertFalse ( is_module_loaded ( "intel_ishtp" ) )
18
+ def test_get_module_list (self , mock_subproc ):
19
+ self .assertEqual ( get_module_list (), [ "module1" , "nodule2" , "module3" ] )
40
20
41
21
@patch ("os.path.isdir" , return_value = True )
42
22
@patch ("os.listdir" , return_value = ["device1" , "device2" ])
@@ -45,22 +25,61 @@ def test_check_devices_success(self, mock_listdir, mock_isdir):
45
25
46
26
@patch ("os.path.isdir" , return_value = False )
47
27
def test_check_devices_no_directory (self , mock_isdir ):
48
- self .assertEqual ( check_devices (), 1 )
28
+ self .assertRaises ( SystemExit )
49
29
50
30
@patch ("os.path.isdir" , return_value = True )
51
31
@patch ("os.listdir" , return_value = [])
52
32
def test_check_devices_empty_directory (self , mock_listdir , mock_isdir ):
53
- self .assertEqual ( check_devices (), 1 )
33
+ self .assertRaises ( SystemExit )
54
34
55
- @patch ("ishtp.is_module_loaded" , return_value = True )
56
- @patch ("ishtp.get_release_version" , return_value = 24 )
57
- def test_check_modules_success (self , mock_release , mock_module ):
35
+ @patch (
36
+ "ishtp.get_module_list" ,
37
+ return_value = ["intel_ishtp_hid" , "intel_ish_ipc" , "intel_ishtp" ],
38
+ )
39
+ @patch (
40
+ "checkbox_support.helpers.release_info.get_release_info" ,
41
+ return_value = "24.04" ,
42
+ )
43
+ def test_check_modules_success_24 (self , mock_release , mock_module ):
58
44
self .assertEqual (check_modules (), 0 )
59
45
60
- @patch ("ishtp.is_module_loaded" , return_value = False )
61
- @patch ("ishtp.get_release_version" , return_value = 24 )
62
- def test_check_modules_fail (self , mock_release , mock_module ):
63
- self .assertEqual (check_modules (), 1 )
46
+ @patch (
47
+ "ishtp.get_module_list" ,
48
+ return_value = ["intel_ishtp_hid" , "intel_ish_ipc" ],
49
+ )
50
+ @patch (
51
+ "checkbox_support.helpers.release_info.get_release_info" ,
52
+ return_value = "24.04" ,
53
+ )
54
+ def test_check_modules_fail_24 (self , mock_release , mock_module ):
55
+ self .assertRaises (SystemExit )
56
+
57
+ @patch (
58
+ "ishtp.get_module_list" ,
59
+ return_value = [
60
+ "intel_ishtp_loader" ,
61
+ "intel_ishtp_hid" ,
62
+ "intel_ish_ipc" ,
63
+ "intel_ishtp" ,
64
+ ],
65
+ )
66
+ @patch (
67
+ "checkbox_support.helpers.release_info.get_release_info" ,
68
+ return_value = "22.04" ,
69
+ )
70
+ def test_check_modules_success_22 (self , mock_release , mock_module ):
71
+ self .assertEqual (check_modules (), 0 )
72
+
73
+ @patch (
74
+ "ishtp.get_module_list" ,
75
+ return_value = ["intel_ishtp_hid" , "intel_ish_ipc" ],
76
+ )
77
+ @patch (
78
+ "checkbox_support.helpers.release_info.get_release_info" ,
79
+ return_value = "22.04" ,
80
+ )
81
+ def test_check_modules_fail_22 (self , mock_release , mock_module ):
82
+ self .assertRaises (SystemExit )
64
83
65
84
66
85
if __name__ == "__main__" :
0 commit comments