From 306fd4bbe7bb527336974adbc2841361b7d74407 Mon Sep 17 00:00:00 2001 From: Jayati Patel Date: Wed, 24 Jul 2024 21:02:08 +0000 Subject: [PATCH 1/5] Unit test dassert_lt() --- helpers/test/test_dbg.py | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/helpers/test/test_dbg.py b/helpers/test/test_dbg.py index a6abe5705b..65993b09e4 100644 --- a/helpers/test/test_dbg.py +++ b/helpers/test/test_dbg.py @@ -713,3 +713,57 @@ def test4(self) -> None: Obj = collections.namedtuple("Obj", ["a", "b"]) list_ = [Obj(1, 2), Obj(1, 2)] hdbg.dassert_all_attributes_are_same(list_, "b") + +# ############################################################################# +class Test_dassert_lt(hunitest.TestCase): + + def test1(self) -> None: + """ + Test where val1 is less than val2. + """ + hdbg.dassert_lt(1, 2) + + def test2(self) -> None: + """ + Test where val1 is equal to val2. + """ + with self.assertRaises(AssertionError) as cm: + hdbg.dassert_lt(2, 2) + + act = str(cm.exception) + exp = """ + * Failed assertion * + 2 < 2 + """ + self.assert_equal(act, exp, fuzzy_match=True) + + def test3(self) -> None: + """ + Test where val1 is greater than val2. + """ + with self.assertRaises(AssertionError) as cm: + hdbg.dassert_lt(3, 2) + act = str(cm.exception).strip() + exp = """ + * Failed assertion * + 3 < 2 + """ + self.assert_equal(act, exp, fuzzy_match=True) + + def test4(self) -> None: + """ + Test where val1 is less than val2 with strings. + """ + hdbg.dassert_lt("a", "b") + + def test5(self) -> None: + """ + Test where val1 is greater than val2 with floats. + """ + with self.assertRaises(AssertionError) as cm: + hdbg.dassert_lt(2.0, 1.0) + act = str(cm.exception) + exp = """ + * Failed assertion * + 2.0 < 1.0""" + self.assert_equal(act, exp, fuzzy_match=True) \ No newline at end of file From 52a454a9e847887fa3f9f6d2fc7da338317be9f8 Mon Sep 17 00:00:00 2001 From: Jayati Patel Date: Thu, 25 Jul 2024 13:15:39 +0000 Subject: [PATCH 2/5] update --- helpers/test/test_dbg.py | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/helpers/test/test_dbg.py b/helpers/test/test_dbg.py index 65993b09e4..2e67bbc86f 100644 --- a/helpers/test/test_dbg.py +++ b/helpers/test/test_dbg.py @@ -715,55 +715,69 @@ def test4(self) -> None: hdbg.dassert_all_attributes_are_same(list_, "b") # ############################################################################# + class Test_dassert_lt(hunitest.TestCase): def test1(self) -> None: """ - Test where val1 is less than val2. + Test that the function works fine if first value is less than second value. """ - hdbg.dassert_lt(1, 2) + val1 = 1 + val2 = 2 + hdbg.dassert_lt(val1, val2) def test2(self) -> None: """ - Test where val1 is equal to val2. + Test that the function works fine if first value is equal to second value, this raises an exception. """ + val1 = 2 + val2 = 2 with self.assertRaises(AssertionError) as cm: - hdbg.dassert_lt(2, 2) - + hdbg.dassert_lt(val1, val2) act = str(cm.exception) exp = """ * Failed assertion * 2 < 2 """ + #check. self.assert_equal(act, exp, fuzzy_match=True) def test3(self) -> None: """ - Test where val1 is greater than val2. + Test that the function works fine if first value is greater than second value, this raises an exception. """ + val1 = 3 + val2 = 2 with self.assertRaises(AssertionError) as cm: - hdbg.dassert_lt(3, 2) + hdbg.dassert_lt(val1, val2) act = str(cm.exception).strip() exp = """ - * Failed assertion * - 3 < 2 + * Failed assertion * + 3 < 2 """ + #check. self.assert_equal(act, exp, fuzzy_match=True) def test4(self) -> None: """ - Test where val1 is less than val2 with strings. + Test that the function works with string inputs. """ - hdbg.dassert_lt("a", "b") + val1 = "a" + val2 = "b" + hdbg.dassert_lt(val1, val2) def test5(self) -> None: """ - Test where val1 is greater than val2 with floats. + Test where first value is greater than second value with floats, this raises an exception. """ + val1 = 2.0 + val2 = 1.0 with self.assertRaises(AssertionError) as cm: - hdbg.dassert_lt(2.0, 1.0) + hdbg.dassert_lt(val1, val2) act = str(cm.exception) exp = """ * Failed assertion * - 2.0 < 1.0""" + 2.0 < 1.0 + """ + #check. self.assert_equal(act, exp, fuzzy_match=True) \ No newline at end of file From 84141b48414aef68cecc51bd0ef2f9446fde424b Mon Sep 17 00:00:00 2001 From: Jayati Patel Date: Sat, 27 Jul 2024 22:08:43 +0000 Subject: [PATCH 3/5] update --- helpers/test/test_dbg.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/helpers/test/test_dbg.py b/helpers/test/test_dbg.py index 2e67bbc86f..c6099b5135 100644 --- a/helpers/test/test_dbg.py +++ b/helpers/test/test_dbg.py @@ -720,7 +720,7 @@ class Test_dassert_lt(hunitest.TestCase): def test1(self) -> None: """ - Test that the function works fine if first value is less than second value. + Test that the function doesn't raise an exception if first value is less than second value. """ val1 = 1 val2 = 2 @@ -728,7 +728,7 @@ def test1(self) -> None: def test2(self) -> None: """ - Test that the function works fine if first value is equal to second value, this raises an exception. + Test that the function raises an exception if first value is equal to second value. """ val1 = 2 val2 = 2 @@ -739,28 +739,28 @@ def test2(self) -> None: * Failed assertion * 2 < 2 """ - #check. + # check. self.assert_equal(act, exp, fuzzy_match=True) def test3(self) -> None: """ - Test that the function works fine if first value is greater than second value, this raises an exception. + Test that the function raises an exception if first value is greater than second value. """ val1 = 3 val2 = 2 with self.assertRaises(AssertionError) as cm: hdbg.dassert_lt(val1, val2) - act = str(cm.exception).strip() + act = str(cm.exception) exp = """ * Failed assertion * 3 < 2 """ - #check. + # check. self.assert_equal(act, exp, fuzzy_match=True) def test4(self) -> None: """ - Test that the function works with string inputs. + Test that the function doesn't raise an exception when we pass string inputs. """ val1 = "a" val2 = "b" @@ -768,7 +768,7 @@ def test4(self) -> None: def test5(self) -> None: """ - Test where first value is greater than second value with floats, this raises an exception. + Test that the function raises an exception where first value is greater than second value with floats. """ val1 = 2.0 val2 = 1.0 @@ -779,5 +779,5 @@ def test5(self) -> None: * Failed assertion * 2.0 < 1.0 """ - #check. + # check. self.assert_equal(act, exp, fuzzy_match=True) \ No newline at end of file From f1db6f2cdef887db610447b14d46018f07b16084 Mon Sep 17 00:00:00 2001 From: jayati1397 Date: Tue, 30 Jul 2024 15:54:08 +0000 Subject: [PATCH 4/5] linter update --- helpers/test/test_dbg.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/helpers/test/test_dbg.py b/helpers/test/test_dbg.py index c6099b5135..72e71122cb 100644 --- a/helpers/test/test_dbg.py +++ b/helpers/test/test_dbg.py @@ -114,7 +114,6 @@ def test5(self) -> None: # TODO(gp): Break it in piece. class Test_dassert_misc1(hunitest.TestCase): - # dassert_in def test_in1(self) -> None: @@ -660,8 +659,10 @@ def test3(self) -> None: """ self.assert_equal(act, exp, purify_text=True, fuzzy_match=True) + # ############################################################################# + class Test_dassert_all_attributes_are_same1(hunitest.TestCase): def test1(self) -> None: """ @@ -714,21 +715,24 @@ def test4(self) -> None: list_ = [Obj(1, 2), Obj(1, 2)] hdbg.dassert_all_attributes_are_same(list_, "b") + # ############################################################################# + class Test_dassert_lt(hunitest.TestCase): - def test1(self) -> None: """ - Test that the function doesn't raise an exception if first value is less than second value. + Test that the function doesn't raise an exception if first value is + less than second value. """ val1 = 1 val2 = 2 hdbg.dassert_lt(val1, val2) - + def test2(self) -> None: """ - Test that the function raises an exception if first value is equal to second value. + Test that the function raises an exception if first value is equal to + second value. """ val1 = 2 val2 = 2 @@ -741,10 +745,11 @@ def test2(self) -> None: """ # check. self.assert_equal(act, exp, fuzzy_match=True) - + def test3(self) -> None: """ - Test that the function raises an exception if first value is greater than second value. + Test that the function raises an exception if first value is greater + than second value. """ val1 = 3 val2 = 2 @@ -760,7 +765,8 @@ def test3(self) -> None: def test4(self) -> None: """ - Test that the function doesn't raise an exception when we pass string inputs. + Test that the function doesn't raise an exception when we pass string + inputs. """ val1 = "a" val2 = "b" @@ -768,7 +774,8 @@ def test4(self) -> None: def test5(self) -> None: """ - Test that the function raises an exception where first value is greater than second value with floats. + Test that the function raises an exception where first value is greater + than second value with floats. """ val1 = 2.0 val2 = 1.0 @@ -780,4 +787,4 @@ def test5(self) -> None: 2.0 < 1.0 """ # check. - self.assert_equal(act, exp, fuzzy_match=True) \ No newline at end of file + self.assert_equal(act, exp, fuzzy_match=True) From 3af80ac7dfe8e7dfcd4c032363abe8a7cc156ffc Mon Sep 17 00:00:00 2001 From: Samarth Date: Wed, 31 Jul 2024 01:06:56 +0000 Subject: [PATCH 5/5] update --- helpers/test/test_dbg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/test/test_dbg.py b/helpers/test/test_dbg.py index 76f2feaaea..25bc2666c0 100644 --- a/helpers/test/test_dbg.py +++ b/helpers/test/test_dbg.py @@ -830,7 +830,7 @@ def test3(self) -> None: # Check. self.assert_equal(act, exp, fuzzy_match=True) - def test5(self) -> None: + def test4(self) -> None: """ Test that the function raises an exception for non-integer and non- float types.