def test_update_config(self): dest = os.path.join(tempfile.mkdtemp(), os.path.basename(CONFIG_FILE)) shutil.copy2(CONFIG_FILE, dest) # Replace 'Sully' match tag from 'Bars' to 'Drink' tags.edit('Bars', 'Sully', 'Drink', 'Sully', {'config': dest}) tags.load(dest) self.assertEqual(tags.find_tag_for('Sully')[0], 'Drink')
def process_file(transactions, options): """Process file's transactions. Operate in a dedicated edit screen.""" tag = None with TERM.fullscreen(): try: for (i, t) in enumerate(transactions): cached_tag, cached_match = tags.find_tag_for(t['payee']) tag, match = process_transaction(t, cached_tag or t['category'], cached_match, options) if tag: tags.edit(cached_tag, cached_match, tag, match, options) t['category'] = tag if not t['payee']: print('Skip transaction: no payee') separator = '-' * 3 print(separator) i = i + 1 if not options.get('batch', False): quick_input('Press any key to continue (Ctrl+D to discard ' 'edits)') except KeyboardInterrupt: return transactions[:i] return transactions[:i]
def process_file(transactions, options): """Process file's transactions.""" cat = None try: i = 0 for (i, t) in enumerate(transactions): cat, match = process_transaction(t, options) tags.edit(t, cat, match, options) i = i + 1 if not options.get('batch', False): quick_input('Press any key to continue (Ctrl+D to discard ' 'edits)') except KeyboardInterrupt: return transactions[:i] return transactions[:i]
def process_transactions(transactions, options): """Process file's transactions.""" cat = None try: i = 0 for (i, t) in enumerate(transactions): if not t["payee"]: print("Skip transaction #%s with no payee field" % (i + 1)) continue cat, match = process_transaction(t, options) tags.edit(t, cat, match, options) i = i + 1 if not options["batch"]: quick_input("\nPress any key to continue (Ctrl+D to discard " "edits)") except KeyboardInterrupt: return transactions[:i] return transactions[:i]
def test_edit__drop_empty_category(self): t = TRANSACTION.copy() t["payee"] = "FOO Art Brut Shop BAR" res = tags.edit(t, "SPAM", "FOO", OPTIONS) self.assertEqual(set(res.keys()), set(["Bars", "SPAM"]))
def test_edit(self): res = tags.edit(TRANSACTION, "Drinks", "Sully bar", OPTIONS) self.assertEqual(set(res.keys()), set(["Bars", "Clothes", "Drinks"])) self.assertEqual(res["Bars"], ["Art Brut"]) res = tags.edit(TRANSACTION, "Drinks", {"payee": "Sully"}, OPTIONS) self.assertEqual(res["Drinks"], [{"payee": "Sully"}])
def test_edit__drop_empty_category(self): t = TRANSACTION.copy() t['payee'] = 'FOO Art Brut Shop BAR' res = tags.edit(t, 'SPAM', 'FOO', OPTIONS) self.assertEqual(set(res.keys()), set(['Bars', 'SPAM']))
def test_edit(self): res = tags.edit(TRANSACTION, 'Drinks', 'Sully bar', OPTIONS) self.assertEqual(set(res.keys()), set(['Bars', 'Clothes', 'Drinks'])) self.assertEqual(res['Bars'], ['Art Brut']) res = tags.edit(TRANSACTION, 'Drinks', {'payee': 'Sully'}, OPTIONS) self.assertEqual(res['Drinks'], [{'payee': 'Sully'}])
def test_edit(self): res = tags.edit(TRANSACTION, 'Drinks', 'Sully bar', OPTIONS) self.assertEqual(set(res.keys()), set(['Bars', 'Clothes', 'Drinks'])) self.assertEqual(res['Bars'], ['Art Brut'])