Skip to content

Commit

Permalink
added tempfile dependency for better file handling in tests
Browse files Browse the repository at this point in the history
added demo of `set_speed_set_for_train_type`
  • Loading branch information
calbaker committed Apr 12, 2024
1 parent 81b2293 commit 669a0a7
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 22 deletions.
3 changes: 2 additions & 1 deletion python/altrios/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cars_empty=50,
cars_loaded=50,
rail_vehicle_type="Manifest",
train_type=alt.TrainType.Freight,
train_type=None,
train_length_meters=None,
train_mass_kilograms=None,
)
Expand Down Expand Up @@ -66,6 +66,7 @@

network = alt.Network.from_file(
alt.resources_root() / "networks/Taconite.yaml")
network.set_speed_set_for_train_type(alt.TrainType.Freight)
link_path = alt.LinkPath.from_csv_file(
alt.resources_root() / "demo_data/link_points_idx.csv"
)
Expand Down
157 changes: 139 additions & 18 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/altrios-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ serde-this-or-that = "0.4.2"
project-root = "0.2.2"
eng_fmt = { workspace = true }
directories = "5.0.1"
tempfile = "3.10.1"

[features]
pyo3 = ["dep:pyo3"]
8 changes: 5 additions & 3 deletions rust/altrios-core/src/track/link/link_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,11 @@ mod tests {
fn test_to_and_from_file_for_links() {
// TODO: make use of `tempfile` or similar crate
let links = Vec::<Link>::valid();
links.to_file("links_test2.yaml").unwrap();
assert_eq!(Vec::<Link>::from_file("links_test2.yaml").unwrap(), links);
std::fs::remove_file("links_test2.yaml").unwrap();
let tempdir = tempfile::tempdir().unwrap();
let temp_file_path = tempdir.path().join("links_test2.yaml");
links.to_file(temp_file_path.clone()).unwrap();
assert_eq!(Vec::<Link>::from_file(temp_file_path).unwrap(), links);
tempdir.close().unwrap();
}

#[test]
Expand Down

0 comments on commit 669a0a7

Please sign in to comment.