Newer
Older
import glob
import importlib.util
import parameterized
import pytest
import shutil
import logging
bilby.core.utils.command_line_args.clean = True
core_examples = glob.glob("examples/core_examples/*.py")
core_examples += glob.glob("examples/core_examples/*/*.py")
core_args = [(fname.split("/")[-1][:-3], fname) for fname in core_examples]
gw_examples = [
"examples/gw_examples/injection_examples/fast_tutorial.py",
"examples/gw_examples/data_examples/GW150914.py",
]
gw_args = [(fname.split("/")[-1][:-3], fname) for fname in gw_examples]
def _execute_file(name, fname):
print("Running {}".format(fname))
spec = importlib.util.spec_from_file_location(name, fname)
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = os.path.abspath(os.path.join(dir_path, os.path.pardir))
@classmethod
def setUpClass(cls):
if os.path.isdir(cls.outdir):
logging.warning("{} not removed prior to tests".format(cls.outdir))
def tearDownClass(cls):
if os.path.isdir(cls.outdir):
logging.warning("{} not removed prior to tests".format(cls.outdir))
@parameterized.parameterized.expand(core_args)
def test_core_examples(self, name, fname):
bilby.core.utils.command_line_args.bilby_test_mode = False
ignore = ["15d_gaussian"]
if any([item in fname for item in ignore]):
pytest.skip()
_execute_file(name, fname)
@parameterized.parameterized.expand(gw_args)
def test_gw_examples(self, name, fname):
""" Loop over examples to check they run """
bilby.core.utils.command_line_args.bilby_test_mode = True
_execute_file(name, fname)