Exemple #1
0
def test_to_roman(integer, roman_numeral):
    """
    Test that `~plasmapy.utils.roman.to_roman` correctly converts
    integers to Roman numerals, and that the inverse is true as well.
    """
    run_test(func=roman.to_roman, args=integer, expected_outcome=roman_numeral)
    run_test(func=roman.from_roman, args=roman_numeral, expected_outcome=int(integer))
Exemple #2
0
def test_from_roman(integer, roman_numeral):
    """
    Test that `~plasmapy.utils.roman.from_roman` correctly converts
    Roman numerals to integers.
    """
    run_test(func=roman.from_roman,
             args=roman_numeral,
             expected_outcome=int(integer))
Exemple #3
0
def test_from_roman_exceptions(input, expected_exception):
    """
    Test that `~plasmapy.utils.roman.from_roman` raises the correct
    exceptions when necessary.
    """
    run_test(func=roman.from_roman,
             args=input,
             expected_outcome=expected_exception)
Exemple #4
0
def test_run_test(f, args, kwargs, expected, whaterror):
    """
    Test the behavior of the test helper function.

    The arguments `f`, `args`, `kwargs`, and `expected` are to be
    passed directly to `~plasmapy.utils.run_test`.  If the test is
    expected to pass, then `whaterror` should be set to `None`.  If the
    test is expected to fail, then `whaterror` should be set to the
    exception that should be raised during the test failure.

    This function does not test that the exception messages are correct;
    it only checks that the exception messages do not raise any
    unexpected exceptions.

    Parameters
    ----------
    f : callable
        The function or method to be tested.

    args : tuple
        The positional arguments to be sent to f.

    kwargs : dict
        The keyword arguments to be sent to f.

    expected : object
        The expected result from the test, which can be an `object`, an
        exception, a warning, or a `tuple` containing the expected
        result and the type of warning.

    whaterror : exception or None
        The type of exception that the test helper function is supposed
        to raise, or `None` if the test helper function is not supposed
        to raise an exception.

    """

    try:
        if whaterror is None:
            run_test(f, args, kwargs, expected)
        else:
            with pytest.raises(whaterror):
                run_test(f, args, kwargs, expected)
                pytest.fail(
                    f"run_test did not raise an exception for "
                    f"{call_string(f, args, kwargs, color=None)} "
                    f"with expected = {repr(expected)} and "
                    f"whaterror = {repr(whaterror)}."
                )
    except Exception as spectacular_exception:
        raise Exception(
            f"An unexpected exception was raised while running "
            f"{call_string(f, args, kwargs, color=None)} with "
            f"expected = {repr(expected)} and "
            f"whaterror = {repr(whaterror)}."
        ) from spectacular_exception
Exemple #5
0
def test_IonizationState_exceptions(test):
    """
    Test that appropriate exceptions are raised for inappropriate inputs
    to `IonizationState`.
    """
    run_test(
        IonizationState,
        kwargs=tests_for_exceptions[test].inputs,
        expected_outcome=tests_for_exceptions[test].expected_exception,
    )
Exemple #6
0
def test_exceptions_upon_instantiation(test_name):
    """
    Test that appropriate exceptions are raised for inappropriate inputs
    to IonizationStates when first instantiated.
    """
    run_test(
        IonizationStates,
        kwargs=tests_for_exceptions[test_name].inputs,
        expected_outcome=tests_for_exceptions[test_name].expected_exception,
    )
Exemple #7
0
def test_run_test_atol():
    run_test(return_arg, 1.0, {}, 0.999999, atol=1.1e-6, rtol=0.0)
Exemple #8
0
def test_is_roman_numeral(input, expected):
    run_test(func=roman.is_roman_numeral,
             args=input,
             expected_outcome=expected)
Exemple #9
0
def test_run_test_rtol_failure():
    with pytest.raises(UnexpectedResultFail):
        run_test(return_arg, 1.0, {}, 0.999999, rtol=1e-7)
        pytest.fail("No exception raised for rtol test.")
Exemple #10
0
def test_nuclear_table(tested_object, args, kwargs, expected_value):
    run_test(tested_object, args, kwargs, expected_value, rtol=1e-3)
Exemple #11
0
def test_to_roman(integer, roman_numeral):
    """
    Test that `~plasmapy.utils.roman.to_roman` correctly converts
    integers to Roman numerals.
    """
    run_test(func=roman.to_roman, args=integer, expected_outcome=roman_numeral)
Exemple #12
0
def test_atomic_functions(inputs):
    print(inputs)
    run_test(inputs)
Exemple #13
0
def test_run_test_atol_failure():
    with pytest.raises(UnexpectedResultError):
        run_test(return_arg, (1.0, ), {}, 0.999999, atol=1e-7)
        pytest.fail("No exception raised for atol test.")
Exemple #14
0
def test_func(inputs):
    """Test cases originally put in the docstring."""
    run_test(inputs)
Exemple #15
0
def test_functions_and_values(tested_function, args, kwargs, expected_output):
    run_test(tested_function, args, kwargs, expected_output)
Exemple #16
0
def test_run_test_rtol():
    run_test(return_arg, 1.0, {}, 0.999999, rtol=1.1e-6)
Exemple #17
0
def test_is_roman_numeral(argument, expected):
    run_test(func=roman.is_roman_numeral, args=argument, expected_outcome=expected)
Exemple #18
0
def test_to_roman_exceptions(function, argument, expected_exception):
    """
    Test that `~plasmapy.utils.roman` functions raise the correct
    exceptions when necessary.
    """
    run_test(func=function, args=argument, expected_outcome=expected_exception)
Exemple #19
0
def test_nuclear(test_inputs):
    run_test(*test_inputs, rtol=1e-3)