예제 #1
0
    def test_hash_entries_same_postings(self):
        entries1, _, __ = loader.load_string("""
          2020-01-01 * "BarAlice" "Beer with my guy friends ASDF"
            Assets:Cash           -10.00 USD
            Expenses:Food:Drinks    2.00 USD
              shared: "Assets:Debtors:Bob 4.00 USD"
              shared901: "Assets:Debtors:Bob 4.00 USD"
            Assets:Debtors:Bob      4.00 USD
              shared: "Expenses:Food:Drinks 4.00 USD"
            Assets:Debtors:Bob      4.00 USD
              shared: "Expenses:Food:Drinks 4.00 USD"
        """)

        entries2, _, __ = loader.load_string("""
          2020-01-01 * "BarAlice" "Beer with my guy friends ASDF"
            Assets:Cash           -10.00 USD
            Expenses:Food:Drinks    2.00 USD
              shared: "Assets:Debtors:Bob 4.00 USD"
              shared901: "Assets:Debtors:Bob 4.00 USD"
            Assets:Debtors:Bob      4.00 USD
              shared: "Expenses:Food:Drinks 4.00 USD"
        """)
        hashes1, _ = compare.hash_entries(entries1)
        hashes2, _ = compare.hash_entries(entries2)
        self.assertNotEqual(set(hashes1), set(hashes2.keys()))
예제 #2
0
    def test_hash_entries_with_duplicates(self):
        entries, _, __ = loader.load_string("""
          2014-08-01 price HOOL  603.10 USD
        """)
        hashes, errors = compare.hash_entries(entries)
        self.assertEqual(1, len(hashes))

        entries, _, __ = loader.load_string("""
          2014-08-01 price HOOL  603.10 USD
          2014-08-01 price HOOL  603.10 USD
          2014-08-01 price HOOL  603.10 USD
          2014-08-01 price HOOL  603.10 USD
          2014-08-01 price HOOL  603.10 USD
        """)
        hashes, errors = compare.hash_entries(entries)
        self.assertEqual(1, len(hashes))
예제 #3
0
 def test_hash_entries(self):
     previous_hashes = None
     for _ in range(64):
         entries, errors, options_map = loader.load_string(TEST_INPUT)
         hashes, errors = compare.hash_entries(entries)
         self.assertFalse(errors)
         if previous_hashes is None:
             previous_hashes = hashes
         else:
             self.assertEqual(previous_hashes.keys(), hashes.keys())
예제 #4
0
def validate_no_duplicates(entries, unused_options_map):
    """Check that the entries are unique, by computing hashes.

    Args:
      entries: A list of directives.
      unused_options_map: An options map.
    Returns:
      A list of new errors, if any were found.
    """
    unused_hashes, errors = compare.hash_entries(entries)
    return entries, errors