<s> import os . path <EOL> import filecmp <EOL> import poioapi . mapper <EOL> import poioapi . data <EOL> class TestTierMapper : <EOL> _tm = None <EOL> _sample_file = '<STR_LIT>' <EOL> def setup ( self ) : <EOL> self . _sample_file = os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_load_mapping ( self ) : <EOL> self . _tm = poioapi . mapper . TierMapper ( ) <EOL> self . _tm . load_mapping ( self . _sample_file ) <EOL> assert len ( self . _tm . _tier_mapping ) == <NUM_LIT:2> <EOL> gloss_tier_labels = self . _tm . tier_labels ( poioapi . data . TIER_GLOSS ) <EOL> pos_tier_labels = self . _tm . tier_labels ( poioapi . data . TIER_POS ) <EOL> assert len ( gloss_tier_labels ) == <NUM_LIT:1> <EOL> assert len ( pos_tier_labels ) == <NUM_LIT:1> <EOL> def test_tier_labels ( self ) : <EOL> self . _tm = poioapi . mapper . TierMapper ( ) <EOL> self . _tm . load_mapping ( self . _sample_file ) <EOL> tiers_to_succeed = [ '<STR_LIT>' ] <EOL> tiers_to_test = self . _tm . tier_labels ( poioapi . data . TIER_GLOSS ) <EOL> assert set ( tiers_to_succeed ) == set ( tiers_to_test ) <EOL> no_tier_type = [ ] <EOL> no_type_to_test = self . _tm . tier_labels ( poioapi . data . TIER_TRANSLATION ) <EOL> assert no_tier_type == no_type_to_test <EOL> def test_tier_label ( self ) : <EOL> self . _tm = poioapi . mapper . TierMapper ( ) <EOL> self . _tm . load_mapping ( self . _sample_file ) <EOL> tier_to_succeed = '<STR_LIT>' <EOL> tier_to_test = self . _tm . tier_label ( poioapi . data . TIER_POS , <NUM_LIT:0> ) <EOL> assert tier_to_succeed == tier_to_test <EOL> def test_append ( self ) : <EOL> self . _tm = poioapi . mapper . TierMapper ( ) <EOL> self . _tm . load_mapping ( self . _sample_file ) <EOL> expected = [ '<STR_LIT>' , '<STR_LIT:test>' ] <EOL> self . _tm . append_to_tier_labels ( poioapi . data . TIER_GLOSS , [ '<STR_LIT:test>' ] ) <EOL> to_test = self . _tm . tier_labels ( poioapi . data . TIER_GLOSS ) <EOL> assert expected == to_test <EOL> def test_exists ( self ) : <EOL> self . _tm = poioapi . mapper . TierMapper ( ) <EOL> self . _tm . load_mapping ( self . _sample_file ) <EOL> tag_exists = self . _tm . tier_label_exists ( '<STR_LIT>' ) <EOL> tag_not_exists = self . _tm . tier_label_exists ( '<STR_LIT:test>' ) <EOL> assert tag_exists is True <EOL> assert tag_not_exists is False <EOL> class TestAnnotationMapper : <EOL> _am = None <EOL> _sample_file = '<STR_LIT>' <EOL> def setup ( self ) : <EOL> self . _sample_file = os . path . join ( os . path . dirname ( __file__ ) , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> def test_load_default ( self ) : <EOL> self . _am = poioapi . mapper . AnnotationMapper ( poioapi . data . MANDINKA , poioapi . data . TYPECRAFT ) <EOL> assert ( len ( self . _am . annotation_mappings ) == <NUM_LIT:1> ) <EOL> assert ( len ( self . _am . annotation_mappings [ poioapi . data . TIER_GLOSS ] ) == <NUM_LIT> ) <EOL> def test_load_user_mapping ( self ) : <EOL> self . _am = poioapi . mapper . AnnotationMapper ( poioapi . data . MANDINKA , poioapi . data . TYPECRAFT ) <EOL> self . _am . load_mappings ( self . _sample_file ) <EOL> assert ( len ( self . _am . annotation_mappings [ poioapi . data . TIER_GLOSS ] ) == <NUM_LIT> ) <EOL> def test_validate_tag ( self ) : <EOL> tag_to_succeed = '<STR_LIT>' <EOL> multitag_to_succeed = '<STR_LIT>' <EOL> self . _am = poioapi . mapper . AnnotationMapper ( poioapi . data . MANDINKA , poioapi . data . TYPECRAFT ) <EOL> self . _am . load_mappings ( self . _sample_file ) <EOL> assert ( self . _am . validate_tag ( poioapi . data . TIER_GLOSS , tag_to_succeed ) == '<STR_LIT>' ) <EOL> assert ( self . _am . validate_tag ( poioapi . data . TIER_GLOSS , multitag_to_succeed ) == '<STR_LIT>' ) <EOL> def test_export ( self ) : <EOL> self . _am = poioapi . mapper . AnnotationMapper ( poioapi . data . MANDINKA , poioapi . data . TYPECRAFT ) <EOL> self . _am . load_mappings ( self . _sample_file ) <EOL> self . _am . add_to_missing ( poioapi . data . TIER_GLOSS , '<STR_LIT>' ) <EOL> self . _am . add_to_missing ( poioapi . data . TIER_GLOSS , '<STR_LIT>' ) <EOL> filename = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> expected_filename = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _am . export_missing_tags ( filename ) <EOL> assert ( os . path . getsize ( filename ) == os . path . getsize ( expected_filename ) ) <EOL> assert ( filecmp . cmp ( filename , expected_filename , False ) is True ) </s>
