@@ -134,12 +134,14 @@ def Shutdown(self):
134
134
self .WaitUntilStateShutdown ()
135
135
logging .info ('Shut down simulator %s.' , self .simulator_id )
136
136
137
- def Delete (self ):
138
- """Deletes the simulator asynchronously .
137
+ def Delete (self , asynchronously = True ):
138
+ """Deletes the simulator.
139
139
140
140
The simulator state should be SHUTDOWN when deleting it. Otherwise, it will
141
141
raise exception.
142
142
143
+ Args:
144
+ asynchronously: whether deleting the simulator asynchronously.
143
145
Raises:
144
146
ios_errors.SimError: The simulator's state is not SHUTDOWN.
145
147
"""
@@ -151,11 +153,21 @@ def Delete(self):
151
153
raise ios_errors .SimError (
152
154
'Can only delete the simulator with state SHUTDOWN. The current '
153
155
'state of simulator %s is %s.' % (self ._simulator_id , sim_state ))
154
- logging .info ('Deleting simulator %s asynchronously.' , self .simulator_id )
155
- subprocess .Popen (['xcrun' , 'simctl' , 'delete' , self .simulator_id ],
156
- stdout = subprocess .PIPE ,
157
- stderr = subprocess .PIPE ,
158
- preexec_fn = os .setpgrp )
156
+ command = ['xcrun' , 'simctl' , 'delete' , self .simulator_id ]
157
+ if asynchronously :
158
+ logging .info ('Deleting simulator %s asynchronously.' , self .simulator_id )
159
+ subprocess .Popen (
160
+ command ,
161
+ stdout = subprocess .PIPE ,
162
+ stderr = subprocess .PIPE ,
163
+ preexec_fn = os .setpgrp )
164
+ else :
165
+ try :
166
+ RunSimctlCommand (command )
167
+ logging .info ('Deleted simulator %s.' , self .simulator_id )
168
+ except ios_errors .SimError as e :
169
+ raise ios_errors .SimError ('Failed to delete simulator %s: %s' %
170
+ (self .simulator_id , str (e )))
159
171
# The delete command won't delete the simulator log directory.
160
172
if os .path .exists (self .simulator_log_root_dir ):
161
173
shutil .rmtree (self .simulator_log_root_dir , ignore_errors = True )
@@ -413,9 +425,8 @@ def GetLastSupportedIphoneSimType(os_version):
413
425
os_version_float = float (os_version )
414
426
for sim_type in supported_sim_types :
415
427
if sim_type .startswith ('iPhone' ):
416
- min_os_version_float = float (
417
- simtype_profile .SimTypeProfile (sim_type ).min_os_version )
418
- if os_version_float >= min_os_version_float :
428
+ min_os_version = simtype_profile .SimTypeProfile (sim_type ).min_os_version
429
+ if os_version_float >= min_os_version :
419
430
return sim_type
420
431
raise ios_errors .SimError ('Can not find supported iPhone simulator type.' )
421
432
@@ -520,17 +531,19 @@ def GetLastSupportedSimOsVersion(os_type=ios_constants.OS.IOS,
520
531
if not device_type :
521
532
return supported_os_versions [- 1 ]
522
533
523
- simtype_max_os_version_float = float (
524
- simtype_profile . SimTypeProfile ( device_type ). max_os_version )
534
+ max_os_version = simtype_profile . SimTypeProfile ( device_type ). max_os_version
535
+ # The supported os versions will be from latest to older after reverse().
525
536
supported_os_versions .reverse ()
537
+ if not max_os_version :
538
+ return supported_os_versions [0 ]
539
+
526
540
for os_version in supported_os_versions :
527
- if float (os_version ) <= simtype_max_os_version_float :
541
+ if float (os_version ) <= max_os_version :
528
542
return os_version
529
- if not supported_os_versions :
530
- raise ios_errors .IllegalArgumentError (
531
- 'The supported OS version %s can not match simulator type %s. Because '
532
- 'its max OS version is %s' %
533
- (supported_os_versions , device_type , simtype_max_os_version_float ))
543
+ raise ios_errors .IllegalArgumentError (
544
+ 'The supported OS version %s can not match simulator type %s. Because '
545
+ 'its max OS version is %s' %
546
+ (supported_os_versions , device_type , max_os_version ))
534
547
535
548
536
549
def GetOsType (device_type ):
@@ -598,16 +611,17 @@ def _ValidateSimulatorTypeWithOsVersion(device_type, os_version):
598
611
"""
599
612
os_version_float = float (os_version )
600
613
sim_profile = simtype_profile .SimTypeProfile (device_type )
601
- min_os_version_float = float ( sim_profile .min_os_version )
602
- if min_os_version_float > os_version_float :
614
+ min_os_version = sim_profile .min_os_version
615
+ if min_os_version > os_version_float :
603
616
raise ios_errors .IllegalArgumentError (
604
- 'The min OS version of %s is %s. But current OS version is %s' %
605
- (device_type , min_os_version_float , os_version ))
606
- max_os_version_float = float (sim_profile .max_os_version )
607
- if max_os_version_float < os_version_float :
608
- raise ios_errors .IllegalArgumentError (
609
- 'The max OS version of %s is %s. But current OS version is %s' %
610
- (device_type , max_os_version_float , os_version ))
617
+ 'The min OS version of %s is %f. But current OS version is %s' %
618
+ (device_type , min_os_version , os_version ))
619
+ max_os_version = sim_profile .max_os_version
620
+ if max_os_version :
621
+ if max_os_version < os_version_float :
622
+ raise ios_errors .IllegalArgumentError (
623
+ 'The max OS version of %s is %f. But current OS version is %s' %
624
+ (device_type , max_os_version , os_version ))
611
625
612
626
613
627
def QuitSimulatorApp ():
0 commit comments