@@ -34,39 +34,55 @@ VALID_VALUES = {
# Names that have no ASCII are allowed, with or without dash separators
'田中流星',
'田中-流星',
'スミスダコタ',
'スミス-ダコタ',
'Яшин-Данила',
# 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-',
}
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
# based on an expectation that entities are typed in by an American. That's
# true less and less and it seems like we should reduce the amount of
# 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'
@pytest.fixture(scope='module')
def hook():
@@ -78,12 +94,21 @@ def test_valid_values_on_postings(hook, src_value):
txn = testutil.Transaction(postings=[
('Assets:Cash', -25),
('Expenses:General', 25, {TEST_KEY: src_value}),
])
assert not any(hook.run(txn))
@pytest.mark.parametrize('src_value', ANONYMOUS_VALUES)
def test_anonymous_values_on_postings(hook, 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):
@@ -96,12 +121,21 @@ def test_valid_values_on_transactions(hook, src_value):
txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
('Expenses:General', 25),
def test_anonymous_values_on_transactions(hook, src_value):
assert txn.meta[TEST_KEY] == 'Anonymous'
def test_invalid_values_on_transactions(hook, src_value):
@@ -115,12 +149,21 @@ def test_valid_values_on_payee(hook, src_value):
txn = testutil.Transaction(payee=src_value, postings=[
def test_anonymous_values_on_payee(hook, src_value):
def test_invalid_values_on_payee(hook, src_value):