示例#1
0
    def test_excludes_entries(self):
        entries1, _, __ = loader.load_string(TEST_INPUT)
        entries2, _, __ = loader.load_string(TEST_INPUT)

        excludes, extra = compare.excludes_entries(entries1[0:4], entries2)
        self.assertFalse(excludes)
        self.assertTrue(extra)

        excludes, extra = compare.excludes_entries(entries1[0:4], entries2[4:])
        self.assertTrue(excludes)
        self.assertFalse(extra)
示例#2
0
def assertExcludesEntries(subset_entries,
                          entries,
                          failfunc=DEFAULT_FAILFUNC,
                          allow_incomplete=False):
    """Check that subset_entries is not included in entries and print extra 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)

    excludes, extra = compare.excludes_entries(subset_entries, entries)
    if not excludes:
        assert extra, "Extra is empty: {}".format(extra)
        oss = io.StringIO()
        if extra:
            oss.write("Extra from from first/excluded set:\n\n")
            for entry in extra:
                oss.write(printer.format_entry(entry))
                oss.write('\n')
        failfunc(oss.getvalue())
示例#3
0
    def assertExcludesEntries(self, subset_entries, entries):
        """Check that subset_entries is not included in entries and print extra 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)

        excludes, extra = compare.excludes_entries(subset_entries, entries)
        if not excludes:
            assert extra, "Extra is empty: {}".format(extra)
            oss = io.StringIO()
            if extra:
                oss.write("Extra from from first/excluded set:\n\n")
                for entry in extra:
                    oss.write(printer.format_entry(entry))
                    oss.write('\n')
            self.fail(oss.getvalue())
示例#4
0
    def assertExcludesEntries(self, subset_entries, entries, allow_incomplete=False):
        """Check that subset_entries is not 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)

        excludes, extra = compare.excludes_entries(subset_entries, entries)
        if not excludes:
            assert extra, "Extra is empty: {}".format(extra)
            oss = io.StringIO()
            if extra:
                oss.write("Extra from from first/excluded set:\n\n")
                for entry in extra:
                    oss.write(printer.format_entry(entry))
                    oss.write('\n')
            self.fail(oss.getvalue())