T-198: tests
This commit is contained in:
parent
564f768c8e
commit
2a7485a15c
1 changed files with 216 additions and 1 deletions
|
|
@ -360,7 +360,11 @@ fn cli_publishes_runner_equivalent_fundamentals_and_preserves_pit_restatement()
|
|||
.unwrap()
|
||||
.map(Result::unwrap)
|
||||
.collect();
|
||||
assert_eq!(rows.len(), 4, "expected Q4-23, Q1-24, Q2-24, and Q1-24/A snapshots in 2024");
|
||||
assert_eq!(
|
||||
rows.len(),
|
||||
4,
|
||||
"expected Q4-23, Q1-24, Q2-24, and Q1-24/A snapshots in 2024"
|
||||
);
|
||||
|
||||
let q2_filed_micros =
|
||||
et_to_utc_micros(ymd_to_epoch_days(2024, 8, 5).unwrap(), 16, 15, 0).unwrap();
|
||||
|
|
@ -501,3 +505,214 @@ fn cli_fails_closed_without_creating_out_dir_on_invalid_flags() {
|
|||
"out_from_mongo must not be created"
|
||||
);
|
||||
}
|
||||
|
||||
const FIXTURE_REQUIRED_ARGS: [&str; 14] = [
|
||||
"--qm-financials",
|
||||
"qmFinancials.bson",
|
||||
"--qm-filings",
|
||||
"qmFilings.bson",
|
||||
"--provider-mapping",
|
||||
"provider_mapping.tsv",
|
||||
"--listing-venues",
|
||||
"listing_venues.tsv",
|
||||
"--currency-field",
|
||||
"currency",
|
||||
"--filings-form-type-field",
|
||||
"formType",
|
||||
"--k",
|
||||
"4",
|
||||
];
|
||||
|
||||
fn assert_single_line_error_then_usage(stderr: &[u8], expected_error: &str) {
|
||||
let text = String::from_utf8(stderr.to_vec()).expect("utf-8 stderr");
|
||||
let mut lines = text.lines();
|
||||
assert_eq!(lines.next(), Some(expected_error), "{text}");
|
||||
assert_eq!(lines.next(), Some("Usage:"), "{text}");
|
||||
assert!(
|
||||
text.contains("curate-fundamentals --qm-financials"),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_fixed_fiscal_period_without_metric_fields_matches_runner_and_writes_null_metrics() {
|
||||
let dir = TempDir::new("fixed-null-metrics");
|
||||
let (fin_path, fil_path, map_path, venues_path) = write_restatement_fixture(&dir.0);
|
||||
|
||||
let baseline_dir = dir.0.join("baseline");
|
||||
let baseline_args = CurateFundamentalsArgs::with_verified_defaults(
|
||||
fin_path,
|
||||
fil_path,
|
||||
map_path,
|
||||
venues_path,
|
||||
baseline_dir.clone(),
|
||||
"currency",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
CurateFundamentalsFiscalPeriod::Fixed(curate_etl::fundamentals::FiscalPeriod::Quarterly),
|
||||
"formType",
|
||||
4,
|
||||
);
|
||||
let baseline_report = run_curate_fundamentals(&baseline_args).expect("run library baseline");
|
||||
let expected_report = format_curate_fundamentals_report(&baseline_report);
|
||||
let baseline_partitions = read_parquet_partitions(&baseline_dir);
|
||||
|
||||
let result = cli()
|
||||
.current_dir(&dir.0)
|
||||
.args(FIXTURE_REQUIRED_ARGS)
|
||||
.args(["--out=cli_out", "--fiscal-period=quarterly"])
|
||||
.output()
|
||||
.expect("run curate-fundamentals");
|
||||
assert!(result.status.success(), "{result:?}");
|
||||
assert!(result.stderr.is_empty(), "{result:?}");
|
||||
|
||||
let stdout = String::from_utf8(result.stdout).expect("utf-8 stdout");
|
||||
let actual: Vec<&str> = stdout.lines().collect();
|
||||
let expected: Vec<&str> = expected_report.lines().collect();
|
||||
assert_eq!(actual.len(), expected.len(), "{stdout}");
|
||||
assert_eq!(actual[..actual.len() - 1], expected[..expected.len() - 1]);
|
||||
|
||||
let cli_partitions = read_parquet_partitions(&dir.0.join("cli_out"));
|
||||
assert_eq!(cli_partitions, baseline_partitions);
|
||||
|
||||
let part_2024 = dir
|
||||
.0
|
||||
.join("cli_out/fundamentals_pit/year=2024/part.parquet");
|
||||
let reader = SerializedFileReader::new(File::open(&part_2024).unwrap()).unwrap();
|
||||
let rows: Vec<Row> = reader
|
||||
.get_row_iter(None)
|
||||
.unwrap()
|
||||
.map(Result::unwrap)
|
||||
.collect();
|
||||
assert!(!rows.is_empty(), "expected nonempty 2024 partition");
|
||||
for row in &rows {
|
||||
let revenue = row
|
||||
.get_column_iter()
|
||||
.find(|(name, _)| name.as_str() == "revenue")
|
||||
.expect("revenue column")
|
||||
.1;
|
||||
assert_eq!(revenue, &Field::Null, "unconfigured metric must be NULL");
|
||||
let currency = row
|
||||
.get_column_iter()
|
||||
.find(|(name, _)| name.as_str() == "currency")
|
||||
.expect("currency column")
|
||||
.1;
|
||||
assert_eq!(currency, &Field::Str("USD".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_rerun_into_fresh_out_dir_is_byte_deterministic() {
|
||||
let dir = TempDir::new("rerun");
|
||||
write_restatement_fixture(&dir.0);
|
||||
|
||||
for out in ["run_a", "run_b"] {
|
||||
let result = cli()
|
||||
.current_dir(&dir.0)
|
||||
.args(FIXTURE_REQUIRED_ARGS)
|
||||
.args(["--out", out, "--quarterly-tokens", "Q1,Q2,Q3,Q4"])
|
||||
.args(["--revenue-field", "IncomeStatement.revenue"])
|
||||
.output()
|
||||
.expect("run curate-fundamentals");
|
||||
assert!(result.status.success(), "{result:?}");
|
||||
}
|
||||
|
||||
let a = read_parquet_partitions(&dir.0.join("run_a"));
|
||||
let b = read_parquet_partitions(&dir.0.join("run_b"));
|
||||
assert!(!a.is_empty());
|
||||
assert_eq!(
|
||||
a, b,
|
||||
"identical inputs must publish identical Parquet bytes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_runner_failure_on_missing_input_exits_nonzero_single_line_without_usage_or_output() {
|
||||
let dir = TempDir::new("missing-input");
|
||||
write_restatement_fixture(&dir.0);
|
||||
fs::remove_file(dir.0.join("qmFilings.bson")).unwrap();
|
||||
|
||||
let result = cli()
|
||||
.current_dir(&dir.0)
|
||||
.args(FIXTURE_REQUIRED_ARGS)
|
||||
.args(["--out", "out", "--fiscal-period", "quarterly"])
|
||||
.output()
|
||||
.expect("run curate-fundamentals");
|
||||
|
||||
assert_eq!(result.status.code(), Some(1));
|
||||
assert!(result.stdout.is_empty());
|
||||
let stderr = String::from_utf8(result.stderr).unwrap();
|
||||
assert_eq!(stderr.lines().count(), 1, "{stderr}");
|
||||
assert!(stderr.starts_with("error: "), "{stderr}");
|
||||
assert!(stderr.contains("qmFilings.bson"), "{stderr}");
|
||||
assert!(!stderr.contains("Usage:"), "{stderr}");
|
||||
assert!(!dir.0.join("out").exists(), "out must not be created");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_truncated_financials_dump_fails_closed_without_publishing() {
|
||||
let dir = TempDir::new("truncated");
|
||||
write_restatement_fixture(&dir.0);
|
||||
fs::write(dir.0.join("qmFinancials.bson"), [0x10u8, 0x00, 0x00]).unwrap();
|
||||
|
||||
let result = cli()
|
||||
.current_dir(&dir.0)
|
||||
.args(FIXTURE_REQUIRED_ARGS)
|
||||
.args(["--out", "out", "--fiscal-period", "quarterly"])
|
||||
.output()
|
||||
.expect("run curate-fundamentals");
|
||||
|
||||
assert_eq!(result.status.code(), Some(1));
|
||||
assert!(result.stdout.is_empty());
|
||||
let stderr = String::from_utf8(result.stderr).unwrap();
|
||||
assert_eq!(stderr.lines().count(), 1, "{stderr}");
|
||||
assert!(stderr.starts_with("error: "), "{stderr}");
|
||||
assert!(!dir.0.join("out/fundamentals_pit").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_parse_time_config_errors_fail_closed_before_touching_out() {
|
||||
let dir = TempDir::new("config-errors");
|
||||
write_restatement_fixture(&dir.0);
|
||||
|
||||
let cases: [(&[&str], &str); 4] = [
|
||||
(
|
||||
&["--quarterly-tokens", "Q1,FY", "--annual-tokens", "FY"],
|
||||
"error: invalid qmFinancials fiscal period configuration: report_period token 'FY' cannot appear in both quarterly and annual lists",
|
||||
),
|
||||
(
|
||||
&["--fiscal-period", "quarterly", "--quarterly-tokens", "Q1"],
|
||||
"error: cannot combine '--fiscal-period' with '--quarterly-tokens' or '--annual-tokens'",
|
||||
),
|
||||
(
|
||||
&["--fiscal-period", "quarterly", "--mongo-uri", "mongodb://localhost:27017/stock"],
|
||||
"error: unknown flag '--mongo-uri' for curate-fundamentals",
|
||||
),
|
||||
(
|
||||
&["--fiscal-period", "quarterly", "--k", "0"],
|
||||
"error: duplicate flag '--k'",
|
||||
),
|
||||
];
|
||||
|
||||
for (idx, (extra, expected_error)) in cases.iter().enumerate() {
|
||||
let out = format!("out_{idx}");
|
||||
let result = cli()
|
||||
.current_dir(&dir.0)
|
||||
.args(FIXTURE_REQUIRED_ARGS)
|
||||
.args(["--out", out.as_str()])
|
||||
.args(*extra)
|
||||
.output()
|
||||
.expect("run curate-fundamentals");
|
||||
assert_eq!(result.status.code(), Some(1), "case {idx}");
|
||||
assert!(result.stdout.is_empty(), "case {idx}");
|
||||
assert_single_line_error_then_usage(&result.stderr, expected_error);
|
||||
assert!(
|
||||
!dir.0.join(&out).exists(),
|
||||
"case {idx}: out must not be created"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue