From df42e9d1e42cfd21be2426059ab395daa2e9d2f4 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 24 Apr 2023 11:48:36 +0100 Subject: [PATCH] ttLib_main.py: test directly __main__.main(), coverage-py doesn't collect in subprocess --- Tests/ttLib/main_test.py | 62 +++++++++++++++------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/Tests/ttLib/main_test.py b/Tests/ttLib/main_test.py index 78b01cc33..d97f3c947 100644 --- a/Tests/ttLib/main_test.py +++ b/Tests/ttLib/main_test.py @@ -3,7 +3,7 @@ import sys import tempfile from pathlib import Path -from fontTools.ttLib import TTFont, TTCollection +from fontTools.ttLib import __main__, TTFont, TTCollection import pytest @@ -42,42 +42,41 @@ def flavor(request): return request.param +def test_ttLib_main_as_subprocess(ttfont_path): + subprocess.run( + [sys.executable, "-m", "fontTools.ttLib", str(ttfont_path)], check=True + ) + + def test_ttLib_open_ttfont(ttfont_path): - subprocess.check_call([sys.executable, "-m", "fontTools.ttLib", ttfont_path]) + __main__.main([str(ttfont_path)]) def test_ttLib_open_save_ttfont(tmp_path, ttfont_path, flavor): output_path = tmp_path / "TestTTF-Regular.ttf" - args = [sys.executable, "-m", "fontTools.ttLib", "-o", output_path, ttfont_path] + args = ["-o", str(output_path), str(ttfont_path)] if flavor is not None: args.extend(["--flavor", flavor]) - subprocess.check_call(args) + + __main__.main(args) + assert output_path.exists() assert TTFont(output_path).getGlyphOrder() == TTFont(ttfont_path).getGlyphOrder() def test_ttLib_open_ttcollection(ttcollection_path): - subprocess.check_call( - [sys.executable, "-m", "fontTools.ttLib", "-y", "0", ttcollection_path] - ) + __main__.main(["-y", "0", str(ttcollection_path)]) def test_ttLib_open_ttcollection_save_single_font(tmp_path, ttcollection_path, flavor): for i in range(2): output_path = tmp_path / f"TestTTF-Regular#{i}.ttf" - args = [ - sys.executable, - "-m", - "fontTools.ttLib", - "-y", - str(i), - "-o", - output_path, - ttcollection_path, - ] + args = ["-y", str(i), "-o", str(output_path), str(ttcollection_path)] if flavor is not None: args.extend(["--flavor", flavor]) - subprocess.check_call(args) + + __main__.main(args) + assert output_path.exists() assert ( TTFont(output_path).getGlyphOrder() @@ -87,33 +86,18 @@ def test_ttLib_open_ttcollection_save_single_font(tmp_path, ttcollection_path, f def test_ttLib_open_ttcollection_save_ttcollection(tmp_path, ttcollection_path): output_path = tmp_path / "TestTTF.ttc" - subprocess.check_call( - [ - sys.executable, - "-m", - "fontTools.ttLib", - "-o", - output_path, - ttcollection_path, - ] - ) + + __main__.main(["-o", str(output_path), str(ttcollection_path)]) + assert output_path.exists() assert len(TTCollection(output_path)) == len(TTCollection(ttcollection_path)) def test_ttLib_open_multiple_fonts_save_ttcollection(tmp_path, ttfont_path): output_path = tmp_path / "TestTTF.ttc" - subprocess.check_call( - [ - sys.executable, - "-m", - "fontTools.ttLib", - "-o", - output_path, - ttfont_path, - ttfont_path, - ] - ) + + __main__.main(["-o", str(output_path), str(ttfont_path), str(ttfont_path)]) + assert output_path.exists() coll = TTCollection(output_path)