Skip to content

Commit d18a0b9

Browse files
committed
update tests, and fix handling of output path
1 parent b316a75 commit d18a0b9

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

goadbWriter.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _get_args(args=None):
3939
)
4040

4141
parser.add_argument(
42-
'-o', '--output',
42+
'-o', '--output_path',
4343
action='store',
4444
help=(
4545
'output file or directory. '
@@ -563,7 +563,7 @@ def _make_goadb_content(glyph_order, glyph_name_dict):
563563
def make_goadb(input_ufo, include_template_glyphs=False):
564564
'''
565565
Make a GOADB from an input UFO.
566-
Optionally, template glyphs can be included.
566+
Optionally, include (un-filled) template glyphs.
567567
'''
568568
f = Font(input_ufo)
569569
glyph_order = get_glyph_order(f, include_template_glyphs)
@@ -576,12 +576,13 @@ def write_goadb(goadb_content, output_path=None):
576576
'''
577577
Write the GOADB to an output file or folder.
578578
'''
579-
if output_path and output_path.is_file():
580-
with open(output_path, 'w') as blob:
581-
blob.write(goadb_content + '\n')
582-
elif output_path and output_path.is_dir():
583-
with open(output_path / 'GlyphOrderAndAliasDB', 'w') as blob:
584-
blob.write(goadb_content + '\n')
579+
if output_path:
580+
if output_path.is_dir():
581+
with open(output_path / 'GlyphOrderAndAliasDB', 'w') as blob:
582+
blob.write(goadb_content + '\n')
583+
else:
584+
with open(output_path, 'w') as blob:
585+
blob.write(goadb_content + '\n')
585586
else:
586587
print(goadb_content)
587588

tests/test_goadbWriter.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
sys.path.append("..")
9-
from goadbWriter import *
9+
from goadbWriter import _get_args, main
1010

1111

1212
TEST_DIR = Path(__file__).parent
@@ -29,10 +29,10 @@ def read_file(path):
2929
def test_get_args():
3030
# args through argparse
3131
ufo_path = str(TEST_DIR / 'goadb_full.ufo')
32-
argparse_args = vars(get_args([ufo_path, '-o', 'goadb']))
32+
argparse_args = vars(_get_args([ufo_path, '-o', 'goadb']))
3333
expected_args = {
34-
'input_file': ufo_path,
35-
'output': 'goadb',
34+
'input_ufo': ufo_path,
35+
'output_path': Path('goadb'),
3636
'template': False,
3737
}
3838
assert argparse_args == expected_args
@@ -77,6 +77,18 @@ def test_default():
7777
assert read_file(goadb_temp) == read_file(goadb_example)
7878

7979

80+
def test_write_to_dir():
81+
'''
82+
writing GOADB to directory (name is auto-generated)
83+
'''
84+
ufo_path = str(TEST_DIR / 'goadb_full.ufo')
85+
goadb_example = TEST_DIR / 'goadb_full'
86+
args = [ufo_path, '-o', str(TEMP_DIR)]
87+
main(args)
88+
goadb_temp = str(TEMP_DIR / 'GlyphOrderAndAliasDB')
89+
assert read_file(goadb_temp) == read_file(goadb_example)
90+
91+
8092
def test_template():
8193
'''
8294
testing UFO with template glyphs only

0 commit comments

Comments
 (0)