def test_includes_entries(self): entries1, _, __ = loader.load_string(TEST_INPUT) entries2, _, __ = loader.load_string(TEST_INPUT) includes, missing = compare.includes_entries(entries1[0:-3], entries2) self.assertTrue(includes) self.assertFalse(missing) includes, missing = compare.includes_entries(entries1, entries2[0:-3]) self.assertFalse(includes) self.assertEqual(3, len(missing))
def assertIncludesEntries(subset_entries, entries, failfunc=DEFAULT_FAILFUNC, allow_incomplete=False): """Check that subset_entries is included in entries and print missing entries. Args: subset_entries: Either a list of directives or a string, in which case the string is run through beancount.parser.parse_string() and the resulting list is used. entries: Same treatment as subset_entries, the other list of directives to compare to. failfunc: A function to call on failure. allow_incomplete: A boolean, true if we allow incomplete inputs and perform light-weight booking. Raises: AssertionError: If the exception fails. """ subset_entries = read_string_or_entries(subset_entries, allow_incomplete) entries = read_string_or_entries(entries) includes, missing = compare.includes_entries(subset_entries, entries) if not includes: assert missing, "Missing is empty: {}".format(missing) oss = io.StringIO() if missing: oss.write("Missing from from expected set:\n\n") for entry in missing: oss.write(printer.format_entry(entry)) oss.write('\n') failfunc(oss.getvalue())
def assertIncludesEntries(self, subset_entries, entries): """Check that subset_entries is included in entries and print missing entries. Args: subset_entries: Either a list of directives or a string, in which case the string is run through beancount.parser.parse_string() and the resulting list is used. entries: Same treatment as subset_entries, the other list of directives to compare to. Raises: AssertionError: If the exception fails. """ subset_entries = read_string_or_entries(subset_entries) entries = read_string_or_entries(entries) includes, missing = compare.includes_entries(subset_entries, entries) if not includes: assert missing, "Missing is empty: {}".format(missing) oss = io.StringIO() if missing: oss.write("Missing from from expected set:\n\n") for entry in missing: oss.write(printer.format_entry(entry)) oss.write('\n') self.fail(oss.getvalue())
def assertIncludesEntries(self, subset_entries, entries, allow_incomplete=False): """Check that subset_entries is included in entries. Entries can be provided either as a list of directives or as a string. In the latter case, the string is parsed with beancount.parser.parse_string() and the resulting directives list is used. If allow_incomplete is True, light-weight booking is performed before comparing the directive lists, allowing to compare transactions with incomplete postings. Args: subset_entries: Subset entries. entries: Entries. allow_incomplete: Perform booking before comparison. Raises: AssertionError: If the exception fails. """ subset_entries = read_string_or_entries(subset_entries, allow_incomplete) entries = read_string_or_entries(entries) includes, missing = compare.includes_entries(subset_entries, entries) if not includes: assert missing, "Missing is empty: {}".format(missing) oss = io.StringIO() if missing: oss.write("Missing from from expected set:\n\n") for entry in missing: oss.write(printer.format_entry(entry)) oss.write('\n') self.fail(oss.getvalue())
def newly_generated_txns(output_txns, correctly_generated_txn_text): # Get transactions from output of plugin (should be tagged appropriately) transactions = [txn for txn in output_txns if isinstance(txn, Transaction)] # Get correctly generated transactions from feature file correctly_generated_txns, _, _ = load_string(correctly_generated_txn_text) has_correct, missing_entries = includes_entries(correctly_generated_txns, transactions) print("Missing entries: {}".format(len(missing_entries))) assert has_correct