<s> from __future__ import division , print_function , unicode_literals <EOL> import os <EOL> assert os . environ [ '<STR_LIT>' ] <EOL> import sys <EOL> sys . path . insert ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> import pyglet <EOL> assert pyglet . mock_level == <NUM_LIT:1> <EOL> from cocos . director import director <EOL> from cocos . cocosnode import CocosNode <EOL> import cocos . actions as ac <EOL> fe = <NUM_LIT> <EOL> director . init ( ) <EOL> def pytest_generate_tests ( metafunc ) : <EOL> param_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> values = [ ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) <EOL> ] <EOL> scenarios = { } <EOL> for v in values : <EOL> name = '<STR_LIT:U+0020>' . join ( [ '<STR_LIT:%s>' % e for e in v ] ) <EOL> scenarios [ name ] = dict ( zip ( param_names , v ) ) <EOL> for k in scenarios : <EOL> metafunc . addcall ( id = k , funcargs = scenarios [ k ] ) <EOL> rec = [ ] <EOL> class UIntervalAction ( ac . IntervalAction ) : <EOL> def init ( self , name , duration ) : <EOL> rec . append ( ( name , '<STR_LIT>' ) ) <EOL> self . duration = duration <EOL> self . name = name <EOL> def start ( self ) : <EOL> rec . append ( ( self . name , '<STR_LIT:start>' ) ) <EOL> def step ( self , dt ) : <EOL> rec . append ( ( self . name , '<STR_LIT>' , dt ) ) <EOL> super ( UIntervalAction , self ) . step ( dt ) <EOL> def update ( self , fraction ) : <EOL> rec . append ( ( self . name , '<STR_LIT>' , fraction ) ) <EOL> def stop ( self ) : <EOL> rec . append ( ( self . name , '<STR_LIT>' ) ) <EOL> class Test_Sequence_IntervalAction : <EOL> def test_instantiation ( self , duration1 , duration2 ) : <EOL> global rec <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> assert isinstance ( a1 , ac . IntervalAction ) <EOL> assert a1 . duration == duration1 <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> rec = [ ] <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> assert isinstance ( composite , ac . IntervalAction ) <EOL> assert composite . duration == ( duration1 + duration2 ) <EOL> assert len ( rec ) == <NUM_LIT:0> <EOL> def test_start ( self , duration1 , duration2 ) : <EOL> global rec <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> rec = [ ] <EOL> node . do ( composite ) <EOL> print ( '<STR_LIT>' , rec ) <EOL> num = <NUM_LIT:0> <EOL> assert rec [ num ] == ( name1 , '<STR_LIT:start>' ) <EOL> if duration1 == <NUM_LIT:0.0> : <EOL> assert rec [ num + <NUM_LIT:1> ] == ( name1 , '<STR_LIT>' , <NUM_LIT:1.0> ) <EOL> assert rec [ num + <NUM_LIT:2> ] == ( name1 , '<STR_LIT>' ) <EOL> assert rec [ num + <NUM_LIT:3> ] == ( name2 , '<STR_LIT:start>' ) <EOL> num = num + <NUM_LIT:3> <EOL> assert len ( rec ) == num + <NUM_LIT:1> <EOL> def test_target_set ( self , duration1 , duration2 ) : <EOL> global rec , next_done <EOL> next_done = <NUM_LIT:0> <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> rec = [ ] <EOL> a_copy = node . do ( composite ) <EOL> assert a_copy . one . target == node <EOL> assert a_copy . two . target == node <EOL> def test_update_below_duration1 ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration1 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> node . do ( composite ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> for next_elapsed in [ duration1 * <NUM_LIT:0.5> , duration1 * <NUM_LIT> ] : <EOL> dt = next_elapsed - elapsed <EOL> rec = [ ] <EOL> node . _step ( dt ) <EOL> rec = [ e for e in rec if e [ <NUM_LIT:1> ] != '<STR_LIT>' ] <EOL> print ( rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' and abs ( rec [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] - next_elapsed / duration1 ) < fe <EOL> assert len ( rec ) == <NUM_LIT:1> <EOL> elapsed = next_elapsed <EOL> def test_update_crossing_duration1_not_duration_at_1st_step ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration2 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> rec = [ ] <EOL> node . do ( composite ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> next_elapsed = ( duration1 + duration2 ) / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> node . _step ( dt ) <EOL> recx = [ e for e in rec if e [ <NUM_LIT:1> ] != '<STR_LIT>' ] <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name1 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT:start>' <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' and rec [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] == <NUM_LIT:1.0> <EOL> assert rec [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert len ( rec ) == <NUM_LIT:3> <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name2 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT:start>' <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert abs ( rec [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] - ( next_elapsed - duration1 ) / duration2 ) < fe <EOL> assert len ( rec ) == <NUM_LIT:2> <EOL> def test_update_crossing_duration1_not_duration_not_at_1st_step ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration1 == <NUM_LIT:0.0> or duration2 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> rec = [ ] <EOL> node . do ( composite ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> next_elapsed = duration1 / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> node . _step ( dt ) <EOL> elapsed = next_elapsed <EOL> next_elapsed = ( duration1 + duration2 ) / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> rec = [ ] <EOL> node . _step ( dt ) <EOL> recx = [ e for e in rec if e [ <NUM_LIT:1> ] != '<STR_LIT>' ] <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name1 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' and rec [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] == <NUM_LIT:1.0> <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert len ( rec ) == <NUM_LIT:2> <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name2 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT:start>' <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert abs ( rec [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] - ( next_elapsed - duration1 ) / duration2 ) < fe <EOL> assert len ( rec ) == <NUM_LIT:2> <EOL> def test_updating_above_duration1_below_duration ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration2 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> node . do ( composite ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> next_elapsed = ( duration1 + duration2 ) / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> node . _step ( dt ) <EOL> elapsed = next_elapsed <EOL> next_elapsed = ( next_elapsed + composite . duration ) / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> rec = [ ] <EOL> node . _step ( dt ) <EOL> assert len ( [ e for e in rec if e [ <NUM_LIT:0> ] == name1 ] ) == <NUM_LIT:0> <EOL> rec = [ e for e in rec if e [ <NUM_LIT:1> ] != '<STR_LIT>' ] <EOL> print ( rec ) <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> assert abs ( rec [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] - ( next_elapsed - duration1 ) / duration2 ) < fe <EOL> assert len ( rec ) == <NUM_LIT:1> <EOL> def test_update_crossing_total_duration_at_1st_step ( self , duration1 , duration2 ) : <EOL> global rec <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> rec = [ ] <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> node . do ( composite ) <EOL> next_elapsed = duration1 + duration2 + fe <EOL> dt = next_elapsed - elapsed <EOL> node . _step ( dt ) <EOL> recx = [ e for e in rec if e [ <NUM_LIT:1> ] != '<STR_LIT>' ] <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name1 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert len ( rec ) == <NUM_LIT:3> <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT:start>' <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' and rec [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] == <NUM_LIT:1.0> <EOL> assert rec [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> rec = [ e for e in recx if e [ <NUM_LIT:0> ] == name2 ] <EOL> print ( '<STR_LIT>' , rec ) <EOL> assert len ( rec ) == <NUM_LIT:3> <EOL> assert rec [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT:start>' <EOL> assert rec [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == '<STR_LIT>' and rec [ <NUM_LIT:1> ] [ <NUM_LIT:2> ] == <NUM_LIT:1.0> <EOL> assert rec [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] == '<STR_LIT>' <EOL> def test_test_receiving_stop_async_before_duration1 ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration1 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> rec = [ ] <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> a_copy = node . do ( composite ) <EOL> rec = [ ] <EOL> a_copy . stop ( ) <EOL> assert rec [ <NUM_LIT:0> ] == ( name1 , '<STR_LIT>' ) <EOL> assert len ( rec ) == <NUM_LIT:1> <EOL> def test_test_receiving_stop_async_after_duration1_before_duration2 ( self , duration1 , duration2 ) : <EOL> global rec <EOL> if duration2 == <NUM_LIT:0.0> : <EOL> return <EOL> node = CocosNode ( ) <EOL> name1 = '<STR_LIT:1>' <EOL> name2 = '<STR_LIT:2>' <EOL> a1 = UIntervalAction ( name1 , duration1 ) <EOL> a2 = UIntervalAction ( name2 , duration2 ) <EOL> elapsed = <NUM_LIT:0.0> <EOL> rec = [ ] <EOL> composite = ac . sequence ( a1 , a2 ) <EOL> a_copy = node . do ( composite ) <EOL> next_elapsed = ( duration1 + duration2 ) / <NUM_LIT> <EOL> dt = next_elapsed - elapsed <EOL> node . _step ( dt ) <EOL> rec = [ ] <EOL> a_copy . stop ( ) <EOL> assert rec [ <NUM_LIT:0> ] == ( name2 , '<STR_LIT>' ) <EOL> assert len ( rec ) == <NUM_LIT:1> </s>
