<s> """<STR_LIT>""" <EOL> import imp <EOL> import os <EOL> import shutil <EOL> from retriever . lib . compile import compile_script <EOL> from retriever import HOME_DIR , ENGINE_LIST <EOL> simple_csv = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> crosstab = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> tests = [ simple_csv , crosstab ] <EOL> def setup_module ( ) : <EOL> """<STR_LIT>""" <EOL> for test in tests : <EOL> if not os . path . exists ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] ) ) : <EOL> os . makedirs ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] ) ) <EOL> with open ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] , test [ '<STR_LIT:name>' ] + '<STR_LIT>' ) , '<STR_LIT:w>' ) as data_file : <EOL> data_file . write ( test [ '<STR_LIT>' ] ) <EOL> with open ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] + '<STR_LIT>' ) , '<STR_LIT:w>' ) as script_file : <EOL> script_file . write ( test [ '<STR_LIT>' ] ) <EOL> compile_script ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] ) ) <EOL> def teardown_module ( ) : <EOL> """<STR_LIT>""" <EOL> for test in tests : <EOL> shutil . rmtree ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] ) ) <EOL> os . remove ( os . path . join ( HOME_DIR , "<STR_LIT>" , test [ '<STR_LIT:name>' ] + '<STR_LIT>' ) ) <EOL> def get_script_module ( script_name ) : <EOL> """<STR_LIT>""" <EOL> file , pathname , desc = imp . find_module ( script_name , [ os . path . join ( HOME_DIR , "<STR_LIT>" ) ] ) <EOL> return imp . load_module ( script_name , file , pathname , desc ) <EOL> mysql_engine , postgres_engine , sqlite_engine , msaccess_engine , csv_engine , download_engine , json_engine , xml_engine = ENGINE_LIST ( ) <EOL> csv_engine . opts = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def test_csv_from_csv ( ) : <EOL> simple_csv_module = get_script_module ( '<STR_LIT>' ) <EOL> simple_csv_module . SCRIPT . download ( csv_engine ) <EOL> simple_csv_module . SCRIPT . engine . disconnect ( ) <EOL> with open ( "<STR_LIT>" , '<STR_LIT:r>' ) as obs_out_file : <EOL> obs_out = obs_out_file . read ( ) <EOL> print len ( obs_out ) <EOL> assert obs_out == simple_csv [ '<STR_LIT>' ] <EOL> def test_crosstab_from_csv ( ) : <EOL> crosstab_module = get_script_module ( '<STR_LIT>' ) <EOL> crosstab_module . SCRIPT . download ( csv_engine ) <EOL> crosstab_module . SCRIPT . engine . disconnect ( ) <EOL> with open ( "<STR_LIT>" , '<STR_LIT:r>' ) as obs_out_file : <EOL> obs_out = obs_out_file . read ( ) <EOL> print len ( obs_out ) <EOL> assert obs_out == crosstab [ '<STR_LIT>' ] </s>
