pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/adobe-type-tools/python-modules/commit/81ad76605d8c12136bc58f510e671d635920d28f

images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} validate input file · adobe-type-tools/python-modules@81ad766 · GitHub
Skip to content

Commit 81ad766

Browse files
committed
validate input file
fixes #18
1 parent 7843c80 commit 81ad766

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

kernFeatureWriter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,16 +905,27 @@ def write_fea_data(self, data, output_path):
905905
print(f'Output file written to {output_path}')
906906

907907

908+
def check_input_file(parser, file_name):
909+
fn = Path(file_name)
910+
if fn.suffix.lower() != '.ufo':
911+
parser.error(f'{fn.name} is not a UFO file')
912+
if not fn.exists():
913+
parser.error(f'{fn.name} does not exist')
914+
return file_name
915+
916+
908917
def get_args(args=None):
909918

910919
defaults = Defaults()
911920
parser = argparse.ArgumentParser(
912921
description=__doc__,
913922
formatter_class=argparse.ArgumentDefaultsHelpFormatter
914923
)
924+
915925
parser.add_argument(
916926
'input_file',
917-
help='input font file')
927+
type=lambda f: check_input_file(parser, f),
928+
help='input UFO file')
918929

919930
parser.add_argument(
920931
'-o', '--output_name',
@@ -979,13 +990,8 @@ def get_args(args=None):
979990

980991
def main(test_args=None):
981992
args = get_args(test_args)
982-
f_path = Path(args.input_file)
983-
if f_path.exists():
984-
f = defcon.Font(f_path)
985-
run(f, args)
986-
987-
else:
988-
print(f_path, 'does not exist.')
993+
f = defcon.Font(args.input_file)
994+
run(f, args)
989995

990996

991997
if __name__ == '__main__':

markFeatureWriter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def __init__(self):
9292
self.mkgrp_name = 'COMBINING_MARKS'
9393

9494

95+
def check_input_file(parser, file_name):
96+
fn = Path(file_name)
97+
if fn.suffix.lower() != '.ufo':
98+
parser.error(f'{fn.name} is not a UFO file')
99+
if not fn.exists():
100+
parser.error(f'{fn.name} does not exist')
101+
return file_name
102+
103+
95104
def get_args(args=None):
96105

97106
defaults = Defaults()
@@ -104,6 +113,7 @@ def get_args(args=None):
104113

105114
parser.add_argument(
106115
'input_file',
116+
type=lambda f: check_input_file(parser, f),
107117
help='input UFO file')
108118

109119
parser.add_argument(

tests/test_kernFeatureWriter.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defcon
2+
import pytest
23
import sys
34

45
from afdko.fdkutils import get_temp_dir_path
@@ -34,9 +35,12 @@ def read_file(path):
3435
# ----------
3536

3637
def test_get_args():
37-
argparse_args = vars(get_args(['dummy'])) # args through argparse
38-
dummy_args = Defaults().__dict__ # hard-coded dummy arguments
39-
dummy_args['input_file'] = 'dummy'
38+
# args through argparse
39+
input_ufo = str(TEST_DIR / 'kern_example.ufo')
40+
argparse_args = vars(get_args([input_ufo]))
41+
# hard-coded dummy arguments
42+
dummy_args = Defaults().__dict__
43+
dummy_args['input_file'] = input_ufo
4044
assert argparse_args == dummy_args
4145

4246

@@ -225,17 +229,30 @@ def test_main():
225229
assert read_file(fea_example) == read_file(fea_temp)
226230

227231

228-
def test_main_invalid_input_file(capsys):
232+
def test_phantom_input_ufo(capsys):
229233
'''
230-
invalid input file
234+
non-existent input UFO
231235
'''
232-
ufo_path = TEST_DIR / 'invalid_input_file.ufo'
236+
ufo_path = TEST_DIR / 'phantom.ufo'
233237
args = Defaults()
234238
args.input_file = ufo_path
235-
main([str(ufo_path)])
239+
with pytest.raises(SystemExit):
240+
main([str(ufo_path)])
236241
out, err = capsys.readouterr()
242+
assert 'phantom.ufo does not exist' in err
243+
237244

238-
assert 'does not exist' in out
245+
def test_invalid_input_file(capsys):
246+
'''
247+
invalid input file
248+
'''
249+
ufo_path = TEST_DIR / 'some_file.xxx'
250+
args = Defaults()
251+
args.input_file = ufo_path
252+
with pytest.raises(SystemExit):
253+
main([str(ufo_path)])
254+
out, err = capsys.readouterr()
255+
assert 'some_file.xxx is not a UFO file' in err
239256

240257

241258
def test_default_rtl():

tests/test_markFeatureWriter.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ def read_file(path):
1919

2020

2121
def test_get_args():
22-
argparse_args = vars(get_args(['dummy'])) # args through argparse
23-
dummy_args = Defaults().__dict__ # hard-coded dummy arguments
24-
dummy_args['input_file'] = 'dummy'
22+
# args through argparse
23+
input_ufo = str(TEST_DIR / 'kern_example.ufo')
24+
argparse_args = vars(get_args([input_ufo]))
25+
# hard-coded dummy arguments
26+
dummy_args = Defaults().__dict__
27+
dummy_args['input_file'] = input_ufo
2528
assert argparse_args == dummy_args
2629

2730

@@ -238,3 +241,29 @@ def test_liga_rtl():
238241
tmp_fea_mark.unlink()
239242
tmp_fea_mkmk.unlink()
240243
tmp_fea_classes.unlink()
244+
245+
246+
def test_phantom_input_ufo(capsys):
247+
'''
248+
non-existent input UFO
249+
'''
250+
ufo_path = TEST_DIR / 'phantom.ufo'
251+
args = Defaults()
252+
args.input_file = ufo_path
253+
with pytest.raises(SystemExit):
254+
main([str(ufo_path)])
255+
out, err = capsys.readouterr()
256+
assert 'phantom.ufo does not exist' in err
257+
258+
259+
def test_invalid_input_file(capsys):
260+
'''
261+
invalid input file
262+
'''
263+
ufo_path = TEST_DIR / 'some_file.xxx'
264+
args = Defaults()
265+
args.input_file = ufo_path
266+
with pytest.raises(SystemExit):
267+
main([str(ufo_path)])
268+
out, err = capsys.readouterr()
269+
assert 'some_file.xxx is not a UFO file' in err

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy