Skip to content

Commit

Permalink
refactor for better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Jan 24, 2025
1 parent 8c73a70 commit 5c0ba39
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum HyperdriveError {
DiCalibrate(String),

/// An error related to peeling.
#[error("{0}\n\nSee for more info: {URL}/*****.html")]
#[error("{0}\n\nSee for more info: {URL}/user/peel/intro.html")]
Peel(String),

/// An error related to solutions-apply.
Expand Down Expand Up @@ -173,6 +173,7 @@ impl From<PeelArgsError> for HyperdriveError {
fn from(e: PeelArgsError) -> Self {
match e {
PeelArgsError::NoOutput
| PeelArgsError::TooManyIonoSub { .. }
| PeelArgsError::ZeroPasses
| PeelArgsError::ZeroLoops
| PeelArgsError::ParseIonoTimeAverageFactor(_)
Expand Down
5 changes: 5 additions & 0 deletions src/cli/peel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub(crate) enum PeelArgsError {
#[error("No calibration output was specified. There must be at least one calibration solution file.")]
NoOutput,

#[error(
"The number of sources to subtract ({total}) is less than the number of sources to iono subtract ({iono})"
)]
TooManyIonoSub { total: usize, iono: usize },

#[error("The number of iono sub passes cannot be 0")]
ZeroPasses,

Expand Down
31 changes: 14 additions & 17 deletions src/cli/peel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,22 @@ impl PeelArgs {
input_vis_params.timeblocks.first().median,
input_vis_params.dut1,
);
if apply_precession {
let srclist = srclist_args.parse(
obs_context.phase_centre,
let (lst_rad, lat_rad) = if apply_precession {
(
precession_info.lmst_j2000,
precession_info.array_latitude_j2000,
&obs_context.get_veto_freqs(),
&*beam,
)?;
(srclist, precession_info.lmst_j2000)
)
} else {
let srclist = srclist_args.parse(
obs_context.phase_centre,
precession_info.lmst,
latitude_rad,
&obs_context.get_veto_freqs(),
&*beam,
)?;
(srclist, precession_info.lmst)
}
(precession_info.lmst, latitude_rad)

Check warning on line 274 in src/cli/peel/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/peel/mod.rs#L274

Added line #L274 was not covered by tests
};
let srclist = srclist_args.parse(
obs_context.phase_centre,
lst_rad,
lat_rad,
&obs_context.get_veto_freqs(),
&*beam,
)?;
(srclist, lst_rad)
};

// Check that the number of sources to peel, iono subtract and subtract
Expand All @@ -292,7 +289,7 @@ impl PeelArgs {
let _max_num_sources = match (num_sources_to_iono_subtract, num_sources_to_subtract) {
(Some(is), Some(s)) => {
if s < is {
panic!("The number of sources to subtract ({s}) must be at least equal to the number of sources to iono subtract ({is})");
return Err(PeelArgsError::TooManyIonoSub { total: s, iono: is }.into());
}
Some(s)
}
Expand Down
18 changes: 17 additions & 1 deletion src/cli/peel/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use crate::{
cli::common::{InputVisArgs, SkyModelWithVetoArgs},
params::{InputVisParams, OutputVisParams, PeelParams},
tests::{get_reduced_1090008640_raw, DataAsStrings},
HyperdriveError,
};

use super::PeelArgs;
use super::{PeelArgs, PeelCliArgs};

#[track_caller]
fn get_reduced_1090008640() -> PeelArgs {
Expand Down Expand Up @@ -203,3 +204,18 @@ fn time_averaging_explicit_output_clip() {
// --output-vis-time-average - output averaging settings
//
// this requires test data with more than one timestep

// testing that parse() catches invalid number of iono sources
#[test]
fn handle_iono_greater_than_total() {
let mut args = get_reduced_1090008640();
args.peel_args = PeelCliArgs {
num_sources_to_iono_subtract: Some(2),
num_sources_to_subtract: Some(1),
..Default::default()
};
match args.parse() {
Err(HyperdriveError::Generic(_)) => {} // expected
_ => panic!("Expected TooManyIonoSub"),

Check warning on line 219 in src/cli/peel/tests.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/peel/tests.rs#L219

Added line #L219 was not covered by tests
};
}

0 comments on commit 5c0ba39

Please sign in to comment.