1*e1fe3e4aSElliott Hughesimport os 2*e1fe3e4aSElliott Hughes 3*e1fe3e4aSElliott Hughesimport pytest 4*e1fe3e4aSElliott Hughesimport py 5*e1fe3e4aSElliott Hughes 6*e1fe3e4aSElliott Hughesfrom fontTools.qu2cu.cli import main 7*e1fe3e4aSElliott Hughesfrom fontTools.ttLib import TTFont 8*e1fe3e4aSElliott Hughes 9*e1fe3e4aSElliott Hughes 10*e1fe3e4aSElliott HughesDATADIR = os.path.join(os.path.dirname(__file__), "data") 11*e1fe3e4aSElliott Hughes 12*e1fe3e4aSElliott HughesTEST_TTFS = [ 13*e1fe3e4aSElliott Hughes py.path.local(DATADIR).join("NotoSansArabic-Regular.quadratic.subset.ttf"), 14*e1fe3e4aSElliott Hughes] 15*e1fe3e4aSElliott Hughes 16*e1fe3e4aSElliott Hughes 17*e1fe3e4aSElliott Hughes@pytest.fixture 18*e1fe3e4aSElliott Hughesdef test_paths(tmpdir): 19*e1fe3e4aSElliott Hughes result = [] 20*e1fe3e4aSElliott Hughes for path in TEST_TTFS: 21*e1fe3e4aSElliott Hughes new_path = tmpdir / path.basename 22*e1fe3e4aSElliott Hughes path.copy(new_path) 23*e1fe3e4aSElliott Hughes result.append(new_path) 24*e1fe3e4aSElliott Hughes return result 25*e1fe3e4aSElliott Hughes 26*e1fe3e4aSElliott Hughes 27*e1fe3e4aSElliott Hughesclass MainTest(object): 28*e1fe3e4aSElliott Hughes @staticmethod 29*e1fe3e4aSElliott Hughes def run_main(*args): 30*e1fe3e4aSElliott Hughes main([str(p) for p in args if p]) 31*e1fe3e4aSElliott Hughes 32*e1fe3e4aSElliott Hughes def test_no_output(self, test_paths): 33*e1fe3e4aSElliott Hughes ttf_path = test_paths[0] 34*e1fe3e4aSElliott Hughes 35*e1fe3e4aSElliott Hughes self.run_main(ttf_path) 36*e1fe3e4aSElliott Hughes 37*e1fe3e4aSElliott Hughes output_path = str(ttf_path).replace(".ttf", ".cubic.ttf") 38*e1fe3e4aSElliott Hughes font = TTFont(output_path) 39*e1fe3e4aSElliott Hughes assert font["head"].glyphDataFormat == 1 40*e1fe3e4aSElliott Hughes assert os.stat(ttf_path).st_size > os.stat(output_path).st_size 41*e1fe3e4aSElliott Hughes 42*e1fe3e4aSElliott Hughes def test_output_file(self, test_paths): 43*e1fe3e4aSElliott Hughes ttf_path = test_paths[0] 44*e1fe3e4aSElliott Hughes output_path = str(ttf_path) + ".cubic" 45*e1fe3e4aSElliott Hughes 46*e1fe3e4aSElliott Hughes self.run_main(ttf_path, "-o", output_path) 47*e1fe3e4aSElliott Hughes 48*e1fe3e4aSElliott Hughes font = TTFont(output_path) 49*e1fe3e4aSElliott Hughes assert font["head"].glyphDataFormat == 1 50*e1fe3e4aSElliott Hughes 51*e1fe3e4aSElliott Hughes def test_stats(self, test_paths): 52*e1fe3e4aSElliott Hughes ttf_path = test_paths[0] 53*e1fe3e4aSElliott Hughes self.run_main(ttf_path, "--verbose") 54*e1fe3e4aSElliott Hughes 55*e1fe3e4aSElliott Hughes def test_all_cubic(self, test_paths): 56*e1fe3e4aSElliott Hughes ttf_path = test_paths[0] 57*e1fe3e4aSElliott Hughes 58*e1fe3e4aSElliott Hughes self.run_main(ttf_path, "-c") 59*e1fe3e4aSElliott Hughes 60*e1fe3e4aSElliott Hughes output_path = str(ttf_path).replace(".ttf", ".cubic.ttf") 61*e1fe3e4aSElliott Hughes font = TTFont(output_path) 62*e1fe3e4aSElliott Hughes assert font["head"].glyphDataFormat == 1 63