def test_implementations__do_not_smoke() -> None:
    implementations = mandelbrot.all_implementations()
    dummy_args = mandelbrot.ParsedArgs(
        grid_side_size=1,
        max_iter=1,
        plot=False,
    )

    for impl in implementations:
        kwargs = dataclasses.asdict(dummy_args)
        kwargs.pop("plot")
        _ = impl.callable(**kwargs)
예제 #2
0
def test_all_implementations__correctly_wraps_the_trivial_implementation(
) -> None:
    ids_to_impls = {
        impl.id_: impl
        for impl in mandelbrot.all_implementations()
    }
    trivial_impl = ids_to_impls["trivial"]

    assert mandelbrot.Implementation(
        id_=mandelbrot.ImplementationID("trivial"),
        callable=mandelbrot.implementations.trivial.main,
        fully_qualified_name="mandelbrot.implementations.trivial.main",
    ) == trivial_impl
예제 #3
0
"""
Simple CPU profiling of Python scripts in :mod:`mandelbrot.implementations`
using :mod:`cProfile`.
"""

import cProfile
import pstats
import tempfile

import mandelbrot

if __name__ == "__main__":
    args = mandelbrot.parsed_mandelbrot_args()

    for impl in mandelbrot.all_implementations():
        cmd = (
            f"{impl.fully_qualified_name}(grid_side_size={args.grid_side_size}, "
            f"max_iter={args.max_iter})")
        print(f"About to profile {cmd}")
        with tempfile.NamedTemporaryFile() as tmp_stats_file:
            cProfile.run(cmd, filename=tmp_stats_file.name)
            stats = pstats.Stats(tmp_stats_file.name)

            stats.sort_stats(
                pstats.SortKey.CUMULATIVE)  # type: ignore  # MyPy's wrong
            stats.print_title()
            stats.print_stats()
            print("Callers:")
            stats.print_callers()
예제 #4
0
def test_all_implementations__contains_expected_implementations() -> None:
    expected_implementations = {"trivial", "numexpr_based", "numpy_based"}
    assert expected_implementations <= {
        impl.id_
        for impl in mandelbrot.all_implementations()
    }
예제 #5
0
def test_all_implementations__is_not_smoking() -> None:
    assert len(mandelbrot.all_implementations())