-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
is_file
optional argument to calc_output_path
Also: * Use it in the `Builder`. * Move `calc_output_path` to `utils.py`. * Add type annotations.
- Loading branch information
Showing
9 changed files
with
110 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import pathlib | ||
|
||
from east_asian_spacing import calc_output_path | ||
|
||
|
||
def test_calc_output_path(): | ||
|
||
def call(input_path, output_path, stem_suffix=None): | ||
input_path = pathlib.Path(input_path) | ||
if output_path: | ||
output_path = pathlib.Path(output_path) | ||
result = calc_output_path(input_path, output_path, stem_suffix) | ||
return str(result) | ||
|
||
assert call('c.otf', None) == 'c.otf' | ||
assert call('a/b/c.otf', None) == os.path.join('a', 'b', 'c.otf') | ||
|
||
assert call('c.otf', None, '-chws') == 'c-chws.otf' | ||
assert call('a/b/c.otf', None, | ||
'-chws') == os.path.join('a', 'b', 'c-chws.otf') | ||
|
||
assert call('c.otf', 'build') == os.path.join('build', 'c.otf') | ||
assert call('a/b/c.otf', 'build') == os.path.join('build', 'c.otf') | ||
|
||
assert call('a/b/c.otf', 'build', | ||
'-xyz') == os.path.join('build', 'c-xyz.otf') | ||
|
||
|
||
def test_calc_output_path_dir(tmp_path: pathlib.Path): | ||
name = 'name' | ||
input = pathlib.Path('in') / name | ||
|
||
# `output` should be a directory if it's an existing directory. | ||
output = tmp_path / 'dir' | ||
output.mkdir() | ||
result = calc_output_path(input, output) | ||
assert result == output / name | ||
|
||
# `output` should be a file if it's an existing file. | ||
output = tmp_path / 'file' | ||
output.write_text('test') | ||
result = calc_output_path(input, output) | ||
assert result == output | ||
|
||
# `output` should be a directory if it does not exist. | ||
output = tmp_path / 'new_dir' | ||
result = calc_output_path(input, output) | ||
assert result == output / name | ||
assert output.is_dir() | ||
|
||
# `output` should be a file if it does not exist and `is_file=True`. | ||
output = tmp_path / 'new_file' | ||
result = calc_output_path(input, output, is_file=True) | ||
assert result == output | ||
assert not output.exists() |