From 3ec4f98c4094cff6306d6b958e92d7e25ac7f837 Mon Sep 17 00:00:00 2001 From: Vaibhav Gupta Date: Fri, 11 Aug 2017 18:40:44 +0530 Subject: [PATCH] Use plasma as a class level fixture in tests --- tardis/plasma/tests/test_complete_plasmas.py | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tardis/plasma/tests/test_complete_plasmas.py b/tardis/plasma/tests/test_complete_plasmas.py index 4473d23e768..5b43fb417fa 100644 --- a/tardis/plasma/tests/test_complete_plasmas.py +++ b/tardis/plasma/tests/test_complete_plasmas.py @@ -11,22 +11,22 @@ class BasePlasmaTest(object): #Class defining all common tests for different setups of Plasma #This can then be inherited for different Plasma setup - @classmethod + @pytest.fixture(scope="class", autouse=True) - def setup(cls, atomic_data_fname, tardis_ref_path, reference_file_path, config_path): - cls.config = Configuration.from_yaml(config_path) - cls.config['atom_data'] = atomic_data_fname - cls.sim = Simulation.from_config(cls.config) + def plasma(self, atomic_data_fname, tardis_ref_path, reference_file_path, config_path): + self.config = Configuration.from_yaml(config_path) + self.config['atom_data'] = atomic_data_fname + self.sim = Simulation.from_config(self.config) if pytest.config.getvalue("--generate-reference"): if os.path.exists(reference_file_path): pytest.skip( 'Reference data {0} does exist and tests will not ' 'proceed generating new data'.format(reference_file_path)) - cls.sim.plasma.to_hdf(reference_file_path) + self.sim.plasma.to_hdf(reference_file_path) pytest.skip("Reference data saved at {0}".format( reference_file_path)) - cls.plasma = cls.sim.plasma + return self.sim.plasma @pytest.fixture(scope="class") def reference_file_path(self): @@ -54,14 +54,14 @@ def config_path(self): j_blues_properties @pytest.mark.parametrize("attr", combined_properties) - def test_plasma_properties(self, reference_file_path, attr): - actual = getattr(self.plasma, attr) + def test_plasma_properties(self, reference_file_path, plasma, attr): + actual = getattr(plasma, attr) expected = pd.read_hdf(reference_file_path, os.path.join('plasma', attr)) assert_almost_equal(actual, expected.values) - def test_levels(self, reference_file_path): - actual = pd.DataFrame(self.plasma.levels) + def test_levels(self, reference_file_path, plasma): + actual = pd.DataFrame(plasma.levels) expected = pd.read_hdf(reference_file_path, os.path.join('plasma', 'levels')) pdt.assert_almost_equal(actual, expected) @@ -69,16 +69,16 @@ def test_levels(self, reference_file_path): scalars_properties = ['time_explosion', 'link_t_rad_t_electron'] @pytest.mark.parametrize("attr", scalars_properties) - def test_scalars_properties(self, reference_file_path, attr): - actual = getattr(self.plasma, attr) + def test_scalars_properties(self, reference_file_path, plasma, attr): + actual = getattr(plasma, attr) if hasattr(actual, 'cgs'): actual = actual.cgs.value expected = pd.read_hdf(reference_file_path, os.path.join( 'plasma', 'scalars'))[attr] assert_almost_equal(actual, expected) - def test_helium_treatment(self, reference_file_path): - actual = self.plasma.helium_treatment + def test_helium_treatment(self, reference_file_path, plasma): + actual = plasma.helium_treatment expected = pd.read_hdf(reference_file_path, os.path.join( 'plasma', 'scalars'))['helium_treatment'] assert actual == expected @@ -115,8 +115,8 @@ def config_path(self): nlte_ion_population_properties + nlte_radiative_properties @pytest.mark.parametrize("attr", nlte_properties) - def test_nlte_properties(self, reference_file_path, attr): - actual = getattr(self.plasma, attr) + def test_nlte_properties(self, reference_file_path, plasma, attr): + actual = getattr(plasma, attr) expected = pd.read_hdf(reference_file_path, os.path.join('plasma', attr)) assert_almost_equal(actual, expected.values)