From 1a58912a6036d7254429d47427b876604a6f4433 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 27 Mar 2017 04:04:02 -0700 Subject: [PATCH] [ttx] Tests --- Tests/ttx/data/TestBOM.ttx | 3 + Tests/ttx/data/TestDFONT.dfont | Bin 0 -> 3505 bytes Tests/ttx/data/TestFFIL | 0 Tests/ttx/data/TestNoSFNT.ttx | 2 + Tests/ttx/data/TestNoXML.ttx | 2 + Tests/ttx/data/TestOTF.otf | Bin 0 -> 2308 bytes Tests/ttx/data/TestOTF.ttx | 519 +++++++++++++++++++++++++++++++ Tests/ttx/data/TestTTC.ttc | Bin 0 -> 2608 bytes Tests/ttx/data/TestTTF.ttf | Bin 0 -> 2336 bytes Tests/ttx/data/TestTTF.ttx | 553 +++++++++++++++++++++++++++++++++ Tests/ttx/data/TestWOFF.woff | Bin 0 -> 1328 bytes Tests/ttx/data/TestWOFF2.woff2 | Bin 0 -> 808 bytes Tests/ttx/ttx_test.py | 202 ++++++++++++ 13 files changed, 1281 insertions(+) create mode 100644 Tests/ttx/data/TestBOM.ttx create mode 100644 Tests/ttx/data/TestDFONT.dfont create mode 100755 Tests/ttx/data/TestFFIL create mode 100644 Tests/ttx/data/TestNoSFNT.ttx create mode 100644 Tests/ttx/data/TestNoXML.ttx create mode 100644 Tests/ttx/data/TestOTF.otf create mode 100644 Tests/ttx/data/TestOTF.ttx create mode 100644 Tests/ttx/data/TestTTC.ttc create mode 100644 Tests/ttx/data/TestTTF.ttf create mode 100644 Tests/ttx/data/TestTTF.ttx create mode 100644 Tests/ttx/data/TestWOFF.woff create mode 100644 Tests/ttx/data/TestWOFF2.woff2 create mode 100644 Tests/ttx/ttx_test.py diff --git a/Tests/ttx/data/TestBOM.ttx b/Tests/ttx/data/TestBOM.ttx new file mode 100644 index 000000000..7597133da --- /dev/null +++ b/Tests/ttx/data/TestBOM.ttx @@ -0,0 +1,3 @@ + + + diff --git a/Tests/ttx/data/TestDFONT.dfont b/Tests/ttx/data/TestDFONT.dfont new file mode 100644 index 0000000000000000000000000000000000000000..a6ea7009be3ed3c1083254effaf54bc6fbfed685 GIT binary patch literal 3505 zcmeHJPiS0482`<@O?J24G@FRUKT91=Xj-tl$<{WI_8=r#DYP3+mUt=Dx7nB7*xh~0 zzL$_h4?-(QQRu19*R`_1A4GptU`~ zLH=p-TgE0*>0*E91wcGU{)wrIU28kIZ66>xTjZzad__6Qstn_8!t@J2y?284N6D8i$XN3P&i^52qA zl-(&Ck7Azlee&^&Jzql{cTunXsj6LZp2908-dhP66aV)uP;&asb=NL zU?mM(6b>ZeU``CyO?nydAyE~_(Z<G5hr%8l)zkPJse=$XJ@YhfTe zmL0`8bf~TJVxt`&SVzT!)G{V^m*rUw3PN1gkyCPj-Br^rVUQ8)y;-IuOk@X5j0x7o z!_>us$a%`F28E>B+Gr53(`6jtRtR{c%M~eAxuu}?7F|Jk1Z{Zr>`%`i`Tl-^4PUG?OFuqbq0&HrRCtx zJ9`F?99dkXif6*JWc4k^x9UoY_p!eObcN9-SoPYTeL_qwAIL*^(qO?8e%oNlC_XgU z!reT<<^hHf5ov?l&>I7&Qf@J95=mko}g$7R~6F*uBIal+sT zy5$`PM~Mdv-iVAGGdM>4uECoyXZ0D}jkt9l!*Ef<0_vDSk4yAMK3$(+qTU)5l6idF^Hnm-)`v-QZ{DR83 zRX^vtWiP3+t_t*?sym)jpK}VFmE&|T2r5UMp}_HcmCF&0Q&q$)nmINb-UnH?D}ElPOmtJwGwzEL4Tyx1?01!JPaYlUy+gfEUQ_TP?BZkGTIceLs=n+ zKgF1vW#w~hmK93AU-O1isp5=Zn$0Jt+)66%lnQnsHO+$Yb;0PX^>6c~cV6Zm^UQ%h zHC@^IlBBR7`*;;cd6_2ICn=w2TTdQR`Ldf&Rcz09>Z$$vhDWm#qe*|BlW(n}iM zX+Vu5`u$#m!juU}{_9!j!W(jUJmC4#Zs1$p8N77*OJ_5iewzjKORN73&B}oVmL5Bu zpzP-F5Xjf!80@9E5yP(>g8$I0w&V0%b6nM%b%S}JH%%V_8{X1kXo~;Nk5B44ez&u- z&aY>M|84%>4CwC$UL%tDlLXPZ>IK&8tVszzufm(I@_wN^GnO6UxMi@{d{vTZR%ldz Ky&}?jb$ + diff --git a/Tests/ttx/data/TestNoXML.ttx b/Tests/ttx/data/TestNoXML.ttx new file mode 100644 index 000000000..8dac50745 --- /dev/null +++ b/Tests/ttx/data/TestNoXML.ttx @@ -0,0 +1,2 @@ + + diff --git a/Tests/ttx/data/TestOTF.otf b/Tests/ttx/data/TestOTF.otf new file mode 100644 index 0000000000000000000000000000000000000000..cd0bdf67d24e99164a89a4bdd920496f346b5bff GIT binary patch literal 2308 zcmeHJUuauZ82_D{G=J8bc9m^)Zsq7k?a>YsOM`HJ>o?Wz~4X=}D2fIQeDDAvSB=%DWn?S1wyHKq8T zBR3R?VGcg^akLG0;ux;^`mQz{ z!%O(W*Y_gARS7@@qvV+9iZ`)9kEr@sLrkpsIDlbs#mB)mpAH-rw|#vG{o+R-hcU_J zX~vA8SDW;4v<-J6p=Eu2R~wFDNxL>?mzOIGxx6a}=T6As_|R#YS(XXAjQOGiw#i$~kGzw-MNho_F1{Gh!II1vkH#(dX=o+aTt+A0+o~978xwl%a=2 zg1#ksq$zC_;6SG~Ni5sOJ6_MC)uMKZZI*s%O2>ddXpxCXIBUDlh)VDx5gUCL%||C=ako&qCgIHP(R zwFYWk44lOTSAU%AH^o+`zRIdfz^_OAw|YjsP1GGh5U)^n@kG&x!P7)SmjjIkaeGfR z9yESxe0}epAHg%T35kzAcxRWsWmmFw{FiemPEdE5-}_VQMqqVXBuvqu!c ziw;7Fo?WM#(mhk}LH($x_iOe3K)o-xesLqdvC>hK-Ir_S-rDo~IaY)sFDLZUVxcfL z`S(dYGdMT%xMwlRiT8Mo2wq~#+*YFR@KO2PXnn0deQ;xC>-hFcczylAMt|+*c7Hf_ zF;@G)`(L + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Copyright (c) 2015 by FontTools. No rights reserved. + + + Test OTF + + + Regular + + + FontTools: Test OTF: 2015 + + + Test OTF + + + Version 1.000 + + + TestOTF-Regular + + + Test OTF is not a trademark of FontTools. + + + FontTools + + + FontTools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools/blob/master/LICENSE.txt + + + Test TTF + + + Copyright (c) 2015 by FontTools. No rights reserved. + + + Test OTF + + + Regular + + + FontTools: Test OTF: 2015 + + + Test OTF + + + Version 1.000 + + + TestOTF-Regular + + + Test OTF is not a trademark of FontTools. + + + FontTools + + + FontTools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools/blob/master/LICENSE.txt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 131 122 -131 hlineto + return + + + + + + 500 450 hmoveto + 750 -400 -750 vlineto + 50 50 rmoveto + 650 300 -650 vlineto + endchar + + + 0 endchar + + + 250 endchar + + + 723 55 hmoveto + -107 callsubr + 241 -122 rmoveto + -107 callsubr + 241 -122 rmoveto + -107 callsubr + endchar + + + 241 55 hmoveto + -107 callsubr + endchar + + + 250 endchar + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttx/data/TestTTC.ttc b/Tests/ttx/data/TestTTC.ttc new file mode 100644 index 0000000000000000000000000000000000000000..a21fe89dc4c4b44093e403aedc8034d88d5c5003 GIT binary patch literal 2608 zcmeHJPiS0482@JW-%GP*n_xw4DPvR96zqGOtu+vf2x+1zWedsDQ_;TNefx**?t8p9 z37eb>%|VJtPM(UW;6(*J=tX-d;z5KS#30xrEqd`FkwOY3kgmU(osCPXsNhY%WoCZg z-}&a7?+q(usX~ktag0Za*j~+N=n};!IJGeM66CPpX{^@S1t(V>&D;kMTe?tcx&fOw zbPK$M*;Z*u3dlk6028kS)uv`C4n47|8wF(1e(2la)78du<={Mf7W^vsTFrCIR{PY) z;C})CoDw7p><&@lF!;l@rfjD^q_@Gp4F2(kUvlXcIs^U!_@SoT4k$y9fmi#BmfQ3` z|Hyg){2F2w13!}C(_h{p8rXz>G6+3o2io%tCZsLrvu#2vCh5DPo3{>-!>7n8dH+JrQz4R}QqFH*XHBsIw78_eifPEfq+k!;1gSYunx_)(C4s=>eYTqvQ6a) z+A`xVO~P8m-DiG>2(O&>OzQ4Vo1TZzQ1=_y&ra{e?|CRc3;x}GIjVHh;21qY(+0=; zY!di#&Kr3WHLe?+qNCI{*uoj#F?gU457H>TZ{+DdJVeja4I>}Xdm-ca0J5(!OPvOo z(Owo9%xQ?JmsH7Plw)rg9PhJ9(39-CktgXOyJ>KW=GlFNEgIpc4Ib#jgEY(a%Ypdm zK0HKA{M~6kSPtveniS)uqav4`I3bG5V%BfTg6}sXTjYJA^^pj@$P1UevR&{ZDGG(z zd9S+IaKjzrDbdqR=}70iFsl14F=1!3S*3!{G2_&;6!l27d?{QZL$~ZT-SDFDD}4#< zM6XF1L{pAat;^bC(JuK-r|8wnZrQ0ITdA`B8zxS%;TN5z8%Zy8&dg2E=Xh-^snz@pDT(wqma2k8># zGVBUiBOSc}JWKQ7tF(wHF03AoJcTH`eUz-1(>WbILe?rLfjn(wtA0JN?mowM?bOq% z=qe9^2rA)K2CkN5HwUt=Awf%RZsC^oUSj3L%H0lo2y*T(+G>6-t!Tl{@wjpn0sJBp4 g=Tq}$b=lwNB%T}2V)){Q>4SvbT5L4<^t{&p28YOce*gdg literal 0 HcmV?d00001 diff --git a/Tests/ttx/data/TestTTF.ttf b/Tests/ttx/data/TestTTF.ttf new file mode 100644 index 0000000000000000000000000000000000000000..e906d012d1b62d6dd9019d1c7513e369a1ea4d06 GIT binary patch literal 2336 zcmeHJPly{;82{dzY%+1-CMG;I?DuetShD3bOIW>&X+mvlOScqz!KdTXV2sK}lmis_IW4cn^f{ZsD)|Bn8o zRK!c{CYHj79&NOPe&Stv9r8Dj_qUviMbFb2$Cl(;@bq!U-y}I|}PG%}*r+z)ti=5V(HMH0#Zv(JdPlr)`$)M%AjC zHLwjN+kfCjfVKcEBJ2H7vSGEM?P09KuY}nTqnCj5RD@ioE}~fQ+8a5C zD7)84-H6kW18n6pS~bjbY*(g{RYsRQ1R_Yr9mJ7)x6lJHvcTG=cF67m zbPm-p?&WFxg-)JgfK&A;M<$*+as)WrF3!=w**b`80^874!%QZk56?EhJUrX~CW_3{ zLc}sM%H7C!Am59Le*#N*`-^yg%NPyl`{+BrF@q1)Zy;2EYH@sYIMZ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SVTCA[0] /* SetFPVectorToAxis */ + + + + + + SVTCA[0] /* SetFPVectorToAxis */ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SVTCA[0] /* SetFPVectorToAxis */ + SVTCA[1] /* SetFPVectorToAxis */ + + + + + + + + + + + + + SVTCA[0] /* SetFPVectorToAxis */ + SVTCA[1] /* SetFPVectorToAxis */ + + + + + + + + + + + + SVTCA[0] /* SetFPVectorToAxis */ + SVTCA[1] /* SetFPVectorToAxis */ + + + + + + + + + + Copyright (c) 2015 by FontTools. No rights reserved. + + + Test TTF + + + Regular + + + FontTools: Test TTF: 2015 + + + Test TTF + + + Version 1.000 + + + TestTTF-Regular + + + Test TTF is not a trademark of FontTools. + + + FontTools + + + FontTools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools/blob/master/LICENSE.txt + + + Test TTF + + + Copyright (c) 2015 by FontTools. No rights reserved. + + + Test TTF + + + Regular + + + FontTools: Test TTF: 2015 + + + Test TTF + + + Version 1.000 + + + TestTTF-Regular + + + Test TTF is not a trademark of FontTools. + + + FontTools + + + FontTools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools + + + https://github.com/behdad/fonttools/blob/master/LICENSE.txt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttx/data/TestWOFF.woff b/Tests/ttx/data/TestWOFF.woff new file mode 100644 index 0000000000000000000000000000000000000000..64cd78dc86433fa450098f671dc2e012b06d7d70 GIT binary patch literal 1328 zcmZXUdr;C@6vr>9pp*iWCAOMcYA}kRmgS~lp*XrFmG~$veuwFP9~ zD*Q|uKQ#vcD+ScMU~CrUzw+7s^i(d??;$}JY=v6q{m=>HzEHbEJTV;9=ze~_5S~GR znq&cc8PxMrg>XOA7N{|wz-$9qsr+>4YX$(l4Bj*I$BJS@PPQN)&Rt;65{SF`1_=06 zAFMHEPs~>-_>d34%E|y^;Bhr^on;(Y5IVptfUZT4Lum)l7B2w8+BAfVAX%nDNoncp z05MTa?03P`+u{%_kbT}d7=Ue`Zez(y9YbmriXMfct*oWIw6p=cIq+pVeecYDrCP1k zs8nj5vik{eWrrQ zCd20B_6A=w^MTkA)pN zSA#1p84h0RktCtugcT0mjg=|Cgg%VFwtKQ}n^QIMFHxieoy)ji=|_yCo$2I^zsmPH zP(*&QNS7I4leQxAQD^V)Kgr|THY3G=#D`osE@jQFDIg|L{e1*0oMTDm^JrRH6Yf;p z+Rh16Q!O*_7S}a&F#hq->TfiadERy7Nlx>1yDRoaAB*Cx;~AUsHfH5^^&6+=#!b_t z6s8%a{aUB|{3a2ESAsZWSQx@#)H{;0co_!kuI*AN71rE9`a}SkZlE;JoAL2wqy7u# zS@Wd%z_gLMwFDKU`4*XVJheUmQBlN;YbLv8gme`-%;qvM_~E@i@67{ZbCPof=_&xe zD%2axAK)UXT!hPYw2h+rP2zL=?W4ESv{AljDP@6x%y{(9Fps@1bD6^1Ro{8Ruonf% zLh^V?0&)OQP84eXmn>_U%hs$l9nqt)3#=3ZQKF{6Le!1UlqabwPr)&$bui*&|6 kM@*t}d9D?>v}Vg4fO>EF`Os#+FbUS7`+=n|z>WdHf3c(!EdT%j literal 0 HcmV?d00001 diff --git a/Tests/ttx/data/TestWOFF2.woff2 b/Tests/ttx/data/TestWOFF2.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..a345573f7f4431265b3079d84394a8a0416239d2 GIT binary patch literal 808 zcmV+@1K0d_Pew8T0RR9100Srh4gdfE00|5L00P(m0RR9100000000000000000000 z00006U;u-92m%QK5ey1!cL6p6Bm)==4gdro1&Cq?Hw*zA3kVTaoae~CI54)gq`j-0 zl;Z_|q9F1SZY0I9h0pQu-+s@2pSkl4Rf{I8LnCQYO(Z-LvPMx&_!oTv&|jaiwer9I zdsDVJrYR%Z6wy`QwD)_(uyAd#aeklYa(X5o=s@oI9l{)qvGsaBhj8HGm>N(a2AZ|S z@{j}ehHV4XWzUG%5%oMkjy-WiiF7XQ!vW?9@xlmyS5s4aQosneu-{< z(wBPKW9n<3r$)SaR2|?r4giK z=?iKS2#Ov5-7KCyWmQQdg#ZABK*v}h0HY8fRE-iK zshA`{p}m;`WNVZ(wi;zktwlwD8&Oqry0<2wp`OlC8=;AbZs;wdSyqT#!HXFF#beUi?pD(2GP)*w3^yzs)_aK%-cmHINOFB{&5pM z`HxTbeNd;VwB0G!0~}ZCVQ)6sW?%`1`Z5r)eO4I=DJ97wv+qK3l!sj5ore6lEH~$> zCUjY-yWp-PW=>~QP^64c4s&BblVI~IGPxUr(sz2uk}TDA>CIhcUC z!vh^z5$&sh4+5`xRqXfGmy35oY0iy7sfQmQ&wE`0C6i!{QjwCvgCr<<;Di m!Go^s3%)(CHXpwm!8dLK^@rS!GLfQCX#QWi>q(}$`e^|6scR(w literal 0 HcmV?d00001 diff --git a/Tests/ttx/ttx_test.py b/Tests/ttx/ttx_test.py new file mode 100644 index 000000000..97287d7ff --- /dev/null +++ b/Tests/ttx/ttx_test.py @@ -0,0 +1,202 @@ +from __future__ import print_function, division, absolute_import +from fontTools.misc.py23 import * +from fontTools import ttx +import getopt +import os +import shutil +import sys +import tempfile +import unittest + +try: + import xattr +except ImportError: + xattr = None +try: + import MacOS +except ImportError: + MacOS = None + + +class TTXTest(unittest.TestCase): + def __init__(self, methodName): + unittest.TestCase.__init__(self, methodName) + # Python 3 renamed assertRaisesRegexp to assertRaisesRegex, + # and fires deprecation warnings if a program uses the old name. + if not hasattr(self, "assertRaisesRegex"): + self.assertRaisesRegex = self.assertRaisesRegexp + + def setUp(self): + self.tempdir = None + self.num_tempfiles = 0 + + def tearDown(self): + if self.tempdir: + shutil.rmtree(self.tempdir) + + @staticmethod + def getpath(testfile): + path, _ = os.path.split(__file__) + return os.path.join(path, "data", testfile) + + def temp_dir(self): + if not self.tempdir: + self.tempdir = tempfile.mkdtemp() + + def temp_font(self, font_path, file_name): + self.temp_dir() + temppath = os.path.join(self.tempdir, file_name) + shutil.copy2(font_path, temppath) + return temppath + +# ----- +# Tests +# ----- + + def test_parseOptions_no_args(self): + with self.assertRaises(getopt.GetoptError) as cm: + ttx.parseOptions([]) + self.assertTrue('Must specify at least one input file' in str(cm.exception)) + + def test_parseOptions_invalid_path(self): + file_path = 'invalid_font_path' + with self.assertRaises(getopt.GetoptError) as cm: + ttx.parseOptions([file_path]) + self.assertTrue('File not found: "%s"' % file_path in str(cm.exception)) + + def test_parseOptions_font2ttx_1st_time(self): + file_name = 'TestOTF.otf' + font_path = self.getpath(file_name) + temp_path = self.temp_font(font_path, file_name) + jobs, _ = ttx.parseOptions([temp_path]) + self.assertEqual(jobs[0][0].__name__, 'ttDump') + self.assertEqual(jobs[0][1:], + (os.path.join(self.tempdir, file_name), + os.path.join(self.tempdir, file_name.split('.')[0] + '.ttx'))) + + def test_parseOptions_font2ttx_2nd_time(self): + file_name = 'TestTTF.ttf' + font_path = self.getpath(file_name) + temp_path = self.temp_font(font_path, file_name) + _, _ = ttx.parseOptions([temp_path]) # this is NOT a mistake + jobs, _ = ttx.parseOptions([temp_path]) + self.assertEqual(jobs[0][0].__name__, 'ttDump') + self.assertEqual(jobs[0][1:], + (os.path.join(self.tempdir, file_name), + os.path.join(self.tempdir, file_name.split('.')[0] + '#1.ttx'))) + + def test_parseOptions_ttx2font_1st_time(self): + file_name = 'TestTTF.ttx' + font_path = self.getpath(file_name) + temp_path = self.temp_font(font_path, file_name) + jobs, _ = ttx.parseOptions([temp_path]) + self.assertEqual(jobs[0][0].__name__, 'ttCompile') + self.assertEqual(jobs[0][1:], + (os.path.join(self.tempdir, file_name), + os.path.join(self.tempdir, file_name.split('.')[0] + '.ttf'))) + + def test_parseOptions_ttx2font_2nd_time(self): + file_name = 'TestOTF.ttx' + font_path = self.getpath(file_name) + temp_path = self.temp_font(font_path, file_name) + _, _ = ttx.parseOptions([temp_path]) # this is NOT a mistake + jobs, _ = ttx.parseOptions([temp_path]) + self.assertEqual(jobs[0][0].__name__, 'ttCompile') + self.assertEqual(jobs[0][1:], + (os.path.join(self.tempdir, file_name), + os.path.join(self.tempdir, file_name.split('.')[0] + '#1.otf'))) + + def test_parseOptions_multiple_fonts(self): + file_names = ['TestOTF.otf', 'TestTTF.ttf'] + font_paths = [self.getpath(file_name) for file_name in file_names] + temp_paths = [self.temp_font(font_path, file_name) \ + for font_path, file_name in zip(font_paths, file_names)] + jobs, _ = ttx.parseOptions(temp_paths) + for i in range(len(jobs)): + self.assertEqual(jobs[i][0].__name__, 'ttDump') + self.assertEqual(jobs[i][1:], + (os.path.join(self.tempdir, file_names[i]), + os.path.join(self.tempdir, file_names[i].split('.')[0] + '.ttx'))) + + def test_parseOptions_mixed_files(self): + operations = ['ttDump', 'ttCompile'] + extensions = ['.ttx', '.ttf'] + file_names = ['TestOTF.otf', 'TestTTF.ttx'] + font_paths = [self.getpath(file_name) for file_name in file_names] + temp_paths = [self.temp_font(font_path, file_name) \ + for font_path, file_name in zip(font_paths, file_names)] + jobs, _ = ttx.parseOptions(temp_paths) + for i in range(len(jobs)): + self.assertEqual(jobs[i][0].__name__, operations[i]) + self.assertEqual(jobs[i][1:], + (os.path.join(self.tempdir, file_names[i]), + os.path.join(self.tempdir, file_names[i].split('.')[0] + extensions[i]))) + + def test_guessFileType_ttf(self): + file_name = 'TestTTF.ttf' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTF') + + def test_guessFileType_otf(self): + file_name = 'TestOTF.otf' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'OTF') + + def test_guessFileType_woff(self): + file_name = 'TestWOFF.woff' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'WOFF') + + def test_guessFileType_woff2(self): + file_name = 'TestWOFF2.woff2' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'WOFF2') + + def test_guessFileType_ttc(self): + file_name = 'TestTTC.ttc' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTC') + + def test_guessFileType_dfont(self): + file_name = 'TestDFONT.dfont' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTF') + + @unittest.skipUnless(xattr or MacOS, "xattr or MacOS not installed") + def test_guessFileType_ffil(self): + file_name = 'TestFFIL' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTF') + + def test_guessFileType_ttx_ttf(self): + file_name = 'TestTTF.ttx' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTX') + + def test_guessFileType_ttx_otf(self): + file_name = 'TestOTF.ttx' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'OTX') + + def test_guessFileType_ttx_bom(self): + file_name = 'TestBOM.ttx' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTX') + + def test_guessFileType_ttx_no_sfntVersion(self): + file_name = 'TestNoSFNT.ttx' + font_path = self.getpath(file_name) + self.assertEqual(ttx.guessFileType(font_path), 'TTX') + + def test_guessFileType_ttx_no_xml(self): + file_name = 'TestNoXML.ttx' + font_path = self.getpath(file_name) + self.assertIsNone(ttx.guessFileType(font_path)) + + def test_guessFileType_invalid_path(self): + font_path = 'invalid_font_path' + self.assertIsNone(ttx.guessFileType(font_path)) + + +if __name__ == "__main__": + sys.exit(unittest.main())