@@ -134,12 +134,14 @@ def Shutdown(self):
134134 self .WaitUntilStateShutdown ()
135135 logging .info ('Shut down simulator %s.' , self .simulator_id )
136136
137- def Delete (self ):
138- """Deletes the simulator asynchronously .
137+ def Delete (self , asynchronously = True ):
138+ """Deletes the simulator.
139139
140140 The simulator state should be SHUTDOWN when deleting it. Otherwise, it will
141141 raise exception.
142142
143+ Args:
144+ asynchronously: whether deleting the simulator asynchronously.
143145 Raises:
144146 ios_errors.SimError: The simulator's state is not SHUTDOWN.
145147 """
@@ -151,11 +153,21 @@ def Delete(self):
151153 raise ios_errors .SimError (
152154 'Can only delete the simulator with state SHUTDOWN. The current '
153155 '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 )))
159171 # The delete command won't delete the simulator log directory.
160172 if os .path .exists (self .simulator_log_root_dir ):
161173 shutil .rmtree (self .simulator_log_root_dir , ignore_errors = True )
@@ -413,9 +425,8 @@ def GetLastSupportedIphoneSimType(os_version):
413425 os_version_float = float (os_version )
414426 for sim_type in supported_sim_types :
415427 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 :
419430 return sim_type
420431 raise ios_errors .SimError ('Can not find supported iPhone simulator type.' )
421432
@@ -520,17 +531,19 @@ def GetLastSupportedSimOsVersion(os_type=ios_constants.OS.IOS,
520531 if not device_type :
521532 return supported_os_versions [- 1 ]
522533
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().
525536 supported_os_versions .reverse ()
537+ if not max_os_version :
538+ return supported_os_versions [0 ]
539+
526540 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 :
528542 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 ))
534547
535548
536549def GetOsType (device_type ):
@@ -598,16 +611,17 @@ def _ValidateSimulatorTypeWithOsVersion(device_type, os_version):
598611 """
599612 os_version_float = float (os_version )
600613 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 :
603616 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 ))
611625
612626
613627def QuitSimulatorApp ():
0 commit comments