From c6398197170c97654b1ad24f37a5d256d181e8ff Mon Sep 17 00:00:00 2001 From: Kyunghan Bae <74843284+qorud02@users.noreply.github.com> Date: Thu, 12 Nov 2026 21:23:44 +0900 Subject: [PATCH 1/2] Parameterize temperature conversion tests in both package examples --- .../tests/examplePy/test_temperature.py | 77 ++++++------------ .../tests/examplePy/test_temperature.py | 79 ++++++------------- 2 files changed, 51 insertions(+), 105 deletions(-) diff --git a/examples/pure-hatch/tests/examplePy/test_temperature.py b/examples/pure-hatch/tests/examplePy/test_temperature.py index c8ac1eef1..6ea90f32a 100644 --- a/examples/pure-hatch/tests/examplePy/test_temperature.py +++ b/examples/pure-hatch/tests/examplePy/test_temperature.py @@ -1,6 +1,6 @@ """Pytest-based unit test examples for the temperature module""" -import math +import pytest from examplePy import temperature @@ -43,56 +43,29 @@ def test_temperature_workflow(): assert abs(result - 50.0) < 0.01 -def test_fahrenheit_to_celsius_positive(): - """Test F to C calculation for positive values""" - value = 95 - expected_result = 35 +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(95, 35, id="positive"), + pytest.param(-13, -25, id="negative"), + pytest.param(0, -17.7778, id="zero"), + ], +) +def test_fahrenheit_to_celsius(value, expected): + """Check known Fahrenheit/Celsius pairs, including zero Fahrenheit.""" result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_negative(): - """Test F to C calculation for negative values""" - value = -13 - expected_result = -25 - result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_zero(): - """Test F to C calculation for zero""" - value = 0 - expected_result = -17.7778 - result = temperature.fahrenheit_to_celsius(value) - - # Test that the result is close to the expected value, within tolerances - assert math.isclose(result, expected_result, abs_tol=0.0001) - - -def test_celsius_to_fahrenheit_positive(): - """Test C to F calculation for positive values""" - value = 100 - expected_result = 212 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_negative(): - """Test C to F calculation for negative values""" - value = -20 - expected_result = -4 + assert result == pytest.approx(expected, abs=0.0001) + + +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(100, 212, id="positive"), + pytest.param(-20, -4, id="negative"), + pytest.param(0, 32, id="zero"), + ], +) +def test_celsius_to_fahrenheit(value, expected): + """Check known Celsius/Fahrenheit pairs.""" result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_zero(): - """Test C to F calculation for zero""" - value = 0 - expected_result = 32 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result + assert result == pytest.approx(expected, abs=0.0001) diff --git a/examples/pure-setuptools/tests/examplePy/test_temperature.py b/examples/pure-setuptools/tests/examplePy/test_temperature.py index 9c6e3d5a3..284c20457 100644 --- a/examples/pure-setuptools/tests/examplePy/test_temperature.py +++ b/examples/pure-setuptools/tests/examplePy/test_temperature.py @@ -1,60 +1,33 @@ -"""Pytest-based unit test examples for the temperature module""" +"""Parametrized conversion cases for the example temperature module.""" -import math +import pytest from examplePy import temperature -def test_fahrenheit_to_celsius_positive(): - """Test F to C calculation for positive values""" - value = 95 - expected_result = 35 +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(95, 35, id="positive"), + pytest.param(-13, -25, id="negative"), + pytest.param(0, -17.7778, id="zero"), + ], +) +def test_fahrenheit_to_celsius(value, expected): + """Check known Fahrenheit/Celsius pairs, including zero Fahrenheit.""" result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_negative(): - """Test F to C calculation for negative values""" - value = -13 - expected_result = -25 - result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_zero(): - """Test F to C calculation for zero""" - value = 0 - expected_result = -17.7778 - result = temperature.fahrenheit_to_celsius(value) - - # Test that the result is close to the expected value, within tolerances - assert math.isclose(result, expected_result, abs_tol=0.0001) - - -def test_celsius_to_fahrenheit_positive(): - """Test C to F calculation for positive values""" - value = 100 - expected_result = 212 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_negative(): - """Test C to F calculation for negative values""" - value = -20 - expected_result = -4 + assert result == pytest.approx(expected, abs=0.0001) + + +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(100, 212, id="positive"), + pytest.param(-20, -4, id="negative"), + pytest.param(0, 32, id="zero"), + ], +) +def test_celsius_to_fahrenheit(value, expected): + """Check known Celsius/Fahrenheit pairs.""" result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_zero(): - """Test C to F calculation for zero""" - value = 0 - expected_result = 32 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result + assert result == pytest.approx(expected, abs=0.0001) From 8bf541dac03cb2a1939308632e85584087c89a8d Mon Sep 17 00:00:00 2001 From: Kyunghan Bae <74843284+qorud02@users.noreply.github.com> Date: Thu, 12 Nov 2026 21:27:58 +0900 Subject: [PATCH 2/2] Follow the setuptools example's import grouping --- examples/pure-setuptools/tests/examplePy/test_temperature.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/pure-setuptools/tests/examplePy/test_temperature.py b/examples/pure-setuptools/tests/examplePy/test_temperature.py index 284c20457..49829064f 100644 --- a/examples/pure-setuptools/tests/examplePy/test_temperature.py +++ b/examples/pure-setuptools/tests/examplePy/test_temperature.py @@ -1,7 +1,6 @@ """Parametrized conversion cases for the example temperature module.""" import pytest - from examplePy import temperature