Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 25 additions & 52 deletions examples/pure-hatch/tests/examplePy/test_temperature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Pytest-based unit test examples for the temperature module"""

import math
import pytest

from examplePy import temperature

Expand Down Expand Up @@ -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)
80 changes: 26 additions & 54 deletions examples/pure-setuptools/tests/examplePy/test_temperature.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,32 @@
"""Pytest-based unit test examples for the temperature module"""

import math
"""Parametrized conversion cases for the example temperature module."""

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
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
@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_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)