T-112: M1.2ab — tools/curate-etl: third runnable command curate-corporate-actions (concatenated-BSON qmSplits + qmDividends files + provider_mapping TSV + Pass 6 delisting-outcomes TSV → corporate_actions/part.parquet) with end-to-end tests and local benchmark (no new crates, no MongoDB connection)
This commit is contained in:
parent
66efb2030b
commit
3cd35b692f
9 changed files with 3211 additions and 7 deletions
|
|
@ -32,8 +32,13 @@ fn no_args_and_help_print_usage_and_succeed() {
|
|||
assert!(text.contains("Usage:"), "{args:?}: {text}");
|
||||
assert!(text.contains("curate-bars-1d"), "{args:?}: {text}");
|
||||
assert!(text.contains("curate-adj-factors"), "{args:?}: {text}");
|
||||
assert!(text.contains("curate-corporate-actions"), "{args:?}: {text}");
|
||||
assert!(text.contains("bench-curate-bars-cmd"), "{args:?}: {text}");
|
||||
assert!(text.contains("bench-curate-adj-cmd"), "{args:?}: {text}");
|
||||
assert!(
|
||||
text.contains("bench-curate-corporate-actions-cmd"),
|
||||
"{args:?}: {text}"
|
||||
);
|
||||
assert!(text.contains("bench-split"), "{args:?}: {text}");
|
||||
assert!(text.contains("bench-corporate-actions"), "{args:?}: {text}");
|
||||
assert!(text.contains("bench-fx"), "{args:?}: {text}");
|
||||
|
|
@ -863,3 +868,191 @@ fn bench_curate_adj_cmd_small_run_is_deterministic_and_reports_stages() {
|
|||
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
||||
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curate_corporate_actions_cli_flag_errors_exit_nonzero_with_usage() {
|
||||
for args in [
|
||||
&["curate-corporate-actions"][..],
|
||||
&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
"s.bson",
|
||||
"--qm-dividends",
|
||||
"d.bson",
|
||||
"--provider-mapping",
|
||||
"m.tsv",
|
||||
][..],
|
||||
&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
"s.bson",
|
||||
"--qm-splits",
|
||||
"s2.bson",
|
||||
"--qm-dividends",
|
||||
"d.bson",
|
||||
"--provider-mapping",
|
||||
"m.tsv",
|
||||
"--out",
|
||||
"out",
|
||||
][..],
|
||||
&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
"s.bson",
|
||||
"--qm-dividends",
|
||||
"d.bson",
|
||||
"--provider-mapping",
|
||||
"m.tsv",
|
||||
"--delistings",
|
||||
"a.tsv",
|
||||
"--delistings=b.tsv",
|
||||
"--out",
|
||||
"out",
|
||||
][..],
|
||||
&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
"s.bson",
|
||||
"--qm-dividends",
|
||||
"d.bson",
|
||||
"--provider-mapping",
|
||||
"m.tsv",
|
||||
"--out",
|
||||
"out",
|
||||
"--unknown",
|
||||
"1",
|
||||
][..],
|
||||
] {
|
||||
let out = run(args);
|
||||
assert!(!out.status.success(), "{args:?} should fail");
|
||||
assert_eq!(out.status.code(), Some(1), "{args:?}");
|
||||
assert!(stdout(&out).is_empty(), "{args:?} wrote to stdout");
|
||||
let err = stderr(&out);
|
||||
assert!(err.contains("error:"), "{args:?}: {err}");
|
||||
assert!(err.contains("Usage:"), "{args:?}: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn curate_corporate_actions_cli_happy_path_and_single_line_runtime_error() {
|
||||
let dir = CliTempDir::new("corp-actions-cli");
|
||||
let splits_path = dir.path.join("splits.bson");
|
||||
let divs_path = dir.path.join("divs.bson");
|
||||
let map_path = dir.path.join("provider_mapping.tsv");
|
||||
let delist_path = dir.path.join("delistings.tsv");
|
||||
let bad_delist_path = dir.path.join("bad_delistings.tsv");
|
||||
let out_with_delist = dir.path.join("out_with");
|
||||
let out_without_delist = dir.path.join("out_without");
|
||||
let out_fail = dir.path.join("out_fail");
|
||||
|
||||
write_file(
|
||||
&map_path,
|
||||
b"qm\tNVDA:US\t2015-01-01\t\t100\n\
|
||||
qm\tSIVB:US\t2015-01-01\t2023-03-10\t300\n\
|
||||
qm\tSIVBQ:US\t2023-03-28\t\t301\n",
|
||||
);
|
||||
write_file(&splits_path, &make_split_doc("NVDA:US", "2024-06-10", 10.0));
|
||||
write_file(
|
||||
&divs_path,
|
||||
&make_div_doc("NVDA:US", "2024-06-11", 0.01, "USD"),
|
||||
);
|
||||
write_file(&delist_path, b"SIVB:US\t2023-03-28\t300\tSIVBQ:US\t\n");
|
||||
write_file(&bad_delist_path, b"SIVB:US\t2023-03-28\t\tSIVBQ:US\t\n");
|
||||
|
||||
// 1. Happy path with --delistings.
|
||||
let res = run(&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-dividends",
|
||||
divs_path.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--delistings",
|
||||
delist_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_with_delist.to_str().unwrap(),
|
||||
]);
|
||||
assert!(res.status.success(), "{}", stderr(&res));
|
||||
assert!(stderr(&res).is_empty(), "{}", stderr(&res));
|
||||
let text = stdout(&res);
|
||||
assert!(text.contains("curate-etl curate-corporate-actions"), "{text}");
|
||||
assert!(text.contains("rows_loaded=1"), "{text}");
|
||||
assert!(text.contains("rows_written=3"), "{text}");
|
||||
assert!(out_with_delist.join("corporate_actions/part.parquet").is_file());
|
||||
|
||||
// 2. Happy path without --delistings.
|
||||
let res_no = run(&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-dividends",
|
||||
divs_path.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_without_delist.to_str().unwrap(),
|
||||
]);
|
||||
assert!(res_no.status.success(), "{}", stderr(&res_no));
|
||||
assert!(stderr(&res_no).is_empty(), "{}", stderr(&res_no));
|
||||
let text_no = stdout(&res_no);
|
||||
assert!(text_no.contains("rows_loaded=0"), "{text_no}");
|
||||
assert!(text_no.contains("rows_written=2"), "{text_no}");
|
||||
assert!(out_without_delist
|
||||
.join("corporate_actions/part.parquet")
|
||||
.is_file());
|
||||
|
||||
// 3. Runtime error (malformed delistings TSV) -> single-line stderr, no Usage, no output.
|
||||
let res_fail = run(&[
|
||||
"curate-corporate-actions",
|
||||
"--qm-splits",
|
||||
splits_path.to_str().unwrap(),
|
||||
"--qm-dividends",
|
||||
divs_path.to_str().unwrap(),
|
||||
"--provider-mapping",
|
||||
map_path.to_str().unwrap(),
|
||||
"--delistings",
|
||||
bad_delist_path.to_str().unwrap(),
|
||||
"--out",
|
||||
out_fail.to_str().unwrap(),
|
||||
]);
|
||||
assert!(!res_fail.status.success());
|
||||
assert_eq!(res_fail.status.code(), Some(1));
|
||||
assert!(stdout(&res_fail).is_empty());
|
||||
let err = stderr(&res_fail);
|
||||
assert_eq!(err.lines().count(), 1, "expected single-line stderr: {err}");
|
||||
assert!(err.contains("bad_delistings.tsv:1:"), "{err}");
|
||||
assert!(!err.contains("Usage:"), "{err}");
|
||||
assert!(!out_fail.join("corporate_actions").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bench_curate_corporate_actions_cmd_small_run_is_deterministic_and_reports_stages() {
|
||||
let a = run(&["bench-curate-corporate-actions-cmd", "2000"]);
|
||||
let b = run(&["bench-curate-corporate-actions-cmd", "2000"]);
|
||||
assert!(a.status.success(), "{}", stderr(&a));
|
||||
assert!(b.status.success(), "{}", stderr(&b));
|
||||
assert!(stderr(&a).is_empty(), "{}", stderr(&a));
|
||||
assert!(stderr(&b).is_empty(), "{}", stderr(&b));
|
||||
|
||||
let text_a = stdout(&a);
|
||||
let text_b = stdout(&b);
|
||||
assert!(
|
||||
text_a.contains("curate-etl bench-curate-corporate-actions-cmd"),
|
||||
"{text_a}"
|
||||
);
|
||||
assert!(text_a.contains("events=2000 "), "{text_a}");
|
||||
assert!(text_a.contains("decode:"), "{text_a}");
|
||||
assert!(text_a.contains("curate:"), "{text_a}");
|
||||
assert!(text_a.contains("write:"), "{text_a}");
|
||||
assert!(text_a.contains("total:"), "{text_a}");
|
||||
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
||||
|
||||
let field = |s: &str, prefix: &str| {
|
||||
s.split_whitespace()
|
||||
.find(|t| t.starts_with(prefix))
|
||||
.map(str::to_owned)
|
||||
};
|
||||
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
||||
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue