<s> import unittest <EOL> import yaml <EOL> import os <EOL> import shutil <EOL> import marmot <EOL> from marmot . representations . wmt_representation_generator import WMTRepresentationGenerator <EOL> from marmot . experiment . import_utils import build_object <EOL> def join_with_module_path ( loader , node ) : <EOL> """<STR_LIT>""" <EOL> module_path = os . path . dirname ( marmot . representations . tests . __file__ ) <EOL> resolved = loader . construct_scalar ( node ) <EOL> return os . path . join ( module_path , resolved ) <EOL> yaml . add_constructor ( '<STR_LIT>' , join_with_module_path ) <EOL> class WMTRepresentationGeneratorTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> module_path = os . path . dirname ( __file__ ) <EOL> self . module_path = module_path <EOL> test_config = os . path . join ( module_path , '<STR_LIT>' ) <EOL> with open ( test_config , "<STR_LIT:r>" ) as cfg_file : <EOL> self . config = yaml . load ( cfg_file . read ( ) ) <EOL> self . wmt_target = os . path . join ( module_path , '<STR_LIT>' ) <EOL> self . wmt_source = os . path . join ( module_path , '<STR_LIT>' ) <EOL> self . tmp_dir = os . path . join ( module_path , '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> if os . path . exists ( self . tmp_dir ) and os . path . isdir ( self . tmp_dir ) : <EOL> shutil . rmtree ( self . tmp_dir ) <EOL> def test_load_from_config ( self ) : <EOL> generator = build_object ( self . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> data_obj = generator . generate ( ) <EOL> self . assertTrue ( '<STR_LIT:target>' in data_obj ) <EOL> self . assertTrue ( '<STR_LIT:source>' in data_obj ) <EOL> self . assertTrue ( '<STR_LIT>' in data_obj ) <EOL> self . assertTrue ( len ( data_obj [ '<STR_LIT:target>' ] ) == len ( data_obj [ '<STR_LIT:source>' ] ) ) <EOL> self . assertTrue ( len ( data_obj [ '<STR_LIT:target>' ] ) == len ( data_obj [ '<STR_LIT>' ] ) ) <EOL> def test_no_saved_files ( self ) : <EOL> generator = WMTRepresentationGenerator ( self . wmt_target , self . wmt_source ) <EOL> data_obj = generator . generate ( ) <EOL> self . assertTrue ( '<STR_LIT:target>' in data_obj ) <EOL> self . assertTrue ( '<STR_LIT:source>' in data_obj ) <EOL> self . assertTrue ( '<STR_LIT>' in data_obj ) <EOL> self . assertTrue ( len ( data_obj [ '<STR_LIT:target>' ] ) == len ( data_obj [ '<STR_LIT:source>' ] ) ) <EOL> self . assertTrue ( len ( data_obj [ '<STR_LIT:target>' ] ) == len ( data_obj [ '<STR_LIT>' ] ) ) <EOL> def test_save_files ( self ) : <EOL> generator = WMTRepresentationGenerator ( self . wmt_target , self . wmt_source , tmp_dir = self . tmp_dir , persist = True ) <EOL> data_obj = generator . generate ( ) <EOL> target = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> tags = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> source = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( self . tmp_dir ) and os . path . isdir ( self . tmp_dir ) ) <EOL> self . assertTrue ( os . path . exists ( target ) and os . path . isfile ( target ) ) <EOL> self . assertTrue ( os . path . exists ( tags ) and os . path . isfile ( tags ) ) <EOL> self . assertTrue ( os . path . exists ( source ) and os . path . isfile ( source ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
