<s> import io <EOL> from nose . tools import eq_ , raises <EOL> from . . map import map <EOL> SAMPLE_XML = """<STR_LIT>""" <EOL> def test_map ( ) : <EOL> f = io . StringIO ( SAMPLE_XML ) <EOL> def process_dump ( dump , path ) : <EOL> for page in dump : <EOL> count = <NUM_LIT:0> <EOL> for rev in page : <EOL> count += <NUM_LIT:1> <EOL> yield { '<STR_LIT>' : page . id , '<STR_LIT>' : count } <EOL> pages = <NUM_LIT:0> <EOL> for doc in map ( [ f ] , process_dump ) : <EOL> page_id = doc [ '<STR_LIT>' ] <EOL> revisions = doc [ '<STR_LIT>' ] <EOL> if page_id == <NUM_LIT:1> : <EOL> eq_ ( revisions , <NUM_LIT:2> ) <EOL> elif page_id == <NUM_LIT:2> : <EOL> eq_ ( revisions , <NUM_LIT:1> ) <EOL> else : <EOL> assert False <EOL> pages += <NUM_LIT:1> <EOL> eq_ ( pages , <NUM_LIT:2> ) <EOL> def test_dict_yield ( ) : <EOL> def test_map ( ) : <EOL> f = io . StringIO ( SAMPLE_XML ) <EOL> def process_dump ( dump , path ) : <EOL> for page in dump : <EOL> count = <NUM_LIT:0> <EOL> for rev in page : <EOL> count += <NUM_LIT:1> <EOL> yield { '<STR_LIT>' : page . id , '<STR_LIT>' : count } <EOL> pages = <NUM_LIT:0> <EOL> for doc in map ( [ f ] , process_dump ) : <EOL> page_id = doc [ '<STR_LIT>' ] <EOL> revisions = doc [ '<STR_LIT>' ] <EOL> if page_id == <NUM_LIT:1> : <EOL> eq_ ( revisions , <NUM_LIT:2> ) <EOL> elif page_id == <NUM_LIT:2> : <EOL> eq_ ( revisions , <NUM_LIT:1> ) <EOL> else : <EOL> assert False <EOL> pages += <NUM_LIT:1> <EOL> eq_ ( pages , <NUM_LIT:2> ) <EOL> @ raises ( TypeError ) <EOL> def test_map_error ( ) : <EOL> f = io . StringIO ( SAMPLE_XML ) <EOL> def process_dump ( dump , path ) : <EOL> for page in dump : <EOL> if page . id == <NUM_LIT:2> : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> pages = <NUM_LIT:0> <EOL> for doc in map ( [ f ] , process_dump ) : <EOL> page_id = doc [ '<STR_LIT>' ] <EOL> def test_map_error_handler ( ) : <EOL> f = io . StringIO ( SAMPLE_XML ) <EOL> def process_dump ( dump , path , handle_error = lambda exp , stack : None ) : <EOL> for page in dump : <EOL> count = <NUM_LIT:0> <EOL> for rev in page : <EOL> count += <NUM_LIT:1> <EOL> if count > <NUM_LIT:2> : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> yield { '<STR_LIT>' : page . id , '<STR_LIT>' : count } <EOL> pages = <NUM_LIT:0> <EOL> for doc in map ( [ f ] , process_dump ) : <EOL> page_id = doc [ '<STR_LIT>' ] <EOL> revisions = doc [ '<STR_LIT>' ] <EOL> if page_id == <NUM_LIT:1> : <EOL> eq_ ( revisions , <NUM_LIT:2> ) <EOL> elif page_id == <NUM_LIT:2> : <EOL> eq_ ( revisions , <NUM_LIT:1> ) <EOL> else : <EOL> assert False <EOL> pages += <NUM_LIT:1> <EOL> eq_ ( pages , <NUM_LIT:2> ) </s>
