<s> """<STR_LIT>""" <EOL> import magic <EOL> import os <EOL> import os . path as op <EOL> import re <EOL> import requests <EOL> from google . protobuf import text_format <EOL> from bakery_cli . fonts_public_pb2 import FontProto , FamilyProto <EOL> from bakery_cli . ttfont import Font <EOL> from bakery_lint . base import BakeryTestCase as TestCase , tags , autofix <EOL> from bakery_lint . base import TestCaseOperator <EOL> def get_test_subset_function ( path ) : <EOL> def function ( self ) : <EOL> if not op . exists ( path ) : <EOL> self . fail ( '<STR_LIT>' % op . basename ( path ) ) <EOL> if magic . from_file ( path ) != '<STR_LIT>' : <EOL> _ = '<STR_LIT>' <EOL> self . fail ( _ % op . basename ( path ) ) <EOL> function . tags = [ '<STR_LIT>' ] <EOL> return function <EOL> def get_FamilyProto_Message ( path ) : <EOL> metadata = FamilyProto ( ) <EOL> text_data = open ( path , "<STR_LIT:rb>" ) . read ( ) <EOL> text_format . Merge ( text_data , metadata ) <EOL> return metadata <EOL> class MetadataSubsetsListTest ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> name = __name__ <EOL> @ classmethod <EOL> def __generateTests__ ( cls ) : <EOL> try : <EOL> metadata = get_FamilyProto_Message ( cls . operator . path ) <EOL> except : <EOL> return <EOL> for font in metadata . fonts : <EOL> for subset in metadata . subsets : <EOL> path = op . join ( op . dirname ( cls . operator . path ) , <EOL> font . filename [ : - <NUM_LIT:3> ] + subset ) <EOL> subsetid = re . sub ( r'<STR_LIT>' , '<STR_LIT:_>' , subset ) <EOL> exec '<STR_LIT>' . format ( subsetid , path ) <EOL> exec '<STR_LIT>' . format ( subsetid , font . filename [ : - <NUM_LIT:3> ] + subset ) <EOL> class TestFontOnDiskFamilyEqualToMetadataProtoBuf ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> @ tags ( '<STR_LIT>' , ) <EOL> def test_font_on_disk_family_equal_in_metadata_protobuf ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = get_FamilyProto_Message ( self . operator . path ) <EOL> unmatched_fonts = [ ] <EOL> for font_metadata in metadata . fonts : <EOL> try : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , <EOL> font_metadata ) <EOL> except IOError : <EOL> continue <EOL> if font . familyname != font_metadata . name : <EOL> unmatched_fonts . append ( font_metadata . filename ) <EOL> if unmatched_fonts : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg . format ( '<STR_LIT:U+002CU+0020>' . join ( unmatched_fonts ) ) ) <EOL> class TestPostScriptNameInMetadataEqualFontOnDisk ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_postscriptname_in_metadata_equal_to_font_on_disk ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in metadata . fonts : <EOL> try : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> except IOError : <EOL> continue <EOL> if font . post_script_name != font_metadata . post_script_name : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg . format ( font . post_script_name , <EOL> font_metadata . post_script_name ) ) <EOL> class CheckMetadataAgreements ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . metadata = get_FamilyProto_Message ( self . operator . path ) <EOL> def test_metadata_family_values_are_all_the_same ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> for font_metadata in self . metadata . fonts : <EOL> if name and font_metadata . name != name : <EOL> self . fail ( '<STR_LIT>' ) <EOL> name = font_metadata . name <EOL> def test_metadata_font_have_regular ( self ) : <EOL> """<STR_LIT>""" <EOL> have = False <EOL> for i in self . metadata . fonts : <EOL> if i . weight == <NUM_LIT> and i . style == '<STR_LIT>' : <EOL> have = True <EOL> self . assertTrue ( have ) <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_metadata_regular_is_400 ( self ) : <EOL> """<STR_LIT>""" <EOL> have = False <EOL> for i in self . metadata . fonts : <EOL> if i . filename . endswith ( '<STR_LIT>' ) and i . weight == <NUM_LIT> : <EOL> have = True <EOL> if not have : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> def test_metadata_regular_is_normal ( self ) : <EOL> """<STR_LIT>""" <EOL> have = False <EOL> for x in self . metadata . fonts : <EOL> if x . full_name . endswith ( '<STR_LIT>' ) and x . style == '<STR_LIT>' : <EOL> have = True <EOL> self . assertTrue ( have ) <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_metadata_filename_matches_postscriptname ( self ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> regex = re . compile ( r'<STR_LIT>' ) <EOL> fonts = [ font for font in self . metadata . fonts <EOL> if not font . post_script_name . endswith ( '<STR_LIT>' ) ] <EOL> for x in fonts : <EOL> post_script_name = regex . sub ( '<STR_LIT>' , x . post_script_name ) <EOL> filename = regex . sub ( '<STR_LIT>' , os . path . splitext ( x . filename ) [ <NUM_LIT:0> ] ) <EOL> if filename != post_script_name : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg . format ( x . filename , x . post_script_name ) ) <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_metadata_fullname_matches_postScriptName ( self ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> regex = re . compile ( r'<STR_LIT>' ) <EOL> for x in self . metadata . fonts : <EOL> post_script_name = regex . sub ( '<STR_LIT>' , x . post_script_name ) <EOL> fullname = regex . sub ( '<STR_LIT>' , x . full_name ) <EOL> if fullname != post_script_name : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg . format ( x . full_name , x . post_script_name ) ) <EOL> def test_metadata_fullname_is_equal_to_internal_font_fullname ( self ) : <EOL> """<STR_LIT>""" <EOL> for font_metadata in self . metadata . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> self . assertEqual ( font . fullname , font_metadata . full_name ) <EOL> def test_font_name_matches_family ( self ) : <EOL> """<STR_LIT>""" <EOL> for font_metadata in self . metadata . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if font_metadata . name != font . familyname : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg ) <EOL> def test_metadata_fonts_fields_have_fontname ( self ) : <EOL> """<STR_LIT>""" <EOL> for x in self . metadata . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , x ) <EOL> self . assertIn ( font . familyname , x . name ) <EOL> self . assertIn ( font . familyname , x . full_name ) <EOL> self . assertIn ( "<STR_LIT>" . join ( str ( font . familyname ) . split ( ) ) , <EOL> x . filename ) <EOL> self . assertIn ( "<STR_LIT>" . join ( str ( font . familyname ) . split ( ) ) , <EOL> x . post_script_name ) <EOL> class CheckMetadataContainsReservedFontName ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> @ tags ( '<STR_LIT:info>' ) <EOL> def test_copyright_contains_correct_rfn ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> if '<STR_LIT>' in font_metadata . copyright : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg % font_metadata . copyright ) <EOL> @ tags ( '<STR_LIT:info>' ) <EOL> def test_copyright_matches_pattern ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> almost_matches = re . search ( r'<STR_LIT>' , font_metadata . copyright ) <EOL> does_match = re . search ( r'<STR_LIT>' , font_metadata . copyright ) <EOL> if ( does_match == None ) : <EOL> if ( almost_matches ) : <EOL> self . fail ( "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> @ tags ( '<STR_LIT:info>' ) <EOL> def test_copyright_is_consistent_across_family ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> copyright = '<STR_LIT>' <EOL> for font_metadata in fm . fonts : <EOL> if copyright and font_metadata . copyright != copyright : <EOL> self . fail ( '<STR_LIT>' ) <EOL> copyright = font_metadata . copyright <EOL> @ tags ( '<STR_LIT:info>' ) <EOL> def test_metadata_copyright_size ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> self . assertLessEqual ( len ( font_metadata . copyright ) , <NUM_LIT> ) <EOL> class File ( object ) : <EOL> def __init__ ( self , rootdir ) : <EOL> self . rootdir = rootdir <EOL> def exists ( self , filename ) : <EOL> return op . exists ( op . join ( self . rootdir , filename ) ) <EOL> def size ( self , filename ) : <EOL> return op . getsize ( op . join ( self . rootdir , filename ) ) <EOL> def mime ( self , filename ) : <EOL> return magic . from_file ( op . join ( self . rootdir , filename ) , mime = True ) <EOL> class CheckMonospaceAgreement ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def test_check_monospace_agreement ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> if fm . category != '<STR_LIT>' : <EOL> return <EOL> for font_metadata in fm . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , <EOL> font_metadata . filename ) <EOL> prev = <NUM_LIT:0> <EOL> for g in font . glyphs ( ) : <EOL> if prev and font . advance_width ( g ) != prev : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' % prev ) ) <EOL> prev = font . advance_width ( g ) <EOL> if prev != font . advance_width ( ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . fail ( msg % ( prev , font . advance_width ( ) ) ) <EOL> class CheckItalicStyleMatchesMacStyle ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def test_check_italic_style_matches_names ( self ) : <EOL> """<STR_LIT>""" <EOL> family = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in family . fonts : <EOL> if font_metadata . style != '<STR_LIT>' : <EOL> continue <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if not bool ( font . macStyle & <NUM_LIT> ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> style = font . familyname . split ( '<STR_LIT:->' ) [ - <NUM_LIT:1> ] <EOL> if not style . endswith ( '<STR_LIT>' ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % font . familyname ) <EOL> style = font . fullname . split ( '<STR_LIT:->' ) [ - <NUM_LIT:1> ] <EOL> if not style . endswith ( '<STR_LIT>' ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % font . fullname ) <EOL> class CheckNormalStyleMatchesMacStyle ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def test_check_normal_style_matches_names ( self ) : <EOL> """<STR_LIT>""" <EOL> family = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in family . fonts : <EOL> if font_metadata . style != '<STR_LIT>' : <EOL> continue <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if bool ( font . macStyle & <NUM_LIT> ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> style = font . familyname . split ( '<STR_LIT:->' ) [ - <NUM_LIT:1> ] <EOL> if style . endswith ( '<STR_LIT>' ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % font . familyname ) <EOL> style = font . fullname . split ( '<STR_LIT:->' ) [ - <NUM_LIT:1> ] <EOL> if style . endswith ( '<STR_LIT>' ) : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % font . fullname ) <EOL> class CheckMetadataMatchesNameTable ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> name = __name__ <EOL> def test_check_metadata_matches_nametable ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> ttfont = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> report = '<STR_LIT>' <EOL> report = report % ( font_metadata . name , fm . name , <EOL> ttfont . familyname ) <EOL> self . assertEqual ( ttfont . familyname , fm . name , report ) <EOL> self . assertEqual ( ttfont . fullname , font_metadata . full_name ) <EOL> class CheckMenuSubsetContainsProperGlyphs ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_check_menu_contains_proper_glyphs ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> tf = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata , is_menu = True ) <EOL> self . check_retrieve_glyphs ( tf , font_metadata ) <EOL> def check_retrieve_glyphs ( self , ttfont , font_metadata ) : <EOL> cmap = ttfont . retrieve_cmap_format_4 ( ) <EOL> glyphs = cmap . cmap <EOL> missing_glyphs = set ( ) <EOL> if ord ( '<STR_LIT:U+0020>' ) not in glyphs : <EOL> missing_glyphs . add ( '<STR_LIT:U+0020>' ) <EOL> for g in font_metadata . name : <EOL> if ord ( g ) not in glyphs : <EOL> missing_glyphs . add ( g ) <EOL> if missing_glyphs : <EOL> _ = '<STR_LIT>' <EOL> report = _ % ( font_metadata . filename , '<STR_LIT>' . join ( missing_glyphs ) ) <EOL> self . fail ( report ) <EOL> class CheckGlyphConsistencyInFamily ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> name = __name__ <EOL> def setUp ( self ) : <EOL> self . familymetadata = get_FamilyProto_Message ( self . operator . path ) <EOL> def test_the_same_number_of_glyphs_across_family ( self ) : <EOL> """<STR_LIT>""" <EOL> glyphs_count = <NUM_LIT:0> <EOL> for font_metadata in self . familymetadata . fonts : <EOL> ttfont = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if not glyphs_count : <EOL> glyphs_count = len ( ttfont . glyphs ) <EOL> if glyphs_count != len ( ttfont . glyphs ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_the_same_names_of_glyphs_across_family ( self ) : <EOL> """<STR_LIT>""" <EOL> glyphs = None <EOL> for font_metadata in self . familymetadata . fonts : <EOL> ttfont = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if not glyphs : <EOL> glyphs = len ( ttfont . glyphs ) <EOL> if glyphs != len ( ttfont . glyphs ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_the_same_encodings_of_glyphs_across_family ( self ) : <EOL> """<STR_LIT>""" <EOL> encoding = None <EOL> for font_metadata in self . familymetadata . fonts : <EOL> ttfont = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> cmap = ttfont . retrieve_cmap_format_4 ( ) <EOL> if not encoding : <EOL> encoding = cmap . platEncID <EOL> if encoding != cmap . platEncID : <EOL> self . fail ( '<STR_LIT>' ) <EOL> class CheckFontNameNotInCamelCase ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_fontname_not_in_camel_case ( self ) : <EOL> """<STR_LIT>""" <EOL> familymetadata = get_FamilyProto_Message ( self . operator . path ) <EOL> camelcased_fontnames = [ ] <EOL> for font_metadata in familymetadata . fonts : <EOL> if bool ( re . match ( r'<STR_LIT>' , font_metadata . name ) ) : <EOL> camelcased_fontnames . append ( font_metadata . name ) <EOL> if camelcased_fontnames : <EOL> self . fail ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> class CheckFontsMenuAgreements ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def menufile ( self , font_metadata ) : <EOL> return '<STR_LIT>' % font_metadata . filename [ : - <NUM_LIT:4> ] <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_menu_file_agreement ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> menufile = self . menufile ( font_metadata ) <EOL> path = op . join ( op . dirname ( self . operator . path ) , menufile ) <EOL> if not op . exists ( path ) : <EOL> self . fail ( '<STR_LIT>' % menufile ) <EOL> if magic . from_file ( path ) != '<STR_LIT>' : <EOL> self . fail ( '<STR_LIT>' % menufile ) <EOL> class CheckFamilyNameMatchesFontNames ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> def test_check_familyname_matches_fontnames ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> _ = '<STR_LIT>' <EOL> _ = _ % ( font_metadata . filename , fm . name , font_metadata . name ) <EOL> self . assertEqual ( font_metadata . name , fm . name , _ ) <EOL> weights = { <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : <NUM_LIT:200> , <EOL> '<STR_LIT>' : <NUM_LIT:200> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> class CheckCanonicalWeights ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_check_canonical_weights ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> weight = font_metadata . weight <EOL> first_digit = weight / <NUM_LIT:100> <EOL> is_invalid = ( weight % <NUM_LIT:100> ) != <NUM_LIT:0> or ( first_digit < <NUM_LIT:1> <EOL> or first_digit > <NUM_LIT:9> ) <EOL> _ = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( is_invalid , _ % ( op . basename ( self . operator . path ) , <EOL> font_metadata . weight ) ) <EOL> tf = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> _ = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> _ = _ % ( font_metadata . filename , font_metadata . weight , <EOL> font_metadata . filename , tf . OS2_usWeightClass ) <EOL> self . assertEqual ( tf . OS2_usWeightClass , font_metadata . weight ) <EOL> class CheckPostScriptNameMatchesWeight ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_postscriptname_contains_correct_weight ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> pair = [ ] <EOL> for k , weight in weights . items ( ) : <EOL> if weight == font_metadata . weight : <EOL> pair . append ( ( k , weight ) ) <EOL> if not pair : <EOL> self . fail ( '<STR_LIT>' ) <EOL> if not ( font_metadata . post_script_name . endswith ( '<STR_LIT>' % pair [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> or font_metadata . post_script_name . endswith ( '<STR_LIT>' % pair [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) ) : <EOL> _ = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . fail ( _ % ( pair [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , pair [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , pair [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) ) <EOL> class CheckFontWeightSameAsInMetadata ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_font_weight_same_as_in_metadata ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> if font . OS2_usWeightClass != font_metadata . weight : <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg % ( font_metadata . weight , font . OS2_usWeightClass ) ) <EOL> class CheckFullNameEqualCanonicalName ( TestCase ) : <EOL> targets = [ '<STR_LIT>' ] <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> def test_metadata_contains_current_font ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> is_canonical = False <EOL> for font_metadata in fm . fonts : <EOL> font = Font . get_ttfont_from_metadata ( self . operator . path , font_metadata ) <EOL> _weights = [ ] <EOL> for value , intvalue in weights . items ( ) : <EOL> if intvalue == font . OS2_usWeightClass : <EOL> _weights . append ( value ) <EOL> for w in _weights : <EOL> current_font = "<STR_LIT>" % ( font . familyname , w ) <EOL> if font_metadata . full_name != current_font : <EOL> is_canonical = True <EOL> if not is_canonical : <EOL> v = map ( lambda x : font . familyname + '<STR_LIT:U+0020>' + x , _weights ) <EOL> msg = '<STR_LIT>' <EOL> self . fail ( msg % ( v , font_metadata . full_name ) ) <EOL> class CheckCanonicalStyles ( TestCase ) : <EOL> name = __name__ <EOL> targets = [ '<STR_LIT>' ] <EOL> tool = '<STR_LIT>' <EOL> CANONICAL_STYLE_VALUES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ITALIC_MASK = <NUM_LIT> <EOL> def test_check_canonical_styles ( self ) : <EOL> """<STR_LIT>""" <EOL> fm = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in fm . fonts : <EOL> self . assertIn ( font_metadata . style , self . CANONICAL_STYLE_VALUES ) <EOL> if self . is_italic ( font_metadata ) : <EOL> if font_metadata . style != '<STR_LIT>' : <EOL> _ = "<STR_LIT>" <EOL> self . fail ( _ % ( font_metadata . filename , font_metadata . style ) ) <EOL> else : <EOL> if font_metadata . style != '<STR_LIT>' : <EOL> _ = "<STR_LIT>" <EOL> self . fail ( _ % ( font_metadata . filename , font_metadata . style ) ) <EOL> def is_italic ( self , font_metadata ) : <EOL> ttfont = Font . get_ttfont_from_metadata ( self . operator . path , <EOL> font_metadata ) <EOL> return ( ttfont . macStyle & self . ITALIC_MASK <EOL> or ttfont . italicAngle <EOL> or self . find_italic_in_name_table ( ttfont ) ) <EOL> def find_italic_in_name_table ( self , ttfont ) : <EOL> for entry in ttfont . names : <EOL> if '<STR_LIT>' in Font . bin2unistring ( entry ) . lower ( ) : <EOL> return True <EOL> class CheckCanonicalFilenames ( TestCase ) : <EOL> weights = { <EOL> <NUM_LIT:100> : '<STR_LIT>' , <EOL> <NUM_LIT:200> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' <EOL> } <EOL> style_names = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> name = __name__ <EOL> tool = '<STR_LIT>' <EOL> targets = [ '<STR_LIT>' ] <EOL> @ tags ( '<STR_LIT>' ) <EOL> def test_check_canonical_filenames ( self ) : <EOL> """<STR_LIT>""" <EOL> family_metadata = get_FamilyProto_Message ( self . operator . path ) <EOL> for font_metadata in family_metadata . fonts : <EOL> canonical_filename = self . create_canonical_filename ( font_metadata ) <EOL> if canonical_filename != font_metadata . filename : <EOL> self . fail ( '<STR_LIT>' . format ( canonical_filename , <EOL> font_metadata . filename ) ) <EOL> def create_canonical_filename ( self , font_metadata ) : <EOL> familyname = font_metadata . name . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> style_weight = '<STR_LIT>' % ( self . weights . get ( font_metadata . weight ) , <EOL> self . style_names . get ( font_metadata . style ) ) <EOL> if not style_weight : <EOL> style_weight = '<STR_LIT>' <EOL> return '<STR_LIT>' % ( familyname , style_weight ) <EOL> def get_suite ( path , apply_autofix = False ) : <EOL> import unittest <EOL> suite = unittest . TestSuite ( ) <EOL> testcases = [ <EOL> MetadataSubsetsListTest , <EOL> MetadataTest , <EOL> TestFontOnDiskFamilyEqualToMetadataProtoBuf , <EOL> TestPostScriptNameInMetadataEqualFontOnDisk , <EOL> CheckMetadataAgreements , <EOL> CheckMetadataContainsReservedFontName , <EOL> CheckMonospaceAgreement , <EOL> CheckItalicStyleMatchesMacStyle , <EOL> CheckNormalStyleMatchesMacStyle , <EOL> CheckMetadataMatchesNameTable , <EOL> CheckMenuSubsetContainsProperGlyphs , <EOL> CheckGlyphConsistencyInFamily , <EOL> CheckFontNameNotInCamelCase , <EOL> CheckFontsMenuAgreements , <EOL> CheckFamilyNameMatchesFontNames , <EOL> CheckCanonicalWeights , <EOL> CheckPostScriptNameMatchesWeight , <EOL> CheckFontWeightSameAsInMetadata , <EOL> CheckFullNameEqualCanonicalName , <EOL> CheckCanonicalStyles , <EOL> CheckCanonicalFilenames <EOL> ] <EOL> for testcase in testcases : <EOL> testcase . operator = TestCaseOperator ( path ) <EOL> testcase . apply_fix = apply_autofix <EOL> if getattr ( testcase , '<STR_LIT>' , False ) : <EOL> if testcase . skipUnless ( ) : <EOL> continue <EOL> if getattr ( testcase , '<STR_LIT>' , None ) : <EOL> testcase . __generateTests__ ( ) <EOL> for test in unittest . defaultTestLoader . loadTestsFromTestCase ( testcase ) : <EOL> suite . addTest ( test ) <EOL> return suite </s>
