def test_fontline_commandline_longusage(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', '--usage'] main() out, err = capsys.readouterr() assert out.endswith("Usage: font-line [subcommand] <arg> [font path 1] <font path 2> <font path ...>") is True
def test_percent_cmd_percent_arg_less_zero(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', 'percent', '-1', 'Test.ttf'] main() out, err = capsys.readouterr() assert err == "[font-line] ERROR: Please enter a percent value that is greater than zero."
def test_percent_cmd_font_file_wrong_filetype(capsys): from fontline.app import main testfile_path = os.path.join("tests", "testingfiles", "bogus.txt") sys.argv = ['font-line', 'percent', '20', testfile_path] main() out, err = capsys.readouterr() assert ("does not appear to be a supported font file type." in err) is True
def test_report_cmd_reportstring_capheight(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[OS/2] CapHeight: 1493" in out
def test_report_cmd_reportstring_typodescender(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[OS/2] TypoDescender: \t-492" in out
def test_report_cmd_reportstring_winascent(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[OS/2] WinAscent: \t1901" in out
def test_report_cmd_reportstring_sha1(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "SHA1: 638f033cc1b6a21597359278bee62cf7e96557ff" in out
def test_report_cmd_reportstring_upm(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[head] Units per Em: \t2048" in out
def test_percent_cmd_too_few_args_two(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', 'percent', '10'] main() out, err = capsys.readouterr() assert err == "[font-line] ERROR: Not enough arguments."
def test_report_cmd_reportstring_version(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "Version 2.020;DEV-03192016;" in out
def test_report_cmd_reportstring_hhea_to_upm(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "(hhea Asc + Desc) / UPM: \t\t1.16" in out
def test_report_cmd_reportstring_ascent_descent(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[hhea] Ascent to Descent: \t\t2384" in out
def test_report_cmd_reportstring_ascent_typoasc(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "Ascent to TypoAscender: \t345" in out
def test_report_cmd_too_few_args(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', 'report'] main() out, err = capsys.readouterr() assert err == "[font-line] ERROR: Missing file path argument(s) after the report subcommand."
def test_report_cmd_reportstring_linegap(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[hhea] LineGap: \t0" in out
def test_fontline_commandline_bad_subcmd(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', 'bogus'] main() out, err = capsys.readouterr() assert err.startswith("[font-lines] ERROR: You used an unsupported") is True
def test_report_cmd_unsupported_filetype(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'bogus.txt') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert err.startswith("[font-line] ERROR: ")
def test_report_cmd_reportstring_ymin(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[head] yMin: -573" in out
def test_percent_cmd_percent_arg_not_integer(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', 'percent', 'astring', 'Test.ttf'] main() out, err = capsys.readouterr() assert err.startswith("[font-line] ERROR: You entered ") is True
def test_report_cmd_reportstring_hhea_to_upm(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "hhea metrics / UPM: 1.16" in out
def test_report_cmd_reportstring_fsselection_bit7_set_false(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[OS/2] fsSelection USE_TYPO_METRICS bit set: False" in out
def test_report_cmd_reportstring_descent_typodesc(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[hhea] Descent to [OS/2] TypoDescender: -9" in out
def test_report_cmd_reportstring_typolinegap(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[OS/2] TypoLineGap: 410" in out
def test_report_cmd_reportstring_ascent_descent(capsys): from fontline.app import main filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf') sys.argv = ['font-line', 'report', filepath] main() out, err = capsys.readouterr() assert "[hhea] Ascent to Descent: 2384" in out
def test_fontline_commandline_notenough_args(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line'] main() out, err = capsys.readouterr() assert err == "[font-line] ERROR: Please include one or more arguments with your command."
def test_percent_cmd_percent_arg_over_hundred(capsys): from fontline.app import main sys.argv = ['font-line', 'percent', '200', 'Test.ttf'] main() out, err = capsys.readouterr() assert out.startswith( "[font-line] Warning: You entered a percent value over 100%.")
def test_fontline_commandline_longhelp(capsys): with pytest.raises(SystemExit): from fontline.app import main sys.argv = ['font-line', '--help'] main() out, err = capsys.readouterr() assert out.startswith("====================================================") is True assert out.endswith("https://github.com/source-foundry/font-line") is True
def test_fontline_commandline_longversion(capsys): with pytest.raises(SystemExit): from fontline.app import main from fontline.app import settings sys.argv = ['font-line', '--version'] main() out, err = capsys.readouterr() assert out == settings.VERSION
def test_percent_cmd_ttf_file_30_percent_adobe_approach(capsys): try: from fontline.app import main fontpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular.ttf') testpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular-test.ttf') newfont_path = os.path.join( 'tests', 'testingfiles', 'SourceCodePro-Regular-test-linegap30.ttf') create_test_file(fontpath) assert file_exists(testpath) is True sys.argv = ['font-line', 'percent', '30', testpath] main() assert file_exists(newfont_path) tt = ttLib.TTFont(newfont_path) os2_typo_ascender = tt['OS/2'].sTypoAscender os2_typo_descender = tt['OS/2'].sTypoDescender os2_win_ascent = tt['OS/2'].usWinAscent os2_win_descent = tt['OS/2'].usWinDescent os2_typo_linegap = tt['OS/2'].sTypoLineGap hhea_ascent = tt['hhea'].ascent hhea_descent = tt['hhea'].descent hhea_linegap = tt['hhea'].lineGap units_per_em = tt['head'].unitsPerEm assert os2_typo_ascender == 750 assert os2_typo_descender == -250 assert os2_win_ascent == 1005 assert os2_win_descent == 294 assert units_per_em == 1000 assert os2_typo_linegap == 0 assert hhea_ascent == 1005 assert hhea_descent == -294 assert hhea_linegap == 0 erase_test_file(testpath) erase_test_file(newfont_path) except Exception as e: # cleanup test files if file_exists(testpath): erase_test_file(testpath) if file_exists(newfont_path): erase_test_file(newfont_path) raise e
def test_percent_cmd_otf_file_10_percent_default_approach(capsys): try: from fontline.app import main fontpath = os.path.join('tests', 'testingfiles', 'Hack-Regular.otf') testpath = os.path.join('tests', 'testingfiles', 'Hack-Regular-test.otf') newfont_path = os.path.join('tests', 'testingfiles', 'Hack-Regular-test-linegap10.otf') create_test_file(fontpath) assert file_exists(testpath) is True sys.argv = ['font-line', 'percent', '10', testpath] main() assert file_exists(newfont_path) tt = ttLib.TTFont(newfont_path) os2_typo_ascender = tt['OS/2'].sTypoAscender os2_typo_descender = tt['OS/2'].sTypoDescender os2_win_ascent = tt['OS/2'].usWinAscent os2_win_descent = tt['OS/2'].usWinDescent os2_typo_linegap = tt['OS/2'].sTypoLineGap hhea_ascent = tt['hhea'].ascent hhea_descent = tt['hhea'].descent hhea_linegap = tt['hhea'].lineGap units_per_em = tt['head'].unitsPerEm assert os2_typo_ascender == 1556 assert os2_typo_descender == -492 assert os2_win_ascent == 1658 assert os2_win_descent == 594 assert units_per_em == 2048 assert os2_typo_linegap == 204 assert hhea_ascent == 1658 assert hhea_descent == -594 assert hhea_linegap == 0 erase_test_file(testpath) erase_test_file(newfont_path) except Exception as e: # cleanup test files if file_exists(testpath): erase_test_file(testpath) if file_exists(newfont_path): erase_test_file(newfont_path) raise e
def test_percent_cmd_otf_file_10_percent(capsys): try: from fontline.app import main fontpath = os.path.join('tests', 'testingfiles', 'Hack-Regular.otf') testpath = os.path.join('tests', 'testingfiles', 'Hack-Regular-test.otf') newfont_path = os.path.join('tests', 'testingfiles', 'Hack-Regular-test-linegap10.otf') create_test_file(fontpath) assert file_exists(testpath) is True sys.argv = ['font-line', 'percent', '10', testpath] main() assert file_exists(newfont_path) tt = ttLib.TTFont(newfont_path) os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender'] os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender'] os2_win_ascent = tt['OS/2'].__dict__['usWinAscent'] os2_win_descent = tt['OS/2'].__dict__['usWinDescent'] os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap'] hhea_ascent = tt['hhea'].__dict__['ascent'] hhea_descent = tt['hhea'].__dict__['descent'] hhea_linegap = tt['hhea'].__dict__['lineGap'] units_per_em = tt['head'].__dict__['unitsPerEm'] assert os2_typo_ascender == 1556 assert os2_typo_descender == -492 assert os2_win_ascent == 1658 assert os2_win_descent == 594 assert units_per_em == 2048 assert os2_typo_linegap == 204 assert hhea_ascent == 1658 assert hhea_descent == -594 assert hhea_linegap == 0 erase_test_file(testpath) erase_test_file(newfont_path) except Exception as e: # cleanup test files if file_exists(testpath): erase_test_file(testpath) if file_exists(newfont_path): erase_test_file(newfont_path) raise e
def test_percent_cmd_ttf_file_30_percent_adobe_approach(capsys): try: from fontline.app import main fontpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular.ttf') testpath = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular-test.ttf') newfont_path = os.path.join('tests', 'testingfiles', 'SourceCodePro-Regular-test-linegap30.ttf') create_test_file(fontpath) assert file_exists(testpath) is True sys.argv = ['font-line', 'percent', '30', testpath] main() assert file_exists(newfont_path) tt = ttLib.TTFont(newfont_path) os2_typo_ascender = tt['OS/2'].sTypoAscender os2_typo_descender = tt['OS/2'].sTypoDescender os2_win_ascent = tt['OS/2'].usWinAscent os2_win_descent = tt['OS/2'].usWinDescent os2_typo_linegap = tt['OS/2'].sTypoLineGap hhea_ascent = tt['hhea'].ascent hhea_descent = tt['hhea'].descent hhea_linegap = tt['hhea'].lineGap units_per_em = tt['head'].unitsPerEm assert os2_typo_ascender == 750 assert os2_typo_descender == -250 assert os2_win_ascent == 1005 assert os2_win_descent == 294 assert units_per_em == 1000 assert os2_typo_linegap == 0 assert hhea_ascent == 1005 assert hhea_descent == -294 assert hhea_linegap == 0 erase_test_file(testpath) erase_test_file(newfont_path) except Exception as e: # cleanup test files if file_exists(testpath): erase_test_file(testpath) if file_exists(newfont_path): erase_test_file(newfont_path) raise e
def test_percent_cmd_font_file_missing(capsys): from fontline.app import main sys.argv = ['font-line', 'percent', '20', 'Test.ttf'] main() out, err = capsys.readouterr() assert ("does not appear to be a valid filepath" in err) is True
def test_report_cmd_missing_file_request(capsys): from fontline.app import main sys.argv = ['font-line', 'report', 'missing.txt'] main() out, err = capsys.readouterr() assert err.startswith("[font-line] ERROR: ")
def test_percent_cmd_percent_arg_over_hundred(capsys): from fontline.app import main sys.argv = ['font-line', 'percent', '200', 'Test.ttf'] main() out, err = capsys.readouterr() assert out.startswith("[font-line] Warning: You entered a percent value over 100%.")