From e7e9060993e5e0d62972fe162518f2b1fa45f6ce Mon Sep 17 00:00:00 2001 From: T5 Team Date: Mon, 9 Oct 2023 10:54:29 -0700 Subject: [PATCH] Fix unit tests for comparing Dictionaries. Replaces `assertContainsSubset` in tests with a functional version that checks equality of asserted values. Previously, only keys were compared. PiperOrigin-RevId: 571983744 --- t5/evaluation/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t5/evaluation/test_utils.py b/t5/evaluation/test_utils.py index de46c0f6..d4790cff 100644 --- a/t5/evaluation/test_utils.py +++ b/t5/evaluation/test_utils.py @@ -26,3 +26,11 @@ def assertDictClose(self, a, b, delta=None, places=None): self.assertAlmostEqual(a[k], b[k], delta=delta, places=places) except AssertionError as e: raise AssertionError(str(e) + " for key '%s'" % k) + + def assertDictContainsSubset(self, expected_subset, actual_set): + self.assertContainsSubset(expected_subset.keys(), actual_set.keys()) + for k in expected_subset: + try: + self.assertEqual(expected_subset[k], actual_set[k]) + except AssertionError as e: + raise AssertionError(str(e) + " for key '%s'" % k) from None