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