def test_z_mean_override(self, kwargs, expected): """Test overriding behavior of kw 'z_mean'.""" ws = hollweg(**kwargs) ws_expected = hollweg(**expected) for mode in ws: assert np.isclose(ws[mode], ws_expected[mode], atol=1e-5, rtol=1.7e-4)
def test_hollweg1999_vals(self, kwargs, expected, desired_beta): """ Test calculated values based on Figure 2 of Hollweg1999 (DOI: https://doi.org/10.1029/1998JA900132) using eqn 3 of Bellan 2012 (DOI: https://doi.org/10.1029/2012JA017856). The WebPlotDigitizer software was used to determine the test parameters for k, B, and expected omega from Figure 2 of Hollweg1999. - GitHub: https://github.com/ankitrohatgi/WebPlotDigitizer - Web Version: https://automeris.io/WebPlotDigitizer/ """ # k values need to be single valued for this test to function correctly cs = speeds.cs_(kwargs["T_e"], kwargs["T_i"], kwargs["ion"]).value va = speeds.va_(kwargs["B"], kwargs["n_i"], ion=kwargs["ion"]).value beta = (cs / va)**2 if not np.isclose(beta, desired_beta, atol=2e-4): pytest.fail( f"The Holweg 1999 paper requires a 'beta' value of {desired_beta:0.5f} " f"and the test parameters yielded {beta:.6f}.") kz = (np.cos(kwargs["theta"]) * kwargs["k"]).value w_alfven = (hollweg(**kwargs)["alfven_mode"]).value big_omega = np.abs(w_alfven / (kz * va)) assert np.allclose(big_omega, expected, atol=1e-2)
def test_return_structure(self, kwargs, expected): """Test the structure of the returned values.""" ws = hollweg(**kwargs) assert isinstance(ws, dict) assert len({"acoustic_mode", "alfven_mode", "fast_mode"} - set(ws.keys())) == 0 for mode, val in ws.items(): assert isinstance(val, u.Quantity) assert val.unit == u.rad / u.s assert val.shape == expected["shape"]
def test_warning(self, kwargs, _warning): """Test scenarios that raise a `Warning`.""" with pytest.warns(_warning): hollweg(**kwargs)
def test_raises(self, kwargs, _error): """Test scenarios that raise an `Exception`.""" with pytest.raises(_error): hollweg(**kwargs)
def test_handle_k_theta_arrays(self, kwargs, expected): """Test scenarios involving k and theta arrays.""" ws = hollweg(**kwargs) for mode, val in ws.items(): assert np.allclose(val.value, expected[mode])