16
16
"""
17
17
18
18
import unittest
19
+ from mock import patch
19
20
from tools .detect_targets import get_interface_version
20
- from tools .test_api import get_autodetected_MUTS_list
21
+
22
+
23
+ class MbedLsToolsMock ():
24
+
25
+ def __init__ (self , type ):
26
+ self .interface_test_type = type
27
+
28
+ def get_details_txt (self , mount_point ):
29
+ return self .details_txt_types [self .interface_test_type ];
30
+
31
+ # Static details.txt types.
32
+ details_txt_types = {
33
+ 'details_valid_interface_version' : {
34
+ 'Unique ID' : '0226000029164e45002f0012706e0006f301000097969900' ,
35
+ 'HIF ID' : '97969900' ,
36
+ 'Auto Reset' : '0' ,
37
+ 'Automation allowed' : '0' ,
38
+ 'Daplink Mode' : 'Interface' ,
39
+ 'Interface Version' : '0240' ,
40
+ 'Git SHA' : 'c765cbb590f57598756683254ca38b211693ae5e' ,
41
+ 'Local Mods' : '0' ,
42
+ 'USB Interfaces' : 'MSD, CDC, HID' ,
43
+ 'Interface CRC' : '0x26764ebf'
44
+ },
45
+ 'details_valid_version' : {
46
+ 'Version' : '0226' ,
47
+ 'Build' : 'Aug 24 2015 17:06:30' ,
48
+ 'Git Commit SHA' : '27a236b9fe39c674a703c5c89655fbd26b8e27e1' ,
49
+ 'Git Local mods' : 'Yes'
50
+ },
51
+ 'details_missing_interface_version' : {
52
+ 'Unique ID' : '0226000033514e450044500585d4001de981000097969900' ,
53
+ 'HIC ID' : '97969900' ,
54
+ 'Auto Reset' : '0' ,
55
+ 'Automation allowed' : '0' ,
56
+ 'Overflow detection' : '0' ,
57
+ 'Daplink Mode' : 'Interface' ,
58
+ 'Git SHA' : 'b403a07e3696cee1e116d44cbdd64446e056ce38' ,
59
+ 'Local Mods' : '0' ,
60
+ 'USB Interfaces' : 'MSD, CDC, HID' ,
61
+ 'Interface CRC' : '0x4d98bf7e' ,
62
+ 'Remount count' : '0'
63
+ },
64
+ 'details_invalid_none' : None
65
+ }
21
66
22
67
"""
23
68
Tests for detect_targets.py
24
69
"""
25
70
26
- class DetectTargetsTests (unittest .TestCase ):
71
+ class DetectTargetsTest (unittest .TestCase ):
27
72
"""
28
73
Test cases for Detect Target functionality
29
74
"""
@@ -33,26 +78,9 @@ def setUp(self):
33
78
Called before each test case
34
79
35
80
:return:
36
- """
37
- # Gather a valid mount point from the host machine
38
- muts = get_autodetected_MUTS_list ()
39
-
40
- count = 0
41
-
42
- for mut in muts .values ():
43
-
44
- count += 1
45
- self .valid_mount_point = mut ['disk' ]
46
- break
47
-
48
- # If no targets are found, there is no way to determine Host OS mount point.
49
- # Function should handle failure gracefully regardless of a mount point being present.
50
- # Therefore it is safe to assume a valid mount point.
51
- if count is 0 :
52
- self .valid_mount_point = "D:"
53
-
54
- self .invalid_mount_point = "23z/e\n "
81
+ """
55
82
self .missing_mount_point = None
83
+ self .mount_point = "D:"
56
84
57
85
def tearDown (self ):
58
86
"""
@@ -62,22 +90,67 @@ def tearDown(self):
62
90
:return:
63
91
"""
64
92
pass
93
+
94
+ @patch ("mbed_lstools.create" , return_value = MbedLsToolsMock ('details_valid_interface_version' ))
95
+ def test_interface_version_valid (self , mbed_lstools_mock ):
96
+ """
97
+ Test that checks function returns correctly when given a valid Interface Version
98
+
99
+ :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
100
+ :return
101
+ """
65
102
66
- def test_interface_version_valid_mount_point (self ):
103
+ interface_version = get_interface_version (self .mount_point )
104
+ assert interface_version == '0240'
67
105
68
- interface_version = get_interface_version (self .valid_mount_point )
69
- assert len (interface_version ) > 0
106
+ @patch ("mbed_lstools.create" , return_value = MbedLsToolsMock ('details_valid_version' ))
107
+ def test_version_valid (self , mbed_lstools_mock ):
108
+ """
109
+ Test that checks function returns correctly when given a valid Version
110
+
111
+ :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
112
+ :return
113
+ """
70
114
71
- def test_interface_version_invalid_mount_point (self ):
115
+ interface_version = get_interface_version (self .mount_point )
116
+ assert interface_version == '0226'
72
117
73
- interface_version = get_interface_version (self .invalid_mount_point )
118
+ @patch ("mbed_lstools.create" , return_value = MbedLsToolsMock ('details_missing_interface_version' ))
119
+ def test_interface_version_missing_interface_version (self , mbed_lstools_mock ):
120
+ """
121
+ Test that checks function returns correctly when DETAILS.txt is present
122
+ but an interface version is not listed.
123
+
124
+ :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
125
+ :return
126
+ """
127
+
128
+ interface_version = get_interface_version (self .mount_point )
74
129
assert interface_version == 'unknown'
75
130
76
- def test_interface_version_missing_mount_point (self ):
131
+ @patch ("mbed_lstools.create" , return_value = MbedLsToolsMock ('details_invalid_none' ))
132
+ def test_version_none (self , mbed_lstools_mock ):
133
+ """
134
+ Test that checks function returns correctly when a valid mount point is supplied
135
+ but DETAILS.txt is not present.
136
+
137
+ :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
138
+ :return
139
+ """
140
+
141
+ interface_version = get_interface_version (self .mount_point )
142
+ assert interface_version == 'unknown'
143
+
144
+ @patch ("mbed_lstools.create" , return_value = MbedLsToolsMock ('details_invalid_none' ))
145
+ def test_interface_version_missing_mount_point (self , mbed_lstools_mock ):
146
+ """
147
+ Test that checks function returns correctly when no moint point is supplied.
77
148
149
+ :param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
150
+ :return
151
+ """
78
152
interface_version = get_interface_version (self .missing_mount_point )
79
153
assert interface_version == 'unknown'
80
154
81
-
82
155
if __name__ == '__main__' :
83
156
unittest .main ()
0 commit comments