def test_convergence_name(): in_path = os.path.join(DATA_DIR_PATH, "prD.do") main_list = simple_read(in_path) convergence = Convergence("test") convergence.add_grids(main_list) assert str(convergence)
def test_get_resolution_insufficient_grids(): convergence = Convergence() with pytest.warns(UserWarning): convergence.add_grids([(1, 0.5)]) with pytest.raises(RuntimeError) as excinfo: convergence.get_resolution(0.001) assert "Insufficient grids" in str(excinfo)
def test_convergence_two_grids(): convergence = Convergence() with pytest.warns(UserWarning): convergence.add_grids([(1, 0.5), (0.5, 0.4)]) lines = str(convergence).split("\n") assert len(lines) == 10 assert lines[1] == "Number of grids to be examined = 2 " assert lines[-2] == " *** Insufficient grids for analysis *** "
def test_convergence_gci_error(mocker): mocker.patch('convergence.interface.gci', side_effect=ArithmeticError("mock")) in_path = os.path.join(DATA_DIR_PATH, "prD.do") main_list = simple_read(in_path) convergence = Convergence(f_anal=0.9713) with pytest.warns(UserWarning): convergence.add_grids(main_list) expected_lines = ( '', 'Number of grids to be examined = 3 ', '', ' Grid Size Quantity ', '', ' 1.000000 0.970500 ', ' 2.000000 0.968540 ', ' 4.000000 0.961780 ', '', '', 'Discretisation errors for fine grids: ', '', ' Grids | e_analytic | e_approx | e_extrap | f_analytic | ', ' ========================================================================= ', ' 1 2 3 | 0.000824 | 0.002020 | 0.000824 | 0.971300 | ', ' ------------------------------------------------------------------------- ', '', ' Grids | f_delta | f_exact | gci_coarse | gci_fine | ', ' ========================================================================= ', ' 1 2 3 | -0.000000 | 0.971300 | | | ', ' ------------------------------------------------------------------------- ', '', ' Grids | p | r21 | r32 | ', ' ========================================================== ', ' 1 2 3 | 1.786170 | 2.000000 | 2.000000 | ', ' ---------------------------------------------------------- ', '', '', 'Discretisation errors for coarse grids: ', '', ' Grids | e_analytic | e_approx | e_extrap | f_analytic | ', ' ========================================================================= ', ' 1 2 3 | 0.002842 | 0.006980 | 0.002842 | 0.971300 | ', ' ------------------------------------------------------------------------- ', '', ' Grids | f_delta | f_exact | gci_coarse | gci_fine | ', ' ========================================================================= ', ' 1 2 3 | -0.000000 | 0.971300 | | | ', ' ------------------------------------------------------------------------- ', '', ' Grids | p | r21 | r32 | ', ' ========================================================== ', ' 1 2 3 | 1.786170 | 2.000000 | 2.000000 | ', ' ---------------------------------------------------------- ', '', '', 'Asymptotic ratio test: ', '', ' Grids | Asymptotic ratio | ', ' ==================================== ', ' 1 2 3 | | ', ' ------------------------------------ ', '') for actual, expected in zip(str(convergence).split("\n"), expected_lines): assert actual == expected
def test_order_of_convergence_runtimeerror(mocker): mocker.patch('convergence.interface.order_of_convergence', side_effect=RuntimeError("mock")) in_path = os.path.join(DATA_DIR_PATH, "prD.do") main_list = simple_read(in_path) convergence = Convergence(f_anal=0.9713) with pytest.warns(UserWarning): convergence.add_grids(main_list) assert str(convergence)
def convergence_anal(): in_path = os.path.join(DATA_DIR_PATH, "prD.do") main_list = simple_read(in_path) convergence = Convergence(f_anal=0.9713) convergence.add_grids(main_list) return convergence