@@ -37,8 +37,14 @@ VALID_VALUES = {
'スミスダコタ',
'スミス-ダコタ',
'Яшин-Данила',
# The PayPal importer produces . in entity metadata
# Governments, using : as a hierarchy separator
'BE',
'US:KY',
'CA:ON',
# The PayPal importer allows ASCII punctuation in entity metadata
'Du-Bois-W.-E.-B.',
"O'Malley-Thomas",
'O`Malley-Thomas',
# import2ledger produces entities that end with -
# That's probably a bug, but allow it for now.
'foo-',
@@ -47,7 +53,6 @@ VALID_VALUES = {
INVALID_VALUES = {
# Starting with a - is not allowed
'-foo',
'-',
# Names that can be reduced to ASCII should be
# Producers should change this to Uberentity or Ueberentity
# I am not wild about this rule and would like to relax it—it's mostly
@@ -56,14 +61,25 @@ INVALID_VALUES = {
# mangling producers are expected to do. But it's the rule for today.
'Überentity',
# Whitespace is never allowed
' ',
'Alex Smith',
'田中\u00A0流星', # Non-breaking space
# The only punctuation allowed is - and .
'スミス_ダコタ',
# Non-ASCII punctuation is not allowed
'Яшин—Данила', # em dash
# An empty string is not valid
'O’Malley-Thomas', # Right-angled apostrophe
'Du-Bois-W。-E。-B。', # Japanese period
}
ANONYMOUS_VALUES = {
# Values produced by various importers that should be translated to
# Anonymous.
'',
'--',
'-----',
'_',
' _ ',
'.',
TEST_KEY = 'entity'
@@ -81,6 +97,15 @@ def test_valid_values_on_postings(hook, src_value):
])
assert not any(hook.run(txn))
@pytest.mark.parametrize('src_value', ANONYMOUS_VALUES)
def test_anonymous_values_on_postings(hook, src_value):
txn = testutil.Transaction(postings=[
('Assets:Cash', -25),
('Expenses:General', 25, {TEST_KEY: src_value}),
assert txn.postings[-1].meta[TEST_KEY] == 'Anonymous'
@pytest.mark.parametrize('src_value', INVALID_VALUES)
def test_invalid_values_on_postings(hook, src_value):
@@ -99,6 +124,15 @@ def test_valid_values_on_transactions(hook, src_value):
def test_anonymous_values_on_transactions(hook, src_value):
txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
('Expenses:General', 25),
assert txn.meta[TEST_KEY] == 'Anonymous'
def test_invalid_values_on_transactions(hook, src_value):
@@ -118,6 +152,15 @@ def test_valid_values_on_payee(hook, src_value):
def test_anonymous_values_on_payee(hook, src_value):
txn = testutil.Transaction(payee=src_value, postings=[
def test_invalid_values_on_payee(hook, src_value):