Skip to content

Commit

Permalink
Merge branch 'fastsim-2' of github.com:NREL/fastsim into fastsim-2
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Dec 6, 2024
2 parents 55bed54 + 10d4a03 commit 94b1eb6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- os: windows
ls: dir

env:
FASTSIM_DISABLE_NETWORK_TESTS: 1

runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -87,7 +90,8 @@ jobs:
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly --profile=minimal -y &&
rustup show
CIBW_BEFORE_BUILD_MACOS: >
rustup target add x86_64-apple-darwin
# - name: build windows 32bit binaries
# if: matrix.os == 'windows'
# run: cibuildwheel --output-dir dist
Expand All @@ -107,7 +111,7 @@ jobs:
- name: list dist files
run: ${{ matrix.ls || 'ls -lh' }} dist/

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: ./dist/*

Expand All @@ -117,7 +121,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: download files
uses: actions/download-artifact@v2.1.1
uses: actions/download-artifact@v4

- name: set up Python 3.10
uses: actions/setup-python@v4
Expand All @@ -128,7 +132,13 @@ jobs:

- run: twine check ./artifact/*

- name: upload files
- name: Publish distribution to Test PyPI
run: twine upload -r testpypi ./artifact/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.FASTSIM_TEST_PYPI_TOKEN }}

- name: Upload files to PyPI
run: twine upload ./artifact/*
env:
TWINE_USERNAME: __token__
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

env:
PYTHON: ${{ matrix.python-version }}
FASTSIM_DISABLE_NETWORK_TESTS: 1

steps:
- uses: actions/checkout@v3

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ jobs:
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly --profile=minimal -y &&
rustup show
CIBW_BEFORE_BUILD_MACOS: >
rustup target add x86_64-apple-darwin
# - name: build windows 32bit binaries
# if: matrix.os == 'windows'
# run: cibuildwheel --output-dir dist
Expand Down
9 changes: 8 additions & 1 deletion python/fastsim/demos/test_demos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import subprocess
import os
from pathlib import Path
Expand All @@ -22,8 +23,14 @@ def test_demo(demo_path: Path):
os.environ["SHOW_PLOTS"] = "false"
os.environ["TESTING"] = "true"

# NOTE: Try to set the python executable based on the current running python which
# MAY be running from a virtual environment.
python_exe = sys.executable
if python_exe == "" or python_exe is None:
python_exe = "python"

rslt = subprocess.run(
["python", demo_path],
[python_exe, demo_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
Expand Down
6 changes: 6 additions & 0 deletions rust/fastsim-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ pub use array_wrappers::*;
#[cfg(test)]
mod tests {
use super::*;
use crate::vehicle_utils::NETWORK_TEST_DISABLE_ENV_VAR_NAME;
use std::env;

#[test]
fn test_diff() {
Expand Down Expand Up @@ -867,6 +869,10 @@ mod tests {

#[test]
fn test_clear_cache() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_clear_cache");
return;
}
let temp_sub_dir = tempfile::TempDir::new_in(create_project_subdir("").unwrap()).unwrap();
let sub_dir_path = temp_sub_dir.path().to_str().unwrap();
let still_exists_before = std::fs::metadata(sub_dir_path).is_ok();
Expand Down
29 changes: 24 additions & 5 deletions rust/fastsim-core/src/vehicle_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ pub fn get_options_for_year_make_model(
#[cfg_attr(feature = "pyo3", pyfunction)]
pub fn get_vehicle_data_for_id(
id: i32,
year: &str,
year: &str,
cache_url: Option<String>,
data_dir: Option<String>,
) -> anyhow::Result<VehicleDataFE> {
Expand All @@ -348,16 +348,21 @@ pub fn get_vehicle_data_for_id(
h.insert(y);
h
};
let ddpath = data_dir.and_then(|dd| Some(PathBuf::from(dd))).unwrap_or(create_project_subdir("fe_label_data")?);
let ddpath = data_dir
.and_then(|dd| Some(PathBuf::from(dd)))
.unwrap_or(create_project_subdir("fe_label_data")?);
let cache_url = cache_url.unwrap_or_else(get_default_cache_url);
populate_cache_for_given_years_if_needed(ddpath.as_path(), &ys, &cache_url).with_context(|| format!("Unable to load or download cache data from {cache_url}"))?;
populate_cache_for_given_years_if_needed(ddpath.as_path(), &ys, &cache_url)
.with_context(|| format!("Unable to load or download cache data from {cache_url}"))?;
let emissions_data = load_emissions_data_for_given_years(ddpath.as_path(), &ys)?;
let fegov_data_by_year =
load_fegov_data_for_given_years(ddpath.as_path(), &emissions_data, &ys)?;
let fegov_db = fegov_data_by_year.get(&y).context(format!("Could not get fueleconomy.gov data from year {y}"))?;
let fegov_db = fegov_data_by_year
.get(&y)
.context(format!("Could not get fueleconomy.gov data from year {y}"))?;
for item in fegov_db.iter() {
if item.id == id {
return Ok(item.clone())
return Ok(item.clone());
}
}
bail!("Could not find ID in data {id}");
Expand Down Expand Up @@ -1498,6 +1503,8 @@ fn extract_file_from_zip(
#[cfg(test)]
mod tests {
use super::*;
use crate::vehicle_utils::NETWORK_TEST_DISABLE_ENV_VAR_NAME;
use std::env;

#[test]
fn test_create_new_vehicle_from_input_data() {
Expand Down Expand Up @@ -1612,6 +1619,10 @@ mod tests {

#[test]
fn test_get_options_for_year_make_model() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_get_options_for_year_make_model");
return;
}
let year = String::from("2020");
let make = String::from("Toyota");
let model = String::from("Corolla");
Expand All @@ -1621,6 +1632,10 @@ mod tests {

#[test]
fn test_import_robustness() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_import_robustness");
return;
}
// Ensure 2019 data is cached
let ddpath = create_project_subdir("fe_label_data").unwrap();
let model_year = 2019;
Expand Down Expand Up @@ -1691,6 +1706,10 @@ mod tests {

#[test]
fn test_get_options_for_year_make_model_for_specified_cacheurl_and_data_dir() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_get_options_for_year_make_model_for_specified_cacheurl_and_data_dir");
return;
}
let year = String::from("2020");
let make = String::from("Toyota");
let model = String::from("Corolla");
Expand Down
7 changes: 7 additions & 0 deletions rust/fastsim-core/src/vehicle_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::simdrive::RustSimDrive;
#[cfg(feature = "default")]
use crate::vehicle::RustVehicle;

pub const NETWORK_TEST_DISABLE_ENV_VAR_NAME: &str = "FASTSIM_DISABLE_NETWORK_TESTS";

#[allow(non_snake_case)]
#[cfg_attr(feature = "pyo3", pyfunction)]
#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -311,6 +313,7 @@ pub fn fetch_github_list(repo_url: Option<String>) -> anyhow::Result<Vec<String>
#[cfg(test)]
mod tests {
use super::*;
use std::env;

#[test]
fn test_get_error_val() {
Expand Down Expand Up @@ -357,6 +360,10 @@ mod tests {
// there's any way to ensure the function succeeds 100% of the time.
#[test]
fn test_fetch_github_list() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_fetch_github_list");
return;
}
let list = fetch_github_list(Some(
"https://api.github.com/repos/NREL/fastsim-vehicles/contents".to_owned(),
))
Expand Down
14 changes: 14 additions & 0 deletions rust/fastsim-core/tests/integration-tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::env;
use std::path::Path;

use fastsim_core::traits::*;
use fastsim_core::vehicle_utils::NETWORK_TEST_DISABLE_ENV_VAR_NAME;
use fastsim_core::*;

const REFERENCE_VEHICLE: &str = include_str!("assets/1110_2022_Tesla_Model_Y_RWD_opt45017.yaml");
Expand Down Expand Up @@ -38,6 +40,10 @@ fn test_to_cache() {

#[test]
fn test_url_to_cache() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_url_to_cache()");
return;
}
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("2022_Tesla_Model_Y_RWD_example.yaml");
Expand All @@ -51,6 +57,10 @@ fn test_url_to_cache() {

#[test]
fn test_from_github_or_url() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_from_github_or_url()");
return;
}
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/assets/2022_Tesla_Model_Y_RWD_example.yaml".to_owned());
// test no url provided
Expand All @@ -77,6 +87,10 @@ fn test_from_github_or_url() {

#[test]
fn test_from_url() {
if env::var(NETWORK_TEST_DISABLE_ENV_VAR_NAME).is_ok() {
println!("SKIPPING: test_from_url()");
return;
}
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/assets/2022_Tesla_Model_Y_RWD_example.yaml".to_owned());
Expand Down

0 comments on commit 94b1eb6

Please sign in to comment.