Skip to content

Commit

Permalink
Fixes to logging tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccully committed Aug 10, 2023
1 parent 20f7537 commit aac4b21
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
2 changes: 1 addition & 1 deletion banzai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def parse_args(settings, extra_console_arguments=None, parser_description='Proce
parser.add_argument('--no-bpm', dest='no_bpm', default=False, action='store_true',
help='Do not use a bad pixel mask to reduce data (BPM contains all zeros)')
parser.add_argument('--use-only-older-calibrations', dest='use_only_older_calibrations', default=False,
action='store_true',
action='store_true',
help='Only use calibrations that were created before the start of the block')
parser.add_argument('--preview-mode', dest='preview_mode', default=False, action='store_true',
help='Save the reductions to the preview directory')
Expand Down
41 changes: 16 additions & 25 deletions banzai/tests/test_header_checker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mock
import pytest

from banzai.tests.utils import FakeLCOObservationFrame, FakeContext
Expand Down Expand Up @@ -53,61 +52,53 @@ def test_one_keyword_missing_and_one_na():
assert set(bad_keywords) == set(tester.expected_header_keywords[0:2])


def test_ra_outside_range():
logger.error = mock.MagicMock()
def test_ra_outside_range(caplog):
tester = HeaderChecker(FakeContext())
tester.check_ra_range(FakeHeaderImage({'CRVAL1': 360.1}))
assert logger.error.called
assert any(record.levelname == 'ERROR' for record in caplog.records)


def test_ra_within_range():
logger.error = mock.MagicMock()
def test_ra_within_range(caplog):
tester = HeaderChecker(FakeContext())
tester.check_ra_range(FakeHeaderImage({'CRVAL1': 359.9}))
tester.check_ra_range(FakeHeaderImage({'CRVAL1': 0.1}))
assert not logger.error.called
assert not any(record.levelname == 'INFO' for record in caplog.records)


def test_dec_outside_range():
logger.error = mock.MagicMock()
def test_dec_outside_range(caplog):
tester = HeaderChecker(FakeContext())
tester.check_dec_range(FakeHeaderImage({'CRVAL2': -90.1}))
assert logger.error.called
assert any(record.levelname == 'ERROR' for record in caplog.records)


def test_dec_within_range():
logger.error = mock.MagicMock()
def test_dec_within_range(caplog):
tester = HeaderChecker(FakeContext())
tester.check_dec_range(FakeHeaderImage({'CRVAL2': -89.9}))
tester.check_dec_range(FakeHeaderImage({'CRVAL2': 89.9}))
tester.check_dec_range(FakeHeaderImage({'CRVAL2': 0.0}))
assert not logger.error.called
assert not any(record.levelname == 'ERROR' for record in caplog.records)


def test_null_exptime_value():
logger.error = mock.MagicMock()
def test_null_exptime_value(caplog):
tester = HeaderChecker(FakeContext())
tester.check_exptime_value(FakeHeaderImage({'EXPTIME': 0.0, 'OBSTYPE': 'test'}))
assert logger.error.called
assert any(record.levelname == 'ERROR' for record in caplog.records)


def test_negative_exptime_value():
logger.error = mock.MagicMock()
def test_negative_exptime_value(caplog):
tester = HeaderChecker(FakeContext())
tester.check_exptime_value(FakeHeaderImage({'EXPTIME': -0.1, 'OBSTYPE': 'test'}))
assert logger.error.called
assert any(record.levelname == 'ERROR' for record in caplog.records)


def test_null_or_negative_exptime_value_for_bias():
logger.error = mock.MagicMock()
def test_null_or_negative_exptime_value_for_bias(caplog):
tester = HeaderChecker(FakeContext())
tester.check_exptime_value(FakeHeaderImage({'EXPTIME': 0.0, 'OBSTYPE': 'BIAS'}))
tester.check_exptime_value(FakeHeaderImage({'EXPTIME': -0.1, 'OBSTYPE': 'BIAS'}))
assert not logger.error.called
assert not any(record.levelname == 'ERROR' for record in caplog.records)


def test_postive_exptime_value():
logger.error = mock.MagicMock()
def test_postive_exptime_value(caplog):
tester = HeaderChecker(FakeContext())
tester.check_exptime_value(FakeHeaderImage({'EXPTIME': 0.1, 'OBSTYPE': 'test'}))
assert not logger.error.called
assert not any(record.levelname == 'ERROR' for record in caplog.records)
8 changes: 3 additions & 5 deletions banzai/tests/test_pattern_noise_qc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import mock
import numpy as np

from banzai.qc import pattern_noise
Expand Down Expand Up @@ -44,7 +43,7 @@ def test_pattern_noise_detects_noise_when_it_should(set_random_seed):
def test_pattern_noise_does_not_detect_white_noise(set_random_seed):
data = generate_data()
detector = pattern_noise.PatternNoiseDetector(None)
assert detector.check_for_pattern_noise(data)[0] == False
assert not detector.check_for_pattern_noise(data)[0]


def test_pattern_noise_does_not_detect_stars(set_random_seed):
Expand All @@ -58,13 +57,12 @@ def test_pattern_noise_does_not_detect_stars(set_random_seed):
assert detector.check_for_pattern_noise(data)[0] == False


def test_pattern_noise_on_2d_image(set_random_seed):
def test_pattern_noise_on_2d_image(set_random_seed, caplog):
image = FakeLCOObservationFrame(hdu_list=[FakeCCDData(data=generate_data(has_pattern_noise=True))])

detector = pattern_noise.PatternNoiseDetector(None)
logger.error = mock.MagicMock()
detector.do_stage(image)
assert logger.error.called
assert any(record.levelname == 'ERROR' for record in caplog.records)


def test_trim_edges():
Expand Down
2 changes: 1 addition & 1 deletion banzai/utils/realtime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def need_to_process_image(file_info, context):
if 'frameid' in file_info:
try:
factory = import_utils.import_attribute(context.FRAME_FACTORY)()
test_image = factory.observation_frame_class(hdu_list=[HeaderOnly(file_info)],
test_image = factory.observation_frame_class(hdu_list=[HeaderOnly(file_info)],
file_path=file_info['filename'])
test_image.instrument = factory.get_instrument_from_header(file_info, db_address=context.db_address)
if image_utils.get_reduction_level(test_image.meta) != '00':
Expand Down

0 comments on commit aac4b21

Please sign in to comment.