From a5ebc04f5d495d72ef72f45ca85579f2d09181e3 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 6 Mar 2021 12:11:16 -0500 Subject: [PATCH] data: Metadata.human_name() treats _ like -. --- conservancy_beancount/data.py | 3 ++- tests/test_data_metadata.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/conservancy_beancount/data.py b/conservancy_beancount/data.py index bf37664..e397bf1 100644 --- a/conservancy_beancount/data.py +++ b/conservancy_beancount/data.py @@ -412,6 +412,7 @@ class Metadata(MutableMapping[MetaKey, MetaValue]): 'paypal-id': 'PayPal ID', 'rt-id': 'Ticket', } + _HUMAN_TRANSLATIONS = str.maketrans('-_', ' ') def __init__(self, source: MutableMapping[MetaKey, MetaValue]) -> None: self.meta = source @@ -479,7 +480,7 @@ class Metadata(MutableMapping[MetaKey, MetaValue]): try: retval = cls._HUMAN_NAMES[key] except KeyError: - retval = key.replace('-', ' ').title() + retval = key.translate(cls._HUMAN_TRANSLATIONS).title() retval = re.sub(r'\bId$', 'ID', retval) cls._HUMAN_NAMES[key] = retval return retval diff --git a/tests/test_data_metadata.py b/tests/test_data_metadata.py index ee8e4a3..1d21cca 100644 --- a/tests/test_data_metadata.py +++ b/tests/test_data_metadata.py @@ -107,6 +107,8 @@ def test_first_link_bad_type_default(simple_txn, meta_value): ('receipt', 'Receipt'), ('rt-id', 'Ticket'), ('tax-statement', 'Tax Statement'), + ('meta_key', 'Meta Key'), + ('meta_id', 'Meta ID'), ]) def test_human_name(meta_name, expected): assert data.Metadata.human_name(meta_name) == expected