Skip to content

Commit 3fe0720

Browse files
committed
[fdiff.utils] add get_tables_argument_list function
parses command line table request into list of table values
1 parent 2faa5d8 commit 3fe0720

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

lib/fdiff/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from datetime import datetime, timezone
44

55

6+
def file_exists(path):
7+
"""Validates file path as existing local file"""
8+
return os.path.isfile(path)
9+
10+
611
def get_file_modtime(path):
712
"""Returns ISO formatted file modification time in local system timezone"""
813
return (
@@ -12,6 +17,14 @@ def get_file_modtime(path):
1217
)
1318

1419

15-
def file_exists(path):
16-
"""Validates file path as existing local file"""
17-
return os.path.isfile(path)
20+
def get_tables_argument_list(table_string):
21+
"""Converts a comma separated OpenType table string into a Python list or return None if
22+
the table_string was not defined (i.e., it was not included in an option on the command line).
23+
Tables that are composed of three characters must be right padded with a space."""
24+
if table_string is None:
25+
return None
26+
else:
27+
return [
28+
table + " " if len(table) == 3 else table
29+
for table in table_string.split(",")
30+
]

tests/test_utils.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import os
22
import re
33

4-
from fdiff.utils import get_file_modtime, file_exists
4+
from fdiff.utils import get_file_modtime, get_tables_argument_list, file_exists
55

66
import pytest
77

88

9+
def test_file_exists_true():
10+
assert file_exists(os.path.join("tests", "testfiles", "test.txt")) is True
11+
12+
13+
def test_file_exists_false():
14+
assert file_exists(os.path.join("tests", "testfiles", "bogus.jpg")) is False
15+
16+
917
def test_get_file_modtime():
1018
modtime = get_file_modtime(os.path.join("tests", "testfiles", "test.txt"))
1119
assert modtime.startswith("2019-09-0") is True
1220
regex = re.compile(r"""\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[-+]\d{2}:\d{2}""")
1321
assert regex.fullmatch(modtime) is not None
1422

1523

16-
def test_file_exists_true():
17-
assert file_exists(os.path.join("tests", "testfiles", "test.txt")) is True
18-
19-
20-
def test_file_exists_false():
21-
assert file_exists(os.path.join("tests", "testfiles", "bogus.jpg")) is False
24+
def test_get_tables_argument_list():
25+
string1 = "head"
26+
string2 = "head,post"
27+
string3 = "head,post,cvt"
28+
assert get_tables_argument_list(string1) == ["head"]
29+
assert get_tables_argument_list(string2) == ["head", "post"]
30+
assert get_tables_argument_list(string3) == ["head", "post", "cvt "]

0 commit comments

Comments
 (0)