Skip to content

Commit

Permalink
fix my own mistakes, oops
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarow committed Sep 24, 2024
1 parent 8359f14 commit 6ad2acb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions rust/fastsim-core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Module containing miscellaneous utility functions.

#[cfg(feature = "default")]
use curl::easy::Easy;
#[cfg(feature = "default")]
use directories::ProjectDirs;
use itertools::Itertools;
Expand All @@ -9,8 +11,6 @@ use regex::Regex;
use std::collections::HashSet;
#[cfg(feature = "default")]
use std::io::Write;
#[cfg(feature = "default")]
use curl::easy::Easy;

use crate::imports::*;
#[cfg(feature = "pyo3")]
Expand Down Expand Up @@ -871,13 +871,13 @@ mod tests {
let sub_dir_path = temp_sub_dir.path().to_str().unwrap();
let still_exists_before = std::fs::metadata(sub_dir_path).is_ok();
assert_eq!(still_exists_before, true);
url_to_cache("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml", "").unwrap();
url_to_cache("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/2022_Tesla_Model_Y_RWD_example.yaml", "").unwrap();
clear_cache(sub_dir_path).unwrap();
let still_exists = std::fs::metadata(sub_dir_path).is_ok();
assert_eq!(still_exists, false);
let path_to_vehicle = path_to_cache()
.unwrap()
.join("1110_2022_Tesla_Model_Y_RWD_opt45017.yaml");
.join("2022_Tesla_Model_Y_RWD_example.yaml");
let vehicle_still_exists = std::fs::metadata(&path_to_vehicle).is_ok();
assert_eq!(vehicle_still_exists, true);
std::fs::remove_file(path_to_vehicle).unwrap();
Expand Down
27 changes: 15 additions & 12 deletions rust/fastsim-core/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const REFERENCE_VEHICLE: &str = include_str!("assets/1110_2022_Tesla_Model_Y_RWD
#[test]
fn test_from_cache() {
let test_path = "1110_2022_Tesla_Model_Y_RWD_opt45017_from_cache.yaml";
let comparison_vehicle = crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
let comparison_vehicle =
crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
crate::vehicle::RustVehicle::to_cache(&comparison_vehicle, test_path).unwrap();
let vehicle = crate::vehicle::RustVehicle::from_cache(test_path, false).unwrap();
assert_eq!(comparison_vehicle, vehicle);
Expand All @@ -19,7 +20,8 @@ fn test_from_cache() {

#[test]
fn test_to_cache() {
let comparison_vehicle = crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
let comparison_vehicle =
crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
crate::vehicle::RustVehicle::to_cache(
&comparison_vehicle,
"1110_2022_Tesla_Model_Y_RWD_opt45017.yaml",
Expand All @@ -36,36 +38,37 @@ fn test_to_cache() {

#[test]
fn test_url_to_cache() {
utils::url_to_cache("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml", "vehicles").unwrap();
utils::url_to_cache("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/2022_Tesla_Model_Y_RWD_example.yaml", "vehicles").unwrap();
let data_subdirectory = utils::create_project_subdir("vehicles").unwrap();
let file_path = data_subdirectory.join("1110_2022_Tesla_Model_Y_RWD_opt45017.yaml");
let file_path = data_subdirectory.join("2022_Tesla_Model_Y_RWD_example.yaml");
println!("{}", file_path.to_string_lossy());
let vehicle = crate::vehicle::RustVehicle::from_file(&file_path, false).unwrap();
let comparison_vehicle = crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
let comparison_vehicle =
crate::vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
assert_eq!(vehicle, comparison_vehicle);
std::fs::remove_file(file_path).unwrap();
}

#[test]
fn test_from_github_or_url() {
let mut comparison_vehicle = vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
comparison_vehicle.doc = Some("Vehicle from https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml".to_owned());
comparison_vehicle.doc = Some("Vehicle from https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/2022_Tesla_Model_Y_RWD_example.yaml".to_owned());
// test no url provided
let vehicle = vehicle::RustVehicle::from_github_or_url(
"public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml",
"assets/2022_Tesla_Model_Y_RWD_example.yaml",
None,
)
.unwrap();
assert_eq!(vehicle, comparison_vehicle);
// test url provided
let vehicle_1 = vehicle::RustVehicle::from_github_or_url(
"1110_2022_Tesla_Model_Y_RWD_opt45017.yaml",
Some("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/"),
"2022_Tesla_Model_Y_RWD_example.yaml",
Some("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/"),
)
.unwrap();
assert_eq!(vehicle_1, comparison_vehicle);
let vehicle_2 = vehicle::RustVehicle::from_github_or_url(
"public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml",
"assets/2022_Tesla_Model_Y_RWD_example.yaml",
Some("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/"),
)
.unwrap();
Expand All @@ -74,8 +77,8 @@ fn test_from_github_or_url() {

#[test]
fn test_from_url() {
let vehicle = vehicle::RustVehicle::from_url("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml", false).unwrap();
let vehicle = vehicle::RustVehicle::from_url("https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/2022_Tesla_Model_Y_RWD_example.yaml", false).unwrap();
let mut comparison_vehicle = vehicle::RustVehicle::from_yaml(REFERENCE_VEHICLE, false).unwrap();
comparison_vehicle.doc = Some("Vehicle from https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/public/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml".to_owned());
comparison_vehicle.doc = Some("Vehicle from https://raw.githubusercontent.com/NREL/fastsim-vehicles/main/assets/2022_Tesla_Model_Y_RWD_example.yaml".to_owned());
assert_eq!(vehicle, comparison_vehicle);
}

0 comments on commit 6ad2acb

Please sign in to comment.