Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
penelopeysm committed Jul 1, 2024
1 parent 04e2fc2 commit c89cfc6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 118 deletions.
4 changes: 2 additions & 2 deletions src/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
let server = mock_fgb_server();

// Get the geometries
let geoms = get_geometries(&server.url("/fgb_example.fgb"), None, None).await;
let geoms = get_geometries(&server.url("/fgb_example.fgb"), None).await;
println!("{geoms:#?}");
assert!(geoms.is_ok(), "The geometry call should not error");
let geoms = geoms.unwrap();
Expand Down Expand Up @@ -235,7 +235,7 @@ mod tests {
-1.373_095_490_899_146_4,
53.026_908_220_355_35,
]);
let geoms = get_geometries(&server.url("/fgb_example.fgb"), Some(&bbox), None).await;
let geoms = get_geometries(&server.url("/fgb_example.fgb"), Some(&bbox)).await;

assert!(geoms.is_ok(), "The geometry call should not error");
let geoms = geoms.unwrap();
Expand Down
112 changes: 0 additions & 112 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,116 +267,4 @@ mod tests {
println!("{metadata:#?}");
assert!(metadata.is_ok(), "Data should have loaded ok");
}

#[tokio::test]
async fn metric_ids_should_expand_properly() {
let config = Config::default();
let metadata = CountryMetadataLoader::new("be")
.load(&config)
.await
.unwrap();
let expanded_metrics = metadata.expand_regex_metric(&MetricId::Hxl("population-*".into()));
assert!(
expanded_metrics.is_ok(),
"Should successfully expand metrics"
);
let expanded_metrics = expanded_metrics.unwrap();

assert_eq!(
expanded_metrics.len(),
7,
"should return the correct number of metrics"
);

let metric_names: Vec<&str> = expanded_metrics
.iter()
.map(MetricId::to_query_string)
.collect();

assert_eq!(
metric_names,
vec![
"#population+children+age5_17",
"#population+infants+age0_4",
"#population+children+age0_17",
"#population+adults+f",
"#population+adults+m",
"#population+adults",
"#population+ind"
],
"should get the correct metrics"
);
}

#[tokio::test]
async fn human_readable_metric_ids_should_expand_properly() {
let config = Config::default();
let metadata = CountryMetadataLoader::new("be")
.load(&config)
.await
.unwrap();
let expanded_metrics =
metadata.expand_regex_metric(&MetricId::CommonName("Children*".into()));

println!("{:#?}", expanded_metrics);

assert!(
expanded_metrics.is_ok(),
"Should successfully expand metrics"
);

let expanded_metrics = expanded_metrics.unwrap();

assert_eq!(
expanded_metrics.len(),
2,
"should return the correct number of metrics"
);

let metric_names: Vec<&str> = expanded_metrics
.iter()
.map(MetricId::to_query_string)
.collect();

assert_eq!(
metric_names,
vec!["Children aged 5 to 17", "Children aged 0 to 17"],
"should get the correct metrics"
);
}

#[tokio::test]
async fn fully_defined_metric_ids_should_expand_to_itself() {
let config = Config::default();
let metadata = CountryMetadataLoader::new("be")
.load(&config)
.await
.unwrap();
let expanded_metrics =
metadata.expand_regex_metric(&MetricId::Hxl(r"#population\+infants\+age0\_4".into()));
assert!(
expanded_metrics.is_ok(),
"Should successfully expand metrics"
);
let expanded_metrics = expanded_metrics.unwrap();

assert_eq!(
expanded_metrics.len(),
1,
"should return the correct number of metrics"
);

let metric_names: Vec<&str> = expanded_metrics
.iter()
.map(MetricId::to_query_string)
.collect();

assert_eq!(
metric_names,
vec!["#population+infants+age0_4",],
"should get the correct metrics"
);

println!("{:#?}", expanded_metrics);
}
}
10 changes: 6 additions & 4 deletions src/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ mod tests {
fn test_fetching_metrics() {
let metrics = [
MetricRequest{
metric_file:"https://popgetter.blob.core.windows.net/popgetter-cli-test/tracts_2019_fiveYear.parquet".into(),
column:"B17021_E006".into()
metric_file: "https://popgetter.blob.core.windows.net/popgetter-cli-test/tracts_2019_fiveYear.parquet".into(),
column: "B17021_E006".into(),
geom_file: "Not needed for this test".into(),
}];
let df = get_metrics(&metrics, None);
assert!(df.is_ok(), "We should get back a result");
Expand Down Expand Up @@ -124,8 +125,9 @@ mod tests {
fn test_fetching_metrics_with_geo_filter() {
let metrics = [
MetricRequest{
metric_file:"https://popgetter.blob.core.windows.net/popgetter-cli-test/tracts_2019_fiveYear.parquet".into(),
column:"B17021_E006".into()
metric_file: "https://popgetter.blob.core.windows.net/popgetter-cli-test/tracts_2019_fiveYear.parquet".into(),
column: "B17021_E006".into(),
geom_file: "Not needed for this test".into(),
}];
let df = get_metrics(
&metrics,
Expand Down

0 comments on commit c89cfc6

Please sign in to comment.