本文整理汇总了Python中bakery_lint.metadata.Metadata类的典型用法代码示例。如果您正苦于以下问题:Python Metadata类的具体用法?Python Metadata怎么用?Python Metadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Metadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_normal_style_matches_names
def test_check_normal_style_matches_names(self):
""" Check metadata.json font.style `italic` matches font internal """
contents = self.read_metadata_contents()
family = Metadata.get_family_metadata(contents)
for font_metadata in family.fonts:
if font_metadata.style != 'normal':
continue
font = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
if bool(font.macStyle & 0b10):
self.fail(('Metadata style has been set to normal'
' but font second bit (italic) in macStyle has'
' been set'))
style = font.familyname.split('-')[-1]
if style.endswith('Italic'):
self.fail(('macStyle second bit is not set but postScriptName "%s"'
' is ended with "Italic"') % font.familyname)
style = font.fullname.split('-')[-1]
if style.endswith('Italic'):
self.fail(('macStyle second bit is not set but fullName "%s"'
' is ended with "Italic"') % font.fullname)
示例2: test_metadata_copyright_size
def test_metadata_copyright_size(self):
""" Copyright notice should be less than 500 chars """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
self.assertLessEqual(len(font_metadata.copyright), 500)
示例3: test_check_metadata_fields
def test_check_metadata_fields(self):
""" Check METADATA.json "fonts" property items have required field """
contents = self.read_metadata_contents()
family = Metadata.get_family_metadata(contents)
keys = [("name", str), ("postScriptName", str),
("fullName", str), ("style", str),
("weight", int), ("filename", str),
("copyright", str)]
missing = set([])
unknown = set([])
for j, itemtype in keys:
for font_metadata in family.fonts:
if j not in font_metadata:
missing.add(j)
for k in font_metadata:
if k not in map(lambda x: x[0], keys):
unknown.add(k)
if unknown:
msg = 'METADATA.json "fonts" property has unknown items [%s]'
self.fail(msg % ', '.join(unknown))
if missing:
msg = 'METADATA.json "fonts" property items missed [%s] items'
self.fail(msg % ', '.join(missing))
示例4: test_metrics_descents_equal_bbox
def test_metrics_descents_equal_bbox(self):
""" Check that descents values are same as min glyph point """
contents = self.read_metadata_contents()
family_metadata = Metadata.get_family_metadata(contents)
fonts_descents_not_bbox = []
ymin = 0
_cache = {}
for font_metadata in family_metadata.fonts:
ttfont = Font.get_ttfont_from_metadata(self.path, font_metadata)
ymin_, ymax_ = ttfont.get_bounding()
ymin = min(ymin, ymin_)
_cache[font_metadata.filename] = {
'os2typo': abs(ttfont.descents.os2typo),
'os2win': abs(ttfont.descents.os2win),
'hhea': abs(ttfont.descents.hhea)
}
for filename, data in _cache.items():
if [data['os2typo'], data['os2win'], data['hhea']] != [abs(ymin)] * 3:
fonts_descents_not_bbox.append(filename)
if fonts_descents_not_bbox:
_ = '[%s] ascents differ to minimum value: %s'
self.fail(_ % (', '.join(fonts_descents_not_bbox), ymin))
示例5: test_check_menu_contains_proper_glyphs
def test_check_menu_contains_proper_glyphs(self):
""" Check menu file contains proper glyphs """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
tf = Font.get_ttfont_from_metadata(self.operator.path, font_metadata, is_menu=True)
self.check_retrieve_glyphs(tf, font_metadata)
示例6: generate
def generate(config, outfile='review.html'):
directory = UpstreamDirectory(config['path'])
fonts = [(path, FontFactory.openfont(op.join(config['path'], path)))
for path in directory.BIN]
metadata_file = open(op.join(config['path'], 'METADATA.json')).read()
family_metadata = Metadata.get_family_metadata(metadata_file)
faces = []
for f in family_metadata.fonts:
faces.append({'name': f.full_name,
'basename': f.post_script_name,
'path': f.filename,
'meta': f})
destfile = open(op.join(config['path'], 'review.html'), 'w')
app_version = report_utils.git_info(config)
report_app = report_utils.ReportApp(config)
fonts_orthography = get_orthography(fonts)
report_app.review_page.dump_file(fonts_orthography, 'orthography.json')
print(report_utils.render_template(
outfile, fonts=faces, markdown=markdown, current_page=outfile,
get_weight_name=get_weight_name,
build_repo_url=report_utils.build_repo_url, app_version=app_version,
get_orthography=get_orthography_old, fontaineFonts=fonts), file=destfile)
示例7: test_check_canonical_filenames
def test_check_canonical_filenames(self):
""" Test If filename is canonical """
contents = self.read_metadata_contents()
family_metadata = Metadata.get_family_metadata(contents)
for font_metadata in family_metadata.fonts:
canonical_filename = self.create_canonical_filename(font_metadata)
self.assertEqual(canonical_filename, font_metadata.filename)
示例8: test_copyright_matches_pattern
def test_copyright_matches_pattern(self):
""" Copyright string matches to Copyright * 20\d\d * (*@*.*) """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
self.assertRegexpMatches(font_metadata.copyright,
r'Copyright\s+\(c\)\s+20\d{2}.*\(.*@.*.*\)')
示例9: test_check_familyname_matches_fontnames
def test_check_familyname_matches_fontnames(self):
""" Check font name is the same as family name """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
_ = '%s: Family name "%s" does not match font name: "%s"'
_ = _ % (font_metadata.filename, fm.name, font_metadata.name)
self.assertEqual(font_metadata.name, fm.name, _)
示例10: test_check_canonical_filenames
def test_check_canonical_filenames(self):
""" Test If filename is canonical """
contents = self.read_metadata_contents()
family_metadata = Metadata.get_family_metadata(contents)
for font_metadata in family_metadata.fonts:
canonical_filename = self.create_canonical_filename(font_metadata)
if canonical_filename != font_metadata.filename:
self.fail('{} != {}'.format(canonical_filename,
font_metadata.filename))
示例11: test_copyright_contains_correct_rfn
def test_copyright_contains_correct_rfn(self):
""" Copyright notice does not contain Reserved File Name """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
if 'Reserved Font Name' in font_metadata.copyright:
msg = '"%s" contains "Reserved File Name"'
self.fail(msg % font_metadata.copyright)
示例12: test_copyright_is_consistent_across_family
def test_copyright_is_consistent_across_family(self):
""" Copyright notice is the same in all fonts? """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
copyright = ''
for font_metadata in fm.fonts:
if copyright and font_metadata.copyright != copyright:
self.fail('Copyright is inconsistent across family')
copyright = font_metadata.copyright
示例13: test_postscriptname_contains_correct_weight
def test_postscriptname_contains_correct_weight(self):
""" Metadata weight matches postScriptName """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
if 'Reserved Font Name' not in font_metadata.copyright:
msg = '"%s" should have "Reserved File Name"'
self.fail(msg % font_metadata.copyright)
示例14: test_postscriptname_contains_correct_weight
def test_postscriptname_contains_correct_weight(self):
""" Metadata weight matches postScriptName """
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
font = Font.get_ttfont_from_metadata(self.path, font_metadata)
if font.OS2_usWeightClass != font_metadata.weight:
msg = 'METADATA.JSON has weight %s but in TTF it is %s'
self.fail(msg % (font_metadata.weight, font.OS2_usWeightClass))
示例15: test_check_metadata_matches_nametable
def test_check_metadata_matches_nametable(self):
contents = self.read_metadata_contents()
fm = Metadata.get_family_metadata(contents)
for font_metadata in fm.fonts:
ttfont = Font.get_ttfont_from_metadata(self.path, font_metadata)
report = '%s: Family name was supposed to be "%s" but is "%s"'
report = report % (font_metadata.name, fm.name,
ttfont.familyname)
self.assertEqual(ttfont.familyname, fm.name, report)
self.assertEqual(ttfont.fullname, font_metadata.full_name)