<s> from __future__ import print_function , unicode_literals <EOL> import datetime <EOL> import unittest <EOL> import weblab . core . coordinator . status as WSS <EOL> class FakeScheduler ( object ) : <EOL> def __init__ ( self , reservation_status , expected_reservation_id ) : <EOL> self . reservation_status = reservation_status <EOL> self . expected_reservation_id = expected_reservation_id <EOL> def is_remote ( self ) : <EOL> return False <EOL> def get_reservation_status ( self , reservation_id ) : <EOL> if reservation_id != self . expected_reservation_id : <EOL> raise ValueError ( "<STR_LIT>" % ( self . expected_reservation_id , reservation_id ) ) <EOL> return self . reservation_status <EOL> class MetaSchedulerTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . wi_five = WSS . WaitingInstancesQueueStatus ( "<STR_LIT>" , <NUM_LIT:5> ) <EOL> self . wi_four = WSS . WaitingInstancesQueueStatus ( "<STR_LIT>" , <NUM_LIT:4> ) <EOL> self . w_five = WSS . WaitingQueueStatus ( "<STR_LIT>" , <NUM_LIT:5> ) <EOL> self . w_four = WSS . WaitingQueueStatus ( "<STR_LIT>" , <NUM_LIT:4> ) <EOL> self . wc1 = WSS . WaitingConfirmationQueueStatus ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . wc2 = WSS . WaitingConfirmationQueueStatus ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . res1 = WSS . LocalReservedStatus ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , { } , <NUM_LIT:50> , None , datetime . datetime . now ( ) , datetime . datetime . now ( ) , True , <NUM_LIT:50> , '<STR_LIT>' ) <EOL> self . res2 = WSS . LocalReservedStatus ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , { } , <NUM_LIT> , "<STR_LIT:foo>" , datetime . datetime . now ( ) , datetime . datetime . now ( ) , True , <NUM_LIT:50> , '<STR_LIT>' ) <EOL> self . post1 = WSS . PostReservationStatus ( "<STR_LIT>" , True , "<STR_LIT>" , "<STR_LIT:bar>" ) <EOL> self . post2 = WSS . PostReservationStatus ( "<STR_LIT>" , True , "<STR_LIT>" , "<STR_LIT:bar>" ) <EOL> def test_query_best_reservation__waiting_instances_equals ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . wi_four , ( self . wi_four , self . wi_five ) ) <EOL> self . _test_schedulers ( self . wi_four , ( self . wi_five , self . wi_four ) ) <EOL> def test_query_best_reservation__waiting_equals ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . w_four , ( self . w_four , self . w_five ) ) <EOL> self . _test_schedulers ( self . w_four , ( self . w_five , self . w_four ) ) <EOL> def test_query_best_reservation__waiting_confirmation_equals ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( ( self . wc1 , self . wc2 ) , ( self . wc1 , self . wc2 ) ) <EOL> self . _test_schedulers ( ( self . wc1 , self . wc2 ) , ( self . wc2 , self . wc1 ) ) <EOL> def test_query_best_reservation__reserved_equals ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( ( self . res1 , self . res2 ) , ( self . res1 , self . res2 ) ) <EOL> self . _test_schedulers ( ( self . res1 , self . res2 ) , ( self . res2 , self . res1 ) ) <EOL> def test_query_best_reservation__post_reservation_equals ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( ( self . post1 , self . post2 ) , ( self . post1 , self . post2 ) ) <EOL> self . _test_schedulers ( ( self . post1 , self . post2 ) , ( self . post2 , self . post1 ) ) <EOL> def test_query_best_reservation__waiting_wins ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . w_four , ( self . w_four , self . wi_four , self . wi_four ) ) <EOL> self . _test_schedulers ( self . w_four , ( self . wi_four , self . w_four , self . wi_five ) ) <EOL> self . _test_schedulers ( self . w_four , ( self . wi_four , self . wi_five , self . w_four ) ) <EOL> def test_query_best_reservation__waiting_confirmation_wins ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . wc1 , ( self . wc1 , self . w_four , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . wc1 , ( self . w_four , self . wc1 , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . wc1 , ( self . w_four , self . wi_four , self . wc1 , self . post1 ) ) <EOL> def test_query_best_reservation__reserved_wins ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . res1 , ( self . res1 , self . wc1 , self . w_four , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . res1 , ( self . wc1 , self . res1 , self . w_four , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . res1 , ( self . wc1 , self . w_four , self . res1 , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . res1 , ( self . wc1 , self . w_four , self . wi_four , self . res1 , self . post1 ) ) <EOL> def test_query_best_reservation__post_reservation_wins ( self ) : <EOL> "<STR_LIT>" <EOL> self . _test_schedulers ( self . post1 , ( self . post1 , self . w_four , self . wi_four ) ) <EOL> self . _test_schedulers ( self . post1 , ( self . post1 , self . w_four , self . wi_four ) ) <EOL> self . _test_schedulers ( self . post1 , ( self . w_four , self . post1 , self . wi_four ) ) <EOL> self . _test_schedulers ( self . post1 , ( self . w_four , self . wi_four , self . post1 ) ) <EOL> self . _test_schedulers ( self . post1 , ( self . w_four , self . wi_four , self . post1 ) ) <EOL> def _test_schedulers ( self , best , all_status ) : <EOL> best_reservation_status = sorted ( all_status ) [ <NUM_LIT:0> ] <EOL> try : <EOL> best [ <NUM_LIT:0> ] <EOL> except TypeError : <EOL> self . assertEquals ( best , best_reservation_status ) <EOL> else : <EOL> self . assertTrue ( best_reservation_status in best ) <EOL> def suite ( ) : <EOL> return unittest . makeSuite ( MetaSchedulerTestCase ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
