Skip to content

Commit 1c4419b

Browse files
committed
changed path parsing approach, updated tests for Windows path support
1 parent b40a386 commit 1c4419b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/fontline/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ def modify_linegap_percent(fontpath, percent):
112112

113113

114114
def get_linegap_percent_filepath(fontpath, percent):
115-
font_basename = os.path.basename(fontpath)
116-
font_dirname = os.path.dirname(fontpath)
115+
fontpath_list = os.path.split(fontpath)
116+
font_dirname = fontpath_list[0]
117+
font_basename = fontpath_list[1]
117118
basepath_list = font_basename.split(".")
118119
outfile_basename = basepath_list[0] + "-linegap" + percent + "." + basepath_list[1]
119120
return os.path.join(font_dirname, outfile_basename)

tests/test_filepaths.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
import os
45
import sys
56
import pytest
67

@@ -12,23 +13,35 @@
1213
test_filepath_four = "~/dir1/dir2/test.ttf"
1314
percent_value = "10"
1415

16+
expected_linegap_basename = "test-linegap" + percent_value + ".ttf"
17+
18+
expected_testpath_list_one = os.path.split(test_filepath_one)
19+
expected_testpath_list_two = os.path.split(test_filepath_two)
20+
expected_testpath_list_three = os.path.split(test_filepath_three)
21+
expected_testpath_list_four = os.path.split(test_filepath_four)
22+
23+
expected_testpath_one = os.path.join(expected_testpath_list_one[0], expected_linegap_basename)
24+
expected_testpath_two = os.path.join(expected_testpath_list_two[0], expected_linegap_basename)
25+
expected_testpath_three = os.path.join(expected_testpath_list_three[0], expected_linegap_basename)
26+
expected_testpath_four = os.path.join(expected_testpath_list_four[0], expected_linegap_basename)
27+
1528

1629
def test_linegap_outfile_filepath_basename():
1730
response = get_linegap_percent_filepath(test_filepath_one, percent_value)
18-
assert response == "test-linegap10.ttf"
31+
assert response == expected_testpath_one
1932

2033

2134
def test_linegap_outfile_filepath_samedir_withdotsyntax():
2235
response = get_linegap_percent_filepath(test_filepath_two, percent_value)
23-
assert response == "./test-linegap10.ttf"
36+
assert response == expected_testpath_two
2437

2538

2639
def test_linegap_outfile_filepath_differentdir_fromroot():
2740
response = get_linegap_percent_filepath(test_filepath_three, percent_value)
28-
assert response == "/dir1/dir2/test-linegap10.ttf"
41+
assert response == expected_testpath_three
2942

3043

3144
def test_linegap_outfile_filepath_differentdir_fromuser():
3245
response = get_linegap_percent_filepath(test_filepath_four, percent_value)
33-
assert response == "~/dir1/dir2/test-linegap10.ttf"
46+
assert response == expected_testpath_four
3447

0 commit comments

Comments
 (0)