def test_sim_conc_dep_no_plot(setup_cte_sim, mocker): '''A plot was requested, but no_plot is set''' setup_cte_sim['no_plot'] = True with temp_bin_filename() as temp_filename: mocked = mocker.patch('simetuc.odesolver._solve_ode') # the num_states changes when the temp lattice is created, # allocate 2x so that we're safe. Also make the num_points 1000. mocked.return_value = np.random.random( (1000, 2 * setup_cte_sim['states']['energy_states'])) sim = simulations.Simulations(setup_cte_sim, full_path=temp_filename) conc_list = [(0.01, 0.3), (0.1, 0.3)] solution = sim.simulate_concentration_dependence(conc_list, dynamics=False) assert mocked.call_count == 2 * len(conc_list) with pytest.warns(plotter.PlotWarning) as warnings: solution.plot() # assert len(warnings) == 1 # one warning warning = warnings.pop(plotter.PlotWarning) assert issubclass(warning.category, plotter.PlotWarning) assert 'A plot was requested, but no_plot setting is set' in str( warning.message) plotter.plt.close('all')
def test_sim_power_dep_no_plot(setup_cte_sim, mocker): '''A plot was requested, but no_plot is set''' setup_cte_sim['no_plot'] = True with temp_bin_filename() as temp_filename: mocked = mocker.patch( 'simetuc.simulations.Simulations.simulate_pulsed_steady_state') mocked.return_value = simulations.SteadyStateSolution( np.empty((1000, )), np.empty((1000, 2 * setup_cte_sim['states']['energy_states'])), [], [], setup_cte_sim) sim = simulations.Simulations(setup_cte_sim, full_path=temp_filename) power_dens_list = np.logspace(1, 2, 3) solution = sim.simulate_power_dependence(power_dens_list) assert mocked.call_count == len(power_dens_list) with pytest.warns(plotter.PlotWarning) as warnings: solution.plot() # assert len(warnings) == 1 # one warning warning = warnings.pop(plotter.PlotWarning) assert issubclass(warning.category, plotter.PlotWarning) assert 'A plot was requested, but no_plot setting is set' in str( warning.message) plotter.plt.close('all')
def test_warn2(): with pytest.warns(None) as warnings: warn() assert len(warnings) == 1 w = warnings.pop() assert w.category == DeprecationWarning
def capture_warnings(*args, **kw): orig_warn(*args, **kw) popwarn = warnings.pop(0) canary.append(popwarn) if regex: assert re.match(popwarn, args[0]) else: eq_(args[0], popwarn)
def test_sim_conc_dep_empty_conc(setup_cte_sim): '''Conc list is empty''' with temp_bin_filename() as temp_filename: sim = simulations.Simulations(setup_cte_sim, full_path=temp_filename) conc_list = [] solution = sim.simulate_concentration_dependence(conc_list) with pytest.warns(plotter.PlotWarning) as warnings: solution.plot() # assert len(warnings) == 1 # one warning warning = warnings.pop(plotter.PlotWarning) assert issubclass(warning.category, plotter.PlotWarning) assert 'Nothing to plot! The concentration_dependence list is emtpy!' in str( warning.message) plotter.plt.close('all')
def test_sim_no_plot(setup_cte_sim): '''Test that no plot works''' setup_cte_sim['no_plot'] = True with temp_bin_filename() as temp_filename: sim = simulations.Simulations(setup_cte_sim, full_path=temp_filename) solution = sim.simulate_dynamics() with pytest.warns(plotter.PlotWarning) as warnings: solution.plot() # assert len(warnings) == 1 # one warning warning = warnings.pop(plotter.PlotWarning) assert issubclass(warning.category, plotter.PlotWarning) assert 'A plot was requested, but no_plot setting is set' in str( warning.message) plotter.plt.close('all')
def capture_warnings(*args, **kw): orig_warn(*args, **kw) popwarn = warnings.pop(0) canary.append(popwarn) eq_(args[0], popwarn)
def capture_warnings(*args, **kw): orig_warn(*args, **kw) popwarn = warnings.pop(0) eq_(args[0], popwarn)