Skip to content

Commit

Permalink
basic test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 28, 2023
1 parent 9b797c8 commit 1842c0d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lcviz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ def light_curve_like_kepler_quarter(seed=42):

quality = np.zeros(len(time), dtype=np.int32)

return LightCurve(
lc = LightCurve(
time=time, flux=flux, flux_err=flux_err, quality=quality
)
lc['flux_alt'] = flux + 1
lc['flux_alt_err'] = flux_err
return lc


try:
Expand Down
2 changes: 1 addition & 1 deletion lcviz/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw

# handle flux_origin default
flux_origin = light_curve.meta.get('FLUX_ORIGIN', None) # i.e. PDCSAP or SAP
if flux_origin == 'flux':
if flux_origin == 'flux' or (flux_origin is None and 'flux' in light_curve.columns):
# then make a copy of this column so it won't be lost when changing with the flux_column
# plugin
light_curve['flux:orig'] = light_curve['flux']
Expand Down
2 changes: 2 additions & 0 deletions lcviz/plugins/flux_origin/flux_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def _include_col(lk_obj, col):
return lk_obj[col].unit == lk_obj['flux'].unit

lk_obj = self.dataset.selected_obj
if lk_obj is None:
return
self.origin.choices = [col for col in lk_obj.columns if _include_col(lk_obj, col)]
flux_origin = lk_obj.meta.get('FLUX_ORIGIN')
if flux_origin in self.origin.choices:
Expand Down
18 changes: 18 additions & 0 deletions lcviz/tests/test_plugin_flux_origin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from numpy.testing import assert_allclose


def test_plugin_flux_origin(helper, light_curve_like_kepler_quarter):
helper.load_data(light_curve_like_kepler_quarter)

fo = helper.plugins['Flux Origin']
assert len(fo.origin.choices) == 2
assert fo.origin.selected == 'flux:orig'

lc = helper.get_data()
assert lc.meta.get('FLUX_ORIGIN') == 'flux:orig'
assert_allclose(lc['flux'], fo._obj.dataset.selected_dc_item['flux:orig'])

fo.origin = 'flux_alt'
lc = helper.get_data()
assert lc.meta.get('FLUX_ORIGIN') == 'flux_alt'
assert_allclose(lc['flux'], fo._obj.dataset.selected_dc_item['flux_alt'])

0 comments on commit 1842c0d

Please sign in to comment.