|
| 1 | +# tests/unit/test_deprecated_aliases.py |
| 2 | +""" |
| 3 | +Unit tests for the camelCase backward-compatibility aliases (deprecated since 0.1.0). |
| 4 | +Each alias must remain importable, emit DeprecationWarning, and return results |
| 5 | +identical to its snake_case counterpart -- but must not be part of the public |
| 6 | +`__all__` surface. |
| 7 | +""" |
| 8 | +import numpy as np |
| 9 | +import pytest |
| 10 | +import flame_components |
| 11 | +from flame_components import ( |
| 12 | + get_mid_flame_ws, |
| 13 | + get_flame_length, |
| 14 | + get_flame_height, |
| 15 | + get_flame_tilt, |
| 16 | + get_flame_residence_time, |
| 17 | + get_flame_depth, |
| 18 | + flame_component_array_multiprocessing, |
| 19 | + getMidFlameWS, |
| 20 | + getFlameLength, |
| 21 | + getFlameHeight, |
| 22 | + getFlameTilt, |
| 23 | + getFlameResidenceTime, |
| 24 | + getFlameDepth, |
| 25 | + flameComponent_ArrayMultiprocessing, |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +class TestDeprecatedAliasesWarnAndMatch: |
| 30 | + def test_get_mid_flame_ws_alias(self): |
| 31 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 32 | + alias_result = getMidFlameWS( |
| 33 | + wind_speed=20.0, canopy_cover=50, canopy_ht=20.0, |
| 34 | + canopy_baseht=5.0, units='SI' |
| 35 | + ) |
| 36 | + direct_result = get_mid_flame_ws( |
| 37 | + wind_speed=20.0, canopy_cover=50, canopy_ht=20.0, |
| 38 | + canopy_baseht=5.0, units='SI' |
| 39 | + ) |
| 40 | + assert alias_result == pytest.approx(direct_result) |
| 41 | + |
| 42 | + def test_get_flame_length_alias(self): |
| 43 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 44 | + alias_result = getFlameLength('Byram_HEAD', 100.0) |
| 45 | + direct_result = get_flame_length('Byram_HEAD', 100.0) |
| 46 | + assert alias_result == pytest.approx(direct_result) |
| 47 | + |
| 48 | + def test_get_flame_height_alias(self): |
| 49 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 50 | + alias_result = getFlameHeight( |
| 51 | + 'Nelson', 5.0, fire_type=1, fire_intensity=1000.0, midflame_ws=2.0 |
| 52 | + ) |
| 53 | + direct_result = get_flame_height( |
| 54 | + 'Nelson', 5.0, fire_type=1, fire_intensity=1000.0, midflame_ws=2.0 |
| 55 | + ) |
| 56 | + assert alias_result == pytest.approx(direct_result) |
| 57 | + |
| 58 | + def test_get_flame_tilt_alias(self): |
| 59 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 60 | + alias_result = getFlameTilt('Standard', flame_length=10.0, flame_height=5.0) |
| 61 | + direct_result = get_flame_tilt('Standard', flame_length=10.0, flame_height=5.0) |
| 62 | + assert alias_result == pytest.approx(direct_result) |
| 63 | + |
| 64 | + def test_get_flame_residence_time_alias(self): |
| 65 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 66 | + alias_result = getFlameResidenceTime(1.0, 1.0, 1.0, 'sec') |
| 67 | + direct_result = get_flame_residence_time(1.0, 1.0, 1.0, 'sec') |
| 68 | + assert alias_result == pytest.approx(direct_result) |
| 69 | + |
| 70 | + def test_get_flame_depth_alias(self): |
| 71 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 72 | + alias_result = getFlameDepth(2.0, 3.0) |
| 73 | + direct_result = get_flame_depth(2.0, 3.0) |
| 74 | + assert alias_result == pytest.approx(direct_result) |
| 75 | + |
| 76 | + def test_flame_component_array_multiprocessing_alias(self): |
| 77 | + ros = np.array([1.0, 2.0, 3.0, 4.0]) |
| 78 | + res_time = np.array([1.0, 1.0, 1.0, 1.0]) |
| 79 | + with pytest.warns(DeprecationWarning, match="Use .* instead"): |
| 80 | + alias_blocks = flameComponent_ArrayMultiprocessing( |
| 81 | + 'flame_depth', num_processors=2, block_size=None, ros=ros, res_time=res_time |
| 82 | + ) |
| 83 | + direct_blocks = flame_component_array_multiprocessing( |
| 84 | + 'flame_depth', num_processors=2, block_size=None, ros=ros, res_time=res_time |
| 85 | + ) |
| 86 | + np.testing.assert_allclose( |
| 87 | + np.concatenate(alias_blocks), np.concatenate(direct_blocks) |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +class TestDeprecatedAliasesExcludedFromAll: |
| 92 | + def test_all_contains_only_snake_case_names(self): |
| 93 | + expected = { |
| 94 | + 'get_mid_flame_ws', |
| 95 | + 'get_flame_length', |
| 96 | + 'get_flame_height', |
| 97 | + 'get_flame_tilt', |
| 98 | + 'get_flame_residence_time', |
| 99 | + 'get_flame_depth', |
| 100 | + 'flame_component_array_multiprocessing', |
| 101 | + } |
| 102 | + assert set(flame_components.__all__) == expected |
| 103 | + |
| 104 | + def test_aliases_not_in_all(self): |
| 105 | + aliases = { |
| 106 | + 'getMidFlameWS', |
| 107 | + 'getFlameLength', |
| 108 | + 'getFlameHeight', |
| 109 | + 'getFlameTilt', |
| 110 | + 'getFlameResidenceTime', |
| 111 | + 'getFlameDepth', |
| 112 | + 'flameComponent_ArrayMultiprocessing', |
| 113 | + } |
| 114 | + assert aliases.isdisjoint(set(flame_components.__all__)) |
0 commit comments