<s> from graphserver . core import * <EOL> import unittest <EOL> import pickle <EOL> class TestServiceCalendar ( unittest . TestCase ) : <EOL> def test_basic ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> assert ( c . head == None ) <EOL> assert ( c . period_of_or_before ( <NUM_LIT:0> ) == None ) <EOL> assert ( c . period_of_or_after ( <NUM_LIT:0> ) == None ) <EOL> def test_get_service_id_int ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> assert c . get_service_id_int ( "<STR_LIT:A>" ) == <NUM_LIT:0> <EOL> assert c . get_service_id_int ( "<STR_LIT:A>" ) == <NUM_LIT:0> <EOL> assert c . get_service_id_int ( "<STR_LIT:B>" ) == <NUM_LIT:1> <EOL> try : <EOL> c . get_service_id_int ( <NUM_LIT:1> ) <EOL> assert False <EOL> except TypeError : <EOL> pass <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:1000> , [ "<STR_LIT:B>" ] ) <EOL> import pickle <EOL> from cStringIO import StringIO <EOL> src = StringIO ( ) <EOL> p = pickle . Pickler ( src ) <EOL> p . dump ( c ) <EOL> datastream = src . getvalue ( ) <EOL> dst = StringIO ( datastream ) <EOL> upc = pickle . Unpickler ( dst ) . load ( ) <EOL> print c . expound ( "<STR_LIT>" ) <EOL> print upc . expound ( "<STR_LIT>" ) <EOL> assert c . expound ( "<STR_LIT>" ) == upc . expound ( "<STR_LIT>" ) , upc <EOL> for _c in [ c , upc ] : <EOL> assert _c . get_service_id_string ( - <NUM_LIT:1> ) == None <EOL> assert _c . get_service_id_string ( <NUM_LIT:0> ) == "<STR_LIT:A>" , _c . to_xml ( ) <EOL> assert _c . get_service_id_string ( <NUM_LIT:1> ) == "<STR_LIT:B>" <EOL> assert _c . get_service_id_string ( <NUM_LIT:2> ) == None <EOL> try : <EOL> _c . get_service_id_string ( "<STR_LIT:A>" ) <EOL> assert False <EOL> except TypeError : <EOL> pass <EOL> def test_single ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:1000> , [ "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT:C>" ] ) <EOL> assert c . head <EOL> assert c . head . begin_time == <NUM_LIT:0> <EOL> assert c . head . end_time == <NUM_LIT:1000> <EOL> assert c . head . service_ids == [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert c . period_of_or_before ( - <NUM_LIT:1> ) == None <EOL> assert c . period_of_or_before ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT:1000> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( - <NUM_LIT:1> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( <NUM_LIT> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( <NUM_LIT:1000> ) == None <EOL> assert c . period_of_or_after ( <NUM_LIT> ) == None <EOL> def test_overlap_a_little ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:1000> , [ "<STR_LIT:A>" ] ) <EOL> c . add_period ( <NUM_LIT:1000> , <NUM_LIT> , [ "<STR_LIT:B>" ] ) <EOL> assert c . head . begin_time == <NUM_LIT:0> <EOL> assert c . head . end_time == <NUM_LIT:1000> <EOL> assert c . period_of_or_before ( - <NUM_LIT:1> ) == None <EOL> assert c . period_of_or_before ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT:1000> ) . begin_time == <NUM_LIT:1000> <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:1000> , <NUM_LIT> , [ "<STR_LIT:B>" ] ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:1000> , [ "<STR_LIT:A>" ] ) <EOL> assert c . head . begin_time == <NUM_LIT:0> <EOL> assert c . head . end_time == <NUM_LIT:1000> <EOL> assert c . period_of_or_before ( - <NUM_LIT:1> ) == None <EOL> assert c . period_of_or_before ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT:1000> ) . begin_time == <NUM_LIT:1000> <EOL> sc = ServiceCalendar ( ) <EOL> sc . add_period ( <NUM_LIT:0> , <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> , [ '<STR_LIT:A>' ] ) <EOL> sc . add_period ( <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> , <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> , [ '<STR_LIT:B>' ] ) <EOL> assert sc . period_of_or_after ( <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> ) . begin_time == <NUM_LIT> <EOL> def test_multiple ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT> , <NUM_LIT> , [ "<STR_LIT:C>" , "<STR_LIT:D>" , "<STR_LIT:E>" ] ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:1000> , [ "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT:C>" ] ) <EOL> assert c . head <EOL> assert c . head . begin_time == <NUM_LIT:0> <EOL> assert c . head . end_time == <NUM_LIT:1000> <EOL> assert c . head . service_ids == [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:0> ] <EOL> assert c . head . previous == None <EOL> assert c . head . next . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_before ( - <NUM_LIT:1> ) == None <EOL> assert c . period_of_or_before ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT:1000> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_before ( <NUM_LIT> ) . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_after ( - <NUM_LIT:1> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( <NUM_LIT:0> ) . begin_time == <NUM_LIT:0> <EOL> assert c . period_of_or_after ( <NUM_LIT:1000> ) . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_after ( <NUM_LIT> ) . begin_time == <NUM_LIT> <EOL> assert c . period_of_or_after ( <NUM_LIT> ) == None <EOL> assert c . period_of_or_after ( <NUM_LIT> ) == None <EOL> def test_add_three ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:10> , [ "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT:C>" ] ) <EOL> c . add_period ( <NUM_LIT:16> , <NUM_LIT:20> , [ "<STR_LIT:C>" , "<STR_LIT:D>" , "<STR_LIT:E>" ] ) <EOL> c . add_period ( <NUM_LIT:11> , <NUM_LIT:15> , [ "<STR_LIT:E>" , "<STR_LIT:F>" , "<STR_LIT>" ] ) <EOL> assert c . head . next . next . begin_time == <NUM_LIT:16> <EOL> def test_periods ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:10> , [ "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT:C>" ] ) <EOL> c . add_period ( <NUM_LIT:16> , <NUM_LIT:20> , [ "<STR_LIT:E>" , "<STR_LIT:F>" , "<STR_LIT>" ] ) <EOL> c . add_period ( <NUM_LIT:11> , <NUM_LIT:15> , [ "<STR_LIT:C>" , "<STR_LIT:D>" , "<STR_LIT:E>" ] ) <EOL> assert [ x . begin_time for x in c . periods ] == [ <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:16> ] <EOL> def test_to_xml ( self ) : <EOL> c = ServiceCalendar ( ) <EOL> c . add_period ( <NUM_LIT:0> , <NUM_LIT:10> , [ "<STR_LIT:A>" , "<STR_LIT:B>" , "<STR_LIT:C>" ] ) <EOL> c . add_period ( <NUM_LIT:16> , <NUM_LIT:20> , [ "<STR_LIT:D>" , "<STR_LIT:E>" , "<STR_LIT:F>" ] ) <EOL> c . add_period ( <NUM_LIT:11> , <NUM_LIT:15> , [ "<STR_LIT:C>" , "<STR_LIT:D>" , "<STR_LIT:E>" ] ) <EOL> assert c . to_xml ( ) == "<STR_LIT>" <EOL> def test_pickle ( self ) : <EOL> cc = ServiceCalendar ( ) <EOL> cc . add_period ( <NUM_LIT:0> , <NUM_LIT:100> , [ "<STR_LIT:A>" , "<STR_LIT:B>" ] ) <EOL> cc . add_period ( <NUM_LIT> , <NUM_LIT:200> , [ "<STR_LIT:C>" , "<STR_LIT:D>" ] ) <EOL> cc . add_period ( <NUM_LIT> , <NUM_LIT> , [ "<STR_LIT:E>" , "<STR_LIT:F>" ] ) <EOL> ss = pickle . dumps ( cc ) <EOL> laz = pickle . loads ( ss ) <EOL> assert cc . __getstate__ ( ) == laz . __getstate__ ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tl = unittest . TestLoader ( ) <EOL> suite = tl . loadTestsFromTestCase ( TestServiceCalendar ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
