nowcastingcli 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/test_physics.py ADDED
@@ -0,0 +1,125 @@
1
+ # tests/test_physics.py
2
+ # Run all tests in this file: pytest tests/test_physics.py -v
3
+ import pytest
4
+ from nowcastingcli.physics import normalize_pressure
5
+
6
+
7
+ # --- Basic correctness ---
8
+
9
+ @pytest.mark.smoke
10
+ def test_sea_level_returns_input():
11
+ """At altitude=0, QNH should equal raw pressure.
12
+
13
+ Smoke: identity case for normalize_pressure() — if this breaks, the
14
+ core formula is broken for every other call site in the app.
15
+
16
+ Run: pytest tests/test_physics.py::test_sea_level_returns_input -v
17
+ """
18
+ assert normalize_pressure(1013.25, altitude_m=0.0, temperature_c=15.0) == pytest.approx(1013.25, rel=1e-4)
19
+
20
+
21
+ @pytest.mark.smoke
22
+ def test_positive_altitude_increases_qnh():
23
+ """Station above sea level → QNH > raw pressure.
24
+
25
+ Smoke: catches a sign error in the correction exponent — the most
26
+ common way to break this formula while refactoring.
27
+
28
+ Run: pytest tests/test_physics.py::test_positive_altitude_increases_qnh -v
29
+ """
30
+ raw = 1000.0
31
+ qnh = normalize_pressure(raw, altitude_m=500.0, temperature_c=15.0)
32
+ assert qnh > raw
33
+
34
+
35
+ ## --- Parameterized test for pressure increase with altitude ---
36
+ # This is more of a sanity check on the formula than a precise table test, so we allow a loose tolerance.
37
+ # Run: pytest tests/test_physics.py::test_qnh_increases_with_altitude -v
38
+ # Instead of writing 5 nearly identical test functions for different altitudes:
39
+ @pytest.mark.parametrize("altitude, expected_min", [
40
+ (0, 1013.0),
41
+ (500, 1070.0),
42
+ (1000, 1130.0),
43
+ (2000, 1260.0),
44
+ ])
45
+ def test_qnh_increases_with_altitude(altitude, expected_min):
46
+ qnh = normalize_pressure(1013.25, altitude_m=altitude, temperature_c=15.0)
47
+ assert qnh >= expected_min - 10 # loose: direction test, not exact table
48
+
49
+ @pytest.mark.smoke
50
+ def test_known_value_burgos():
51
+ """
52
+ Burgos is ~856m ASL. At 15°C, 950 hPa raw → ~1052 hPa QNH approx.
53
+ Tolerance loose — we're testing the formula, not ICAO tables.
54
+
55
+ Smoke: anchors the formula to a real-world reference value, not just
56
+ directional/identity checks — catches magnitude errors those miss.
57
+
58
+ Run: pytest tests/test_physics.py::test_known_value_burgos -v
59
+ """
60
+ qnh = normalize_pressure(950.0, altitude_m=856.0, temperature_c=15.0)
61
+ assert qnh == pytest.approx(1052.0, abs=2.0)
62
+
63
+
64
+ # --- Edge cases and guard rails ---
65
+
66
+ def test_negative_altitude_decreases_qnh():
67
+ """Below sea level (Dead Sea ~-430m) → QNH < raw pressure.
68
+
69
+ Run: pytest tests/test_physics.py::test_negative_altitude_decreases_qnh -v
70
+ """
71
+ raw = 1060.0
72
+ qnh = normalize_pressure(raw, altitude_m=-430.0, temperature_c=25.0)
73
+ assert qnh < raw
74
+
75
+
76
+ def test_extreme_cold_does_not_crash():
77
+ """Formula must survive extreme temperatures, not divide by zero.
78
+
79
+ Run: pytest tests/test_physics.py::test_extreme_cold_does_not_crash -v
80
+ """
81
+ result = normalize_pressure(900.0, altitude_m=3000.0, temperature_c=-40.0)
82
+ assert result > 0
83
+
84
+
85
+ # --- Guards ---
86
+
87
+ def test_zero_pressure_raises():
88
+ """pressure_hpa=0 is physically impossible — must raise ValueError.
89
+
90
+ Run: pytest tests/test_physics.py::test_zero_pressure_raises -v
91
+ """
92
+ with pytest.raises(ValueError, match="pressure_hpa"):
93
+ normalize_pressure(0.0, altitude_m=100.0, temperature_c=15.0)
94
+
95
+
96
+ def test_negative_pressure_raises():
97
+ """Negative pressure is physically impossible — must raise ValueError.
98
+
99
+ Run: pytest tests/test_physics.py::test_negative_pressure_raises -v
100
+ """
101
+ with pytest.raises(ValueError, match="pressure_hpa"):
102
+ normalize_pressure(-10.0, altitude_m=100.0, temperature_c=15.0)
103
+
104
+
105
+ @pytest.mark.smoke
106
+ def test_altitude_above_limit_raises():
107
+ """altitude_m > 5000 exceeds the ISA troposphere model — must raise ValueError.
108
+
109
+ Smoke: guards the input-validation path, not just the formula — if this
110
+ regresses, out-of-model altitudes silently produce bogus QNH values
111
+ instead of failing loudly.
112
+
113
+ Run: pytest tests/test_physics.py::test_altitude_above_limit_raises -v
114
+ """
115
+ with pytest.raises(ValueError, match="altitude_m"):
116
+ normalize_pressure(1013.25, altitude_m=5001.0, temperature_c=15.0)
117
+
118
+
119
+ def test_altitude_at_limit_is_accepted():
120
+ """altitude_m == 5000 is exactly at the boundary — must not raise.
121
+
122
+ Run: pytest tests/test_physics.py::test_altitude_at_limit_is_accepted -v
123
+ """
124
+ result = normalize_pressure(1013.25, altitude_m=5000.0, temperature_c=15.0)
125
+ assert result > 0