use satkit::spaceweather;
use satkit::utils::datadir;
use satkit::Instant;
fn sw_bytes() -> Option<Vec<u8>> {
let path = datadir().ok()?.join("SW-All.csv");
std::fs::read(path).ok()
}
#[test]
fn init_from_bytes_replaces_and_query_works() {
let Some(bytes) = sw_bytes() else {
eprintln!(
"skipping: SW-All.csv not available in datadir(); \
run `python -m satkit.utils.update_datafiles` or set SATKIT_DATA"
);
return;
};
spaceweather::init_from_bytes(&bytes).expect("init_from_bytes should succeed on first call");
let tm = Instant::from_datetime(2023, 11, 14, 0, 0, 0.0).unwrap();
let r1 = spaceweather::get(&tm).expect("get() should find a record for 2023-11-14");
spaceweather::init_from_bytes(&bytes)
.expect("second init_from_bytes should succeed (refreshable subsystem)");
let r2 = spaceweather::get(&tm).expect("get() after reload");
assert_eq!(r1.date, r2.date);
assert_eq!(r1.f10p7_obs, r2.f10p7_obs);
}