<s> from rb . promise import Promise <EOL> def test_resolved_promise ( ) : <EOL> p = Promise . resolved ( <NUM_LIT> ) <EOL> assert p . is_resolved <EOL> assert not p . is_pending <EOL> assert not p . is_rejected <EOL> assert p . value == <NUM_LIT> <EOL> def test_rejected_promise ( ) : <EOL> err = RuntimeError ( '<STR_LIT>' ) <EOL> p = Promise . rejected ( err ) <EOL> assert not p . is_resolved <EOL> assert not p . is_pending <EOL> assert p . is_rejected <EOL> assert p . reason == err <EOL> def test_success_callbacks ( ) : <EOL> results = [ ] <EOL> p = Promise ( ) <EOL> assert p . is_pending <EOL> p . done ( results . append ) <EOL> assert results == [ ] <EOL> p . resolve ( <NUM_LIT> ) <EOL> assert results == [ <NUM_LIT> ] <EOL> p = Promise . resolved ( <NUM_LIT> ) <EOL> p . done ( results . append ) <EOL> assert results == [ <NUM_LIT> , <NUM_LIT> ] <EOL> def test_failure_callbacks ( ) : <EOL> results = [ ] <EOL> p = Promise ( ) <EOL> assert p . is_pending <EOL> p . done ( on_failure = results . append ) <EOL> assert results == [ ] <EOL> p . reject ( <NUM_LIT> ) <EOL> assert results == [ <NUM_LIT> ] <EOL> p = Promise . rejected ( <NUM_LIT> ) <EOL> p . done ( on_failure = results . append ) <EOL> assert results == [ <NUM_LIT> , <NUM_LIT> ] <EOL> def test_promise_then ( ) : <EOL> p = Promise . resolved ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def on_success ( value ) : <EOL> return value + [ <NUM_LIT:4> ] <EOL> p2 = p . then ( success = on_success ) <EOL> assert p2 . value == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> def test_promise_all ( ) : <EOL> p = Promise . all ( [ ] ) <EOL> assert p . is_resolved <EOL> assert p . value == [ ] <EOL> p = Promise . all ( { } ) <EOL> assert p . is_resolved <EOL> assert p . value == { } <EOL> p = Promise . all ( [ <EOL> Promise . resolved ( <NUM_LIT:1> ) , <EOL> Promise . resolved ( <NUM_LIT:2> ) , <EOL> Promise . resolved ( <NUM_LIT:3> ) , <EOL> ] ) <EOL> assert p . is_resolved <EOL> assert p . value == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> p = Promise . all ( { <EOL> '<STR_LIT>' : Promise . resolved ( <NUM_LIT:1> ) , <EOL> '<STR_LIT>' : Promise . resolved ( <NUM_LIT:2> ) , <EOL> '<STR_LIT>' : Promise . resolved ( <NUM_LIT:3> ) , <EOL> } ) <EOL> assert p . is_resolved <EOL> assert p . value == { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } <EOL> p = Promise . all ( [ <EOL> Promise . resolved ( <NUM_LIT:1> ) , <EOL> Promise . rejected ( <NUM_LIT:2> ) , <EOL> Promise . resolved ( <NUM_LIT:3> ) , <EOL> ] ) <EOL> assert p . is_rejected <EOL> assert p . reason == <NUM_LIT:2> <EOL> def test_auto_coercion ( ) : <EOL> p = Promise . all ( [ <NUM_LIT:1> , <NUM_LIT:2> , Promise . resolved ( <NUM_LIT:3> ) ] ) <EOL> assert p . is_resolved <EOL> assert p . value == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> p = Promise . all ( { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> , <NUM_LIT:3> : Promise . resolved ( <NUM_LIT:3> ) } ) <EOL> assert p . is_resolved <EOL> assert p . value == { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> , <NUM_LIT:3> : <NUM_LIT:3> } </s>
