Skip to content

Commit 3b1113e

Browse files
Merge pull request #64 from source-foundry/quiet-flag
Add new --quiet flag
2 parents 55e92be + dcda9a7 commit 3b1113e

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

lib/dehinter/__main__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def run(argv: List[str]) -> None:
6060
parser.add_argument(
6161
"--keep-head", help="do not modify head table", action="store_true"
6262
)
63+
parser.add_argument("--quiet", help="silence standard output", action="store_true")
6364
parser.add_argument("INFILE", help="in file path (hinted font)")
6465

6566
args = parser.parse_args(argv)
@@ -105,6 +106,8 @@ def run(argv: List[str]) -> None:
105106
)
106107
sys.exit(1)
107108

109+
use_verbose_output = not args.quiet
110+
108111
dehint(
109112
tt,
110113
keep_cvar=args.keep_cvar,
@@ -119,7 +122,7 @@ def run(argv: List[str]) -> None:
119122
keep_prep=args.keep_prep,
120123
keep_ttfa=args.keep_ttfa,
121124
keep_vdmx=args.keep_vdmx,
122-
verbose=True,
125+
verbose=use_verbose_output,
123126
)
124127

125128
# File write
@@ -134,18 +137,20 @@ def run(argv: List[str]) -> None:
134137

135138
try:
136139
tt.save(outpath)
137-
print(f"{os.linesep}[+] Saved dehinted font as '{outpath}'")
140+
if use_verbose_output:
141+
print(f"{os.linesep}[+] Saved dehinted font as '{outpath}'")
138142
except Exception as e: # pragma: no cover
139143
sys.stderr.write(
140144
f"[!] Error: Unable to save dehinted font file: {str(e)}{os.linesep}"
141145
)
142146

143147
# File size comparison
144148
# --------------------
145-
infile_size_tuple = get_filesize(args.INFILE)
146-
outfile_size_tuple = get_filesize(
147-
outpath
148-
) # depends on outpath definition defined during file write
149-
print(f"{os.linesep}[*] File sizes:")
150-
print(f" {infile_size_tuple[0]}{infile_size_tuple[1]} (hinted)")
151-
print(f" {outfile_size_tuple[0]}{outfile_size_tuple[1]} (dehinted)")
149+
if use_verbose_output:
150+
infile_size_tuple = get_filesize(args.INFILE)
151+
outfile_size_tuple = get_filesize(
152+
outpath
153+
) # depends on outpath definition defined during file write
154+
print(f"{os.linesep}[*] File sizes:")
155+
print(f" {infile_size_tuple[0]}{infile_size_tuple[1]} (hinted)")
156+
print(f" {outfile_size_tuple[0]}{outfile_size_tuple[1]} (dehinted)")

tests/test_main.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def font_validator(filepath):
3939
assert (tt["head"].flags & 1 << 4) == 0
4040

4141

42-
def test_default_run_roboto():
42+
def test_default_run_roboto(capsys):
4343
test_dir = os.path.join("tests", "test_files", "fonts", "temp")
4444
notouch_inpath = os.path.join("tests", "test_files", "fonts", "Roboto-Regular.ttf")
4545
test_inpath = os.path.join(
@@ -58,6 +58,8 @@ def test_default_run_roboto():
5858

5959
# execute
6060
run(test_args)
61+
captured = capsys.readouterr()
62+
assert "Saved dehinted font as" in captured.out
6163

6264
# test
6365
font_validator(test_outpath)
@@ -544,6 +546,35 @@ def test_run_with_outfile_path_noto():
544546
shutil.rmtree(test_dir)
545547

546548

549+
def test_default_run_roboto_quiet_flag_stdout_test(capsys):
550+
test_dir = os.path.join("tests", "test_files", "fonts", "temp")
551+
notouch_inpath = os.path.join("tests", "test_files", "fonts", "Roboto-Regular.ttf")
552+
test_inpath = os.path.join(
553+
"tests", "test_files", "fonts", "temp", "Roboto-Regular.ttf"
554+
)
555+
test_outpath = os.path.join(
556+
"tests", "test_files", "fonts", "temp", "Roboto-Regular-dehinted.ttf"
557+
)
558+
test_args = ["--quiet", test_inpath]
559+
560+
# setup
561+
if os.path.isdir(test_dir):
562+
shutil.rmtree(test_dir)
563+
os.mkdir(test_dir)
564+
shutil.copyfile(notouch_inpath, test_inpath)
565+
566+
# execute
567+
run(test_args)
568+
captured = capsys.readouterr()
569+
assert captured.out == ""
570+
571+
# test
572+
font_validator(test_outpath)
573+
574+
# tear down
575+
shutil.rmtree(test_dir)
576+
577+
547578
#
548579
# Validation error testing
549580
#

0 commit comments

Comments
 (0)