<s> import sys <EOL> import os <EOL> sys . path . append ( os . path . abspath ( "<STR_LIT:..>" ) ) <EOL> import MDB . DBbuilder as DBbuilder <EOL> import wx <EOL> import shutil <EOL> import MDB . wx_signal as wx_signal <EOL> from MDB . gui import MyFrame <EOL> from MDB . gui import check_and_setup <EOL> from MDB . DBbuilder import images_folder <EOL> movies1 = [ ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> True ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' + <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> True ) , <EOL> ] <EOL> movies2 = [ ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) ] <EOL> movie_filenames = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def setup_db_dir ( ) : <EOL> try : shutil . rmtree ( '<STR_LIT:test>' ) <EOL> except : pass <EOL> os . mkdir ( '<STR_LIT:test>' ) <EOL> home_var = '<STR_LIT>' <EOL> if ( home_var not in os . environ ) : <EOL> home_var = '<STR_LIT>' <EOL> home_old = os . environ [ home_var ] <EOL> os . environ [ home_var ] = os . path . abspath ( '<STR_LIT>' ) <EOL> conn , cur , mdb_dir = check_and_setup ( ) <EOL> os . environ [ home_var ] = home_old <EOL> return conn , cur , mdb_dir <EOL> def test_name_parser ( ) : <EOL> for filename , moviename , _ in movies1 : <EOL> assert ( DBbuilder . get_movie_name ( filename ) == moviename ) <EOL> def test_get_imdb_data_correctness ( ) : <EOL> for moviename , data in movies2 : <EOL> res = DBbuilder . get_imdb_data ( moviename ) <EOL> assert ( ( res [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] ) == data ) <EOL> def test_get_imdb_data_existence ( ) : <EOL> for filename , moviename , _ in movies1 : <EOL> res = DBbuilder . get_imdb_data ( moviename ) <EOL> assert ( res is not None ) <EOL> print "<STR_LIT>" <EOL> print filename , '<STR_LIT>' , res [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] , res [ '<STR_LIT>' ] <EOL> def test_dbbuilder_images ( ) : <EOL> conn , cur , mdb_dir = setup_db_dir ( ) <EOL> dbthread = DBbuilder . DBbuilderThread ( None , [ item [ <NUM_LIT:0> ] for item in movies1 ] , <EOL> mdb_dir ) <EOL> dbthread . start ( ) <EOL> dbthread . join ( ) <EOL> for item in movies1 : <EOL> if item [ <NUM_LIT:2> ] : <EOL> assert ( os . path . exists ( os . path . join ( mdb_dir , images_folder , <EOL> item [ <NUM_LIT:0> ] + '<STR_LIT>' ) ) ) <EOL> else : <EOL> assert ( True ) <EOL> class CountingFrame ( wx . Frame ) : <EOL> def __init__ ( self , parent , total ) : <EOL> wx . Frame . __init__ ( self , parent , title = "<STR_LIT>" , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . Bind ( wx_signal . EVT_FILE_DONE , self . on_file_done ) <EOL> self . total = total <EOL> def on_file_done ( self , evt ) : <EOL> print "<STR_LIT>" + evt . filename <EOL> self . total -= <NUM_LIT:1> <EOL> assert True <EOL> if self . total == <NUM_LIT:0> : <EOL> self . Destroy ( ) <EOL> def test_DBbuilder_signal ( ) : <EOL> conn , cur , mdb_dir = setup_db_dir ( ) <EOL> app = wx . App ( False ) <EOL> frame = CountingFrame ( None , total = len ( movies1 ) ) <EOL> dbthread = DBbuilder . DBbuilderThread ( frame , [ item [ <NUM_LIT:0> ] for item in movies1 ] , <EOL> mdb_dir ) <EOL> dbthread . start ( ) <EOL> app . MainLoop ( ) <EOL> def test_gui_row_addition ( ) : <EOL> conn , cur , mdb_dir = setup_db_dir ( ) <EOL> app = wx . App ( ) <EOL> frame = MyFrame ( None , conn , cur , mdb_dir ) <EOL> app . SetTopWindow ( frame ) <EOL> frame . Maximize ( ) <EOL> frame . Show ( ) <EOL> dbthread = DBbuilder . DBbuilderThread ( frame , [ item [ <NUM_LIT:0> ] for item in movies1 ] , <EOL> mdb_dir ) <EOL> dbthread . start ( ) <EOL> app . MainLoop ( ) </s>
