Skip to content

Commit

Permalink
Testing: add isinstance asserts to plot tests
Browse files Browse the repository at this point in the history
Add several checks to ensure that the plot object returned by a
get_xxx_plot() call has the expected class. These were not made
before because the mocking done to support chips testing meant that
the tests would fail (thanks to the mocking). As this has now been
removed add back the instance checks.

Note that these tests don't really add that much, so they are not
essential.
  • Loading branch information
DougBurke committed Jan 24, 2020
1 parent 1b7e00c commit d63ea35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
21 changes: 11 additions & 10 deletions sherpa/astro/ui/tests/test_astro_ui_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2019 Smithsonian Astrophysical Observatory
# Copyright (C) 2019, 2020 Smithsonian Astrophysical Observatory
#
#
# This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -34,9 +34,8 @@

from sherpa.astro import ui

# the chips plot tests mean that we can't test the plot instances
# (because of the mocking that the chips tests do)
# from sherpa.plot import DataPlot, FitPlot, ModelPlot
from sherpa.astro.plot import ARFPlot, BkgDataPlot, ModelHistogram, \
SourcePlot

from sherpa.utils.err import IdentifierErr
from sherpa.utils.testing import requires_data, requires_fits, \
Expand Down Expand Up @@ -252,12 +251,6 @@ def setup_example_bkg_model(idval):
"""


# The following tests do not check whether returned values are
# of the expected class instance, since the chips plot tests
# use a mock object and so mess-up simple "isinstance(x, ModelPlot)"
# checks.
#

@pytest.mark.usefixtures("clean_astro_ui")
@pytest.mark.parametrize("idval", [None, 1, "one", 23])
def test_get_arf_plot(idval):
Expand All @@ -270,6 +263,8 @@ def test_get_arf_plot(idval):
else:
ap = ui.get_arf_plot(idval)

assert isinstance(ap, ARFPlot)

assert ap.xlo == pytest.approx(_energies[:-1])
assert ap.xhi == pytest.approx(_energies[1:])

Expand All @@ -294,6 +289,8 @@ def test_get_bkg_plot(idval):
else:
bp = ui.get_bkg_plot(idval)

assert isinstance(bp, BkgDataPlot)

assert bp.x == pytest.approx(_data_chan)

# normalise by exposure time and bin width, but bin width here
Expand Down Expand Up @@ -376,6 +373,8 @@ def test_get_model_plot(idval):
else:
mp = ui.get_model_plot(idval)

assert isinstance(mp, ModelHistogram)

assert mp.xlo == pytest.approx(_data_chan)
assert mp.xhi == pytest.approx(_data_chan + 1)

Expand Down Expand Up @@ -462,6 +461,8 @@ def test_get_source_plot_energy(idval):
ui.set_analysis(idval, 'energy')
sp = ui.get_source_plot(idval)

assert isinstance(sp, SourcePlot)

assert sp.xlo == pytest.approx(_energies[:-1])
assert sp.xhi == pytest.approx(_energies[1:])

Expand Down
17 changes: 5 additions & 12 deletions sherpa/ui/tests/test_ui_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2019 Smithsonian Astrophysical Observatory
# Copyright (C) 2019, 2020 Smithsonian Astrophysical Observatory
#
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -24,8 +24,7 @@

from sherpa import ui

# the chips plot tests mean that we can't test the plot instances
# from sherpa.plot import DataPlot, FitPlot, ModelPlot
from sherpa.plot import DataPlot, FitPlot, ModelPlot

from sherpa.stats import Chi2Gehrels
from sherpa.utils.testing import requires_plotting
Expand Down Expand Up @@ -100,15 +99,9 @@ def test_get_fit_plot(idval):
else:
f = ui.get_fit_plot(idval)

# Should we be checking exact class?
#
# No - because the mock_chips pytest routine redefines these
# classes and so makes the test fail (or at least that's my
# assumption).
#
# assert isinstance(f, FitPlot)
# assert isinstance(f.dataplot, DataPlot)
# assert isinstance(f.modelplot, ModelPlot)
assert isinstance(f, FitPlot)
assert isinstance(f.dataplot, DataPlot)
assert isinstance(f.modelplot, ModelPlot)

dp = f.dataplot
mp = f.modelplot
Expand Down

0 comments on commit d63ea35

Please sign in to comment.