<s> '''<STR_LIT>''' <EOL> import unittest <EOL> import tempfile <EOL> import os <EOL> import shutil <EOL> import errno <EOL> import time <EOL> import yaml <EOL> from cola . core . utils import import_job_desc <EOL> from cola . core . zip import ZipHandler <EOL> from cola . context import Context <EOL> class Test ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . working_dir = tempfile . mkdtemp ( ) <EOL> self . job_dir = os . path . join ( self . working_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . zip_dir = os . path . join ( self . working_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( self . zip_dir ) : <EOL> os . makedirs ( self . zip_dir ) <EOL> wiki_path = os . path . join ( <EOL> os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> shutil . copytree ( wiki_path , os . path . join ( self . job_dir , '<STR_LIT>' ) ) <EOL> except OSError , e : <EOL> if e . errno == errno . ENOTDIR : <EOL> shutil . copy ( wiki_path , os . path . join ( self . job_dir , '<STR_LIT>' ) ) <EOL> else : <EOL> raise <EOL> self . job_name = import_job_desc ( wiki_path ) . uniq_name <EOL> old_wiki_path = os . path . join ( self . job_dir , '<STR_LIT>' ) <EOL> new_wiki_path = os . path . join ( self . job_dir , self . job_name ) <EOL> os . rename ( old_wiki_path , new_wiki_path ) <EOL> ZipHandler . compress ( os . path . join ( self . zip_dir , self . job_name + '<STR_LIT>' ) , <EOL> new_wiki_path ) <EOL> config_file = os . path . join ( new_wiki_path , '<STR_LIT>' ) <EOL> try : <EOL> os . remove ( os . path . join ( new_wiki_path , '<STR_LIT>' ) ) <EOL> except : <EOL> pass <EOL> with open ( config_file ) as f : <EOL> yaml_obj = yaml . load ( f ) <EOL> yaml_obj [ '<STR_LIT>' ] [ '<STR_LIT:size>' ] = <NUM_LIT:5> <EOL> yaml_obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> yaml_obj [ '<STR_LIT>' ] [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> with open ( config_file , '<STR_LIT:w>' ) as f : <EOL> yaml . dump ( yaml_obj , f ) <EOL> def tearDown ( self ) : <EOL> try : <EOL> shutil . rmtree ( self . working_dir ) <EOL> except : <EOL> pass <EOL> def testMasterWorker ( self ) : <EOL> ctx = Context ( is_master = True , master_addr = '<STR_LIT:127.0.0.1>' , <EOL> working_dir = self . working_dir ) <EOL> master = ctx . start_master ( ) <EOL> ctx . start_worker ( ) <EOL> master . run_job ( self . job_name , wait_for_workers = True ) <EOL> while master . has_running_jobs ( ) : <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> master . shutdown ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
