Skip to content

Commit

Permalink
Change pytestconfig to request.config (tardis-sn#1190)
Browse files Browse the repository at this point in the history
* Change `pytestconfig` to `request.config`

* Removed docstring by mistake. Fixed.
  • Loading branch information
epassaro authored Jul 6, 2020
1 parent 3278e37 commit 99ee417
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
8 changes: 4 additions & 4 deletions tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ def pytest_addoption(parser):


@pytest.fixture(scope="session")
def generate_reference(pytestconfig):
option = pytestconfig.getvalue("generate_reference")
def generate_reference(request):
option = request.config.getoption("--generate-reference")
if option is None:
return False
else:
return option


@pytest.fixture(scope="session")
def tardis_ref_path(pytestconfig):
tardis_ref_path = pytestconfig.getvalue("tardis_refdata")
def tardis_ref_path(request):
tardis_ref_path = request.config.getoption("--tardis-refdata")
if tardis_ref_path is None:
pytest.skip("--tardis-refdata was not specified")
else:
Expand Down
29 changes: 16 additions & 13 deletions tardis/montecarlo/tests/test_packet_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@

@pytest.fixture
def data_path():
return os.path.join(tardis.__path__[0], 'montecarlo', 'tests', 'data')
return os.path.join(tardis.__path__[0], "montecarlo", "tests", "data")


@pytest.fixture
def packet_unit_test_fpath(tardis_ref_path):
return os.path.abspath(os.path.join(
tardis_ref_path, 'packet_unittest.h5'))
return os.path.abspath(os.path.join(tardis_ref_path, "packet_unittest.h5"))


def test_bb_packet_sampling(pytestconfig, tardis_ref_data, packet_unit_test_fpath):
def test_bb_packet_sampling(request, tardis_ref_data, packet_unit_test_fpath):
bb = BlackBodySimpleSource(2508)
#ref_df = pd.read_hdf('test_bb_sampling.h5')
if pytestconfig.getvalue("--generate-reference"):
ref_bb = pd.read_hdf(packet_unit_test_fpath, key='/blackbody')
ref_bb.to_hdf(tardis_ref_data, key='/packet_unittest/blackbody',
mode='a')
# ref_df = pd.read_hdf('test_bb_sampling.h5')
if request.config.getoption("--generate-reference"):
ref_bb = pd.read_hdf(packet_unit_test_fpath, key="/blackbody")
ref_bb.to_hdf(
tardis_ref_data, key="/packet_unittest/blackbody", mode="a"
)

ref_df = tardis_ref_data['/packet_unittest/blackbody']
ref_df = tardis_ref_data["/packet_unittest/blackbody"]
nus = bb.create_blackbody_packet_nus(10000, 100)
mus = bb.create_zero_limb_darkening_packet_mus(100)
unif_energies = bb.create_uniform_packet_energies(100)
assert np.all(np.isclose(nus, ref_df['nus']))
assert np.all(np.isclose(mus, ref_df['mus']))
assert np.all(np.isclose(unif_energies, ref_df['energies']))
assert np.all(np.isclose(nus, ref_df["nus"]))
assert np.all(np.isclose(mus, ref_df["mus"]))
assert np.all(np.isclose(unif_energies, ref_df["energies"]))

6 changes: 2 additions & 4 deletions tardis/plasma/tests/test_complete_plasmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,10 @@ def config(self, request):
return config

@pytest.fixture(scope="class")
def plasma(
self, pytestconfig, chianti_he_db_fpath, config, tardis_ref_data
):
def plasma(self, request, chianti_he_db_fpath, config, tardis_ref_data):
config["atom_data"] = chianti_he_db_fpath
sim = Simulation.from_config(config)
if pytestconfig.getvalue("--generate-reference"):
if request.config.getoption("--generate-reference"):
sim.plasma.to_hdf(tardis_ref_data, path=config.plasma.save_path)
pytest.skip("Reference data saved at {0}".format(tardis_ref_data))
return sim.plasma
Expand Down
6 changes: 3 additions & 3 deletions tardis/tests/integration_tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ def model_quantities(request):
@pytest.mark.integration
class TestIntegration(object):
"""Slow integration test for various setups present in subdirectories of
``tardis/tests/integration_tests``.
``tardis/tests/integration_tests``.
"""

@classmethod
@pytest.fixture(scope="class", autouse=True)
def setup(self, request, reference, data_path, pytestconfig):
def setup(self, request, reference, data_path):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
"""
# Get capture manager
capmanager = pytestconfig.pluginmanager.getplugin("capturemanager")
capmanager = request.config.pluginmanager.getplugin("capturemanager")

# The last component in dirpath can be extracted as name of setup.
self.name = data_path["setup_name"]
Expand Down

0 comments on commit 99ee417

Please sign in to comment.