From f5b32a10a81bc25f0e418c6d572914f86323a287 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Jul 2025 03:29:34 +0500 Subject: [PATCH 1/4] Add unit tests for factorial.py --- maths/test_factorial.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 maths/test_factorial.py diff --git a/maths/test_factorial.py b/maths/test_factorial.py new file mode 100644 index 000000000000..5ae2b52fdaa8 --- /dev/null +++ b/maths/test_factorial.py @@ -0,0 +1,22 @@ +import unittest +from factorial import factorial + +class TestFactorial(unittest.TestCase): + + def test_zero(self): + self.assertEqual(factorial(0), 1) + + def test_positive_integers(self): + self.assertEqual(factorial(1), 1) + self.assertEqual(factorial(5), 120) + self.assertEqual(factorial(7), 5040) + + def test_large_number(self): + self.assertEqual(factorial(10), 3628800) + + def test_negative_number(self): + with self.assertRaises(ValueError): + factorial(-3) + +if __name__ == '__main__': + unittest.main() From 5e0e9ad5e96ab9401a400d2a3ab1f706354370cc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 22:42:14 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/test_factorial.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maths/test_factorial.py b/maths/test_factorial.py index 5ae2b52fdaa8..1081c32c70b3 100644 --- a/maths/test_factorial.py +++ b/maths/test_factorial.py @@ -1,8 +1,8 @@ import unittest from factorial import factorial -class TestFactorial(unittest.TestCase): +class TestFactorial(unittest.TestCase): def test_zero(self): self.assertEqual(factorial(0), 1) @@ -18,5 +18,6 @@ def test_negative_number(self): with self.assertRaises(ValueError): factorial(-3) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() From 6f1b5cdf998419062f96cdaf1cf26a65876febe7 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 5 Jul 2025 12:51:34 +0200 Subject: [PATCH 3/4] uvx --python=3.12 unittest2pytest --write test_factorial.py --- maths/test_factorial.py | 44 +++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/maths/test_factorial.py b/maths/test_factorial.py index 1081c32c70b3..d80d88add745 100644 --- a/maths/test_factorial.py +++ b/maths/test_factorial.py @@ -1,23 +1,37 @@ -import unittest -from factorial import factorial +# /// script +# requires-python = ">=3.13" +# dependencies = [ +# "pytest", +# ] +# /// +import pytest -class TestFactorial(unittest.TestCase): - def test_zero(self): - self.assertEqual(factorial(0), 1) +from maths.factorial import factorial, factorial_recursive - def test_positive_integers(self): - self.assertEqual(factorial(1), 1) - self.assertEqual(factorial(5), 120) - self.assertEqual(factorial(7), 5040) - def test_large_number(self): - self.assertEqual(factorial(10), 3628800) +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) +def test_zero(function): + assert function(0) == 1 - def test_negative_number(self): - with self.assertRaises(ValueError): - factorial(-3) + +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) +def test_positive_integers(function): + assert function(1) == 1 + assert function(5) == 120 + assert function(7) == 5040 + + +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) +def test_large_number(function): + assert function(10) == 3628800 + + +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) +def test_negative_number(function): + with pytest.raises(ValueError): + function(-3) if __name__ == "__main__": - unittest.main() + pytest.main(["-v", __file__]) From a15b6fbfb424c950db33a31b09989ba34f13cd56 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 5 Jul 2025 12:55:59 +0200 Subject: [PATCH 4/4] Update error message in current_stock_price.py --- web_programming/current_stock_price.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_programming/current_stock_price.py b/web_programming/current_stock_price.py index 16b0b6772a9c..531da949ea50 100644 --- a/web_programming/current_stock_price.py +++ b/web_programming/current_stock_price.py @@ -23,7 +23,7 @@ def stock_price(symbol: str = "AAPL") -> str: """ >>> stock_price("EEEE") - '- ' + 'No tag with the specified data-testid attribute found.' >>> isinstance(float(stock_price("GOOG")),float) True """