nautilus_persistence/test_data.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Rust custom data types used for catalog roundtrip testing.
17//!
18//! Exposed to Python via the persistence PyO3 module so Python tests can exercise
19//! custom data write/query roundtrips.
20
21use nautilus_core::{Params, UnixNanos};
22use nautilus_model::identifiers::InstrumentId;
23use nautilus_persistence_macros::custom_data;
24
25/// A simple Rust custom data type for roundtrip testing.
26///
27/// Used in persistence integration tests (`test_catalog.rs`) and Python roundtrip tests.
28/// Tests call `ensure_custom_data_registered::<RustTestCustomData>()` before using the catalog.
29#[custom_data(pyo3)]
30pub struct RustTestCustomData {
31 pub instrument_id: InstrumentId,
32 pub value: f64,
33 pub flag: bool,
34 pub ts_event: UnixNanos,
35 pub ts_init: UnixNanos,
36}
37
38/// YieldCurveData-equivalent custom data type using the macro with `Vec<f64>` fields.
39///
40/// Tests `Vec<f64>` / ListFloat64 support. Exposed to Python for roundtrip tests.
41#[custom_data(pyo3)]
42pub struct MacroYieldCurveData {
43 pub curve_name: String,
44 pub tenors: Vec<f64>,
45 pub interest_rates: Vec<f64>,
46 pub ts_event: UnixNanos,
47 pub ts_init: UnixNanos,
48}
49
50/// Rust custom data type that exercises `Params` field support in the macro.
51#[custom_data(pyo3)]
52pub struct RustTestParamsCustomData {
53 pub name: String,
54 pub params: Params,
55 pub ts_event: UnixNanos,
56 pub ts_init: UnixNanos,
57}
58
59#[cfg(test)]
60mod tests {
61 use arrow::datatypes::DataType;
62 use nautilus_serialization::arrow::ArrowSchemaProvider;
63 use rstest::rstest;
64
65 use super::*;
66
67 #[rstest]
68 fn test_macro_yield_curve_data_schema_has_ts_init() {
69 let schema = MacroYieldCurveData::get_schema(None);
70 let field_names: Vec<_> = schema.fields().iter().map(|f| f.name().clone()).collect();
71 assert!(
72 field_names.iter().any(|f| f == "ts_init"),
73 "Schema must have ts_init for DataFusion ORDER BY; got: {field_names:?}",
74 );
75 assert!(
76 field_names.iter().any(|f| f == "ts_event"),
77 "Schema must have ts_event; got: {field_names:?}",
78 );
79 }
80
81 #[rstest]
82 fn test_rust_test_params_custom_data_schema_uses_utf8_for_params() {
83 let schema = RustTestParamsCustomData::get_schema(None);
84 let params_field = schema.field_with_name("params").unwrap();
85
86 assert_eq!(params_field.data_type(), &DataType::Utf8);
87 }
88}