forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iossim_util_test.py
214 lines (193 loc) · 8.27 KB
/
iossim_util_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for iossim_util.py."""
import mock
import unittest
import iossim_util
import test_runner
import test_runner_test
SIMULATORS_LIST = {
'devices': {
'com.apple.CoreSimulator.SimRuntime.iOS-11-4': [{
'isAvailable':
True,
'name':
'iPhone 5s 11.4 test simulator',
'deviceTypeIdentifier':
'com.apple.CoreSimulator.SimDeviceType.iPhone-5s',
'state':
'Shutdown',
'udid':
'E4E66320-177A-450A-9BA1-488D85B7278E'
}],
'com.apple.CoreSimulator.SimRuntime.iOS-13-2': [{
'isAvailable':
True,
'name':
'iPhone X 13.2.2 test simulator',
'deviceTypeIdentifier':
'com.apple.CoreSimulator.SimDeviceType.iPhone-X',
'state':
'Shutdown',
'udid':
'E4E66321-177A-450A-9BA1-488D85B7278E'
}, {
'isAvailable':
True,
'name':
'iPhone 11 13.2.2 test simulator',
'deviceTypeIdentifier':
'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
'state':
'Shutdown',
'udid':
'A4E66321-177A-450A-9BA1-488D85B7278E'
}]
},
'devicetypes': [
{
'name': 'iPhone 5s',
'bundlePath': '/path/iPhone 4s/Content',
'identifier': 'com.apple.CoreSimulator.SimDeviceType.iPhone-5s'
},
{
'name': 'iPhone X',
'bundlePath': '/path/iPhone X/Content',
'identifier': 'com.apple.CoreSimulator.SimDeviceType.iPhone-X'
},
{
'name': 'iPhone 11',
'bundlePath': '/path/iPhone 11/Content',
'identifier': 'com.apple.CoreSimulator.SimDeviceType.iPhone-11'
},
],
'pairs': [],
'runtimes': [
{
"buildversion": "15F79",
"bundlePath": "/path/Runtimes/iOS 11.4.simruntime",
"identifier": "com.apple.CoreSimulator.SimRuntime.iOS-11-4",
"isAvailable": True,
"name": "iOS 11.4",
"version": "11.4"
},
{
"buildversion": "17A844",
"bundlePath": "/path/Runtimes/iOS 13.1.simruntime",
"identifier": "com.apple.CoreSimulator.SimRuntime.iOS-13-1",
"isAvailable": True,
"name": "iOS 13.1",
"version": "13.1"
},
{
"buildversion": "17B102",
"bundlePath": "/path/Runtimes/iOS.simruntime",
"identifier": "com.apple.CoreSimulator.SimRuntime.iOS-13-2",
"isAvailable": True,
"name": "iOS 13.2",
"version": "13.2.2"
},
]
}
@mock.patch.object(
iossim_util, 'get_simulator_list', return_value=SIMULATORS_LIST)
class GetiOSSimUtil(test_runner_test.TestCase):
"""Tests for iossim_util.py."""
def setUp(self):
super(GetiOSSimUtil, self).setUp()
def test_get_simulator_runtime_by_version(self, _):
"""Ensures correctness of filter."""
self.assertEqual(
'com.apple.CoreSimulator.SimRuntime.iOS-13-2',
iossim_util.get_simulator_runtime_by_version(
iossim_util.get_simulator_list(), '13.2.2'))
def test_get_simulator_runtime_by_version_not_found(self, _):
"""Ensures that SimulatorNotFoundError raises if no runtime."""
with self.assertRaises(test_runner.SimulatorNotFoundError) as context:
iossim_util.get_simulator_runtime_by_version(
iossim_util.get_simulator_list(), '13.2')
expected_message = ('Simulator does not exist: Not found '
'"13.2" SDK in runtimes')
self.assertTrue(expected_message in str(context.exception))
def test_get_simulator_device_type_by_platform(self, _):
"""Ensures correctness of filter."""
self.assertEqual(
'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
iossim_util.get_simulator_device_type_by_platform(
iossim_util.get_simulator_list(), 'iPhone 11'))
def test_get_simulator_device_type_by_platform_not_found(self, _):
"""Ensures that SimulatorNotFoundError raises if no platform."""
with self.assertRaises(test_runner.SimulatorNotFoundError) as context:
iossim_util.get_simulator_device_type_by_platform(
iossim_util.get_simulator_list(), 'iPhone XI')
expected_message = ('Simulator does not exist: Not found device '
'"iPhone XI" in devicetypes')
self.assertTrue(expected_message in str(context.exception))
def test_get_simulator_runtime_by_device_udid(self, _):
"""Ensures correctness of filter."""
self.assertEqual(
'com.apple.CoreSimulator.SimRuntime.iOS-13-2',
iossim_util.get_simulator_runtime_by_device_udid(
'E4E66321-177A-450A-9BA1-488D85B7278E'))
def test_get_simulator_runtime_by_device_udid_not_found(self, _):
"""Ensures that SimulatorNotFoundError raises if no device with UDID."""
with self.assertRaises(test_runner.SimulatorNotFoundError) as context:
iossim_util.get_simulator_runtime_by_device_udid('non_existing_UDID')
expected_message = ('Simulator does not exist: Not found simulator with '
'"non_existing_UDID" UDID in devices')
self.assertTrue(expected_message in str(context.exception))
def test_get_simulator_udids_by_platform_and_version(self, _):
"""Ensures correctness of filter."""
self.assertEqual(['A4E66321-177A-450A-9BA1-488D85B7278E'],
iossim_util.get_simulator_udids_by_platform_and_version(
'iPhone 11', '13.2.2'))
def test_get_simulator_udids_by_platform_and_version_not_found(self, _):
"""Ensures that filter returns empty list if no device with version."""
self.assertEqual([],
iossim_util.get_simulator_udids_by_platform_and_version(
'iPhone 11', '13.1'))
@mock.patch('subprocess.check_output', autospec=True)
def test_create_device_by_platform_and_version(self, subprocess_mock, _):
"""Ensures that command is correct."""
subprocess_mock.return_value = 'NEW_UDID'
self.assertEqual(
'NEW_UDID',
iossim_util.create_device_by_platform_and_version(
'iPhone 11', '13.2.2'))
self.assertEqual([
'xcrun', 'simctl', 'create', 'iPhone 11 13.2.2 test simulator',
'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
'com.apple.CoreSimulator.SimRuntime.iOS-13-2'
], subprocess_mock.call_args[0][0])
@mock.patch('subprocess.check_output', autospec=True)
def test_delete_simulator_by_udid(self, subprocess_mock, _):
"""Ensures that command is correct."""
iossim_util.delete_simulator_by_udid('UDID')
self.assertEqual(['xcrun', 'simctl', 'delete', 'UDID'],
subprocess_mock.call_args[0][0])
@mock.patch('subprocess.check_call', autospec=True)
def test_wipe_simulator_by_platform_and_version(self, subprocess_mock, _):
"""Ensures that command is correct."""
iossim_util.wipe_simulator_by_udid('A4E66321-177A-450A-9BA1-488D85B7278E')
self.assertEqual(
['xcrun', 'simctl', 'erase', 'A4E66321-177A-450A-9BA1-488D85B7278E'],
subprocess_mock.call_args[0][0])
@mock.patch('subprocess.check_output', autospec=True)
def test_get_home_directory(self, subprocess_mock, _):
"""Ensures that command is correct."""
subprocess_mock.return_value = 'HOME_DIRECTORY'
self.assertEqual('HOME_DIRECTORY',
iossim_util.get_home_directory('iPhone 11', '13.2.2'))
self.assertEqual([
'xcrun', 'simctl', 'getenv', 'A4E66321-177A-450A-9BA1-488D85B7278E',
'HOME'
], subprocess_mock.call_args[0][0])
@mock.patch.object(iossim_util, 'create_device_by_platform_and_version')
def test_no_new_sim_created_when_one_exists(self, mock_create, _):
"""Ensures no simulator is created when one in desired dimension exists."""
self.assertEqual('A4E66321-177A-450A-9BA1-488D85B7278E',
iossim_util.get_simulator('iPhone 11', '13.2.2'))
self.assertFalse(mock_create.called)
if __name__ == '__main__':
unittest.main()