Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test_autofit/aggregator/summary_files/test_aggregate_fits.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import importlib.util
from enum import Enum
import pytest

import autofit as af
from pathlib import Path


# `astropy` ships via the `[optional]` extras. Envs installed without them
# must skip rather than fail with `No module named 'astropy'`.
requires_astropy = pytest.mark.skipif(
importlib.util.find_spec("astropy") is None,
reason="requires astropy (installed via the [optional] extras)",
)


pytestmark = requires_astropy


class FITSFit(Enum):
"""
The HDUs that can be extracted from the fit.fits file.
Expand Down
11 changes: 11 additions & 0 deletions test_autofit/aggregator/test_child_analysis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.util
from pathlib import Path

import pytest
Expand All @@ -7,6 +8,14 @@
import autofit as af


# `astropy` ships via the `[optional]` extras. Envs installed without them
# must skip rather than fail with `No module named 'astropy'`.
requires_astropy = pytest.mark.skipif(
importlib.util.find_spec("astropy") is None,
reason="requires astropy (installed via the [optional] extras)",
)


@pytest.fixture(name="directory")
def make_directory():
return Path(__file__).parent
Expand Down Expand Up @@ -50,12 +59,14 @@ def make_aggregator(session, directory):
return aggregator


@requires_astropy
def test_database_aggregator(aggregator):
assert list(aggregator.child_values("example")) == [
["hello world", "hello world"],
]


@requires_astropy
def test_child_values(aggregator):
fit, *_ = list(aggregator)
assert fit.child_values("example") == ["hello world", "hello world"]
14 changes: 14 additions & 0 deletions test_autofit/aggregator/test_reference.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.util
import os

import pytest
Expand All @@ -9,6 +10,14 @@
from autofit.database.aggregator.info import Info


# `astropy` ships via the `[optional]` extras. Envs installed without them
# must skip rather than fail with `No module named 'astropy'`.
requires_astropy = pytest.mark.skipif(
importlib.util.find_spec("astropy") is None,
reason="requires astropy (installed via the [optional] extras)",
)


@pytest.fixture(name="directory")
def make_directory():
return Path(__file__).parent
Expand Down Expand Up @@ -56,6 +65,7 @@ def database_aggregator(
return aggregator


@requires_astropy
def test_database(database_aggregator):
fit = list(database_aggregator)[0]
model = fit.model
Expand All @@ -67,20 +77,24 @@ def make_info(database_aggregator):
return Info(database_aggregator.session)


@requires_astropy
def test_query_fits(info):
fits = info.fits
assert len(info.fits) == 3
assert fits[0].total_parameters == 4


@requires_astropy
def test_headers_and_rows(info):
assert len(info.headers) == len(info.rows[0])


@requires_astropy
def test_info_path(info, output_directory):
assert info.path == output_directory / "database.info"


@requires_astropy
def test_database_info(
database_aggregator,
output_directory,
Expand Down
12 changes: 12 additions & 0 deletions test_autofit/aggregator/test_scrape.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import importlib.util

import pytest

from autofit import SearchOutput
from autofit.database.aggregator.scrape import _add_files


# `astropy` ships via the `[optional]` extras. Envs installed without them
# must skip rather than fail with `No module named 'astropy'`.
requires_astropy = pytest.mark.skipif(
importlib.util.find_spec("astropy") is None,
reason="requires astropy (installed via the [optional] extras)",
)


class MockFit:
def __init__(self):
self.jsons = {}
Expand Down Expand Up @@ -36,6 +46,7 @@ def make_fit(directory):
return fit


@requires_astropy
def test_add_files(fit):
assert fit.jsons["model"] == {
"class_path": "autofit.example.model.Gaussian",
Expand Down Expand Up @@ -63,6 +74,7 @@ def test_add_files(fit):
}


@requires_astropy
def test_add_recursive(fit):
assert fit.jsons["directory.example"] == {
"hello": "world",
Expand Down
8 changes: 8 additions & 0 deletions test_autofit/database/test_file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

from autofit.database import JSON
from autofit import database as db

# `astropy` ships via the `[optional]` extras; skip the module there
# rather than fail collection with `No module named 'astropy'`.
pytest.importorskip(
"astropy",
reason="requires astropy (installed via the [optional] extras)",
)

from astropy.io import fits


Expand Down
10 changes: 9 additions & 1 deletion test_autofit/non_linear/paths/test_save_and_load.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import numpy as np
import pytest
from astropy.io import fits

import autofit as af

# `astropy` ships via the `[optional]` extras; skip the module there
# rather than fail collection with `No module named 'astropy'`.
pytest.importorskip(
"astropy",
reason="requires astropy (installed via the [optional] extras)",
)

from astropy.io import fits


@pytest.fixture(name="dictionary")
def make_dictionary():
Expand Down
12 changes: 12 additions & 0 deletions test_autofit/non_linear/search/nest/test_nautilus.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import importlib.util

import numpy as np
import pytest

import autofit as af

pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")

# The regression test below runs a real `search.fit`, which imports the
# `nautilus` sampler; it ships via the `[optional]` extras. Envs installed
# without those extras must skip rather than fail with
# `No module named 'nautilus'` — the other tests here only read config.
requires_nautilus = pytest.mark.skipif(
importlib.util.find_spec("nautilus") is None,
reason="requires nautilus-sampler (installed via the [optional] extras)",
)


def test__explicit_params():
search = af.Nautilus(
Expand Down Expand Up @@ -54,6 +65,7 @@ def test__test_mode():
assert search.n_like_max == 1


@requires_nautilus
def test__single_core_builds_no_pool(monkeypatch):
"""
number_of_cores=1 must not construct a multiprocessing pool: nautilus
Expand Down
Loading