forked from sherpa/sherpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_chips_unit.py
96 lines (82 loc) · 2.45 KB
/
test_chips_unit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# Copyright (C) 2016, 2018, 2019 Smithsonian Astrophysical Observatory
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import pytest
from sherpa.utils.testing import requires_data, requires_fits
import importlib
def assert_chips_called(chips):
"""
Just make sure the mock is being called once. At this point we are not too
concerned about the correctness of the calls. We are assuming the code works.
Parameters
----------
chips : the mock object backing the tests
"""
chips.lock.assert_any_call()
chips.unlock.assert_any_call()
@pytest.fixture
def chips(mock_chips):
return mock_chips[1]
@pytest.fixture(autouse=True)
def ui(mock_chips):
"""
Load and return the sherpa.astro.ui module
"""
from sherpa.astro import ui
importlib.reload(ui)
return ui
@pytest.fixture(autouse=True)
def clean_up(request, ui):
def fin():
ui.clean()
request.addfinalizer(fin)
@pytest.fixture(autouse=True)
def load_data(ui, make_data_path):
"""
Load dataset before every test.
"""
ui.load_data(make_data_path("3c273.pi"))
ui.set_source("powlaw1d.p")
ui.set_bkg_model("const1d.c")
ui.fit()
@requires_data
@requires_fits
@pytest.mark.parametrize("call, args", [
("model", ()),
("arf", ()),
("source", ()),
("bkg", ()),
("bkg_model", ()),
("bkg_resid", ()),
("bkg_ratio", ()),
("bkg_delchi", ()),
("bkg_chisqr", ()),
("bkg_fit", ()),
("bkg_source", ()),
("energy_flux", ()),
("photon_flux", ()),
("bkg_fit_resid", ()),
("bkg_fit_delchi", ()),
("source_component", (1, "p")),
("model_component", (1, "p")),
("order", (1,)),
])
def test_plot(call, args, chips, ui):
function = getattr(ui, "plot_" + call)
function(*args)
assert_chips_called(chips)