-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from importlib import resources | ||
from os import PathLike | ||
from typing import TypeAlias, Literal | ||
|
||
import yaml | ||
|
||
_data_dir = resources.files(__package__).joinpath('data') | ||
|
||
PresetName: TypeAlias = Literal[ | ||
'cjk_unified_to_kangxi_radicals', | ||
'cjk_unified_to_radicals_supplement', | ||
'inherited_glyphs', | ||
] | ||
|
||
|
||
def load_yaml( | ||
file_path: str | bytes | PathLike[str] | PathLike[bytes], | ||
) -> dict[int, list[int]]: | ||
with open(file_path, 'rb') as file: | ||
return yaml.safe_load(file) | ||
|
||
|
||
def load_preset(name: PresetName) -> dict[int, list[int]]: | ||
return yaml.safe_load(_data_dir.joinpath(f'{name}.yaml').read_bytes()) |
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,31 @@ | ||
import unidata_blocks | ||
|
||
from pixel_font_knife import character_fallback_util | ||
|
||
_block_cjk_unified = unidata_blocks.get_block_by_name('CJK Unified Ideographs') | ||
_block_kangxi_radicals = unidata_blocks.get_block_by_name('Kangxi Radicals') | ||
_block_radicals_supplement = unidata_blocks.get_block_by_name('CJK Radicals Supplement') | ||
|
||
|
||
def test_preset_cjk_unified_to_kangxi_radicals(): | ||
mapping = character_fallback_util.load_preset('cjk_unified_to_kangxi_radicals') | ||
for target, code_points in mapping.items(): | ||
assert target in _block_cjk_unified | ||
for code_point in code_points: | ||
assert code_point in _block_kangxi_radicals | ||
|
||
|
||
def test_preset_cjk_unified_to_radicals_supplement(): | ||
mapping = character_fallback_util.load_preset('cjk_unified_to_radicals_supplement') | ||
for target, code_points in mapping.items(): | ||
assert target in _block_cjk_unified | ||
for code_point in code_points: | ||
assert code_point in _block_radicals_supplement | ||
|
||
|
||
def test_preset_inherited_glyphs(): | ||
mapping = character_fallback_util.load_preset('inherited_glyphs') | ||
for target, code_points in mapping.items(): | ||
assert target in _block_cjk_unified | ||
for code_point in code_points: | ||
assert code_point in _block_cjk_unified |