From 1524f870b4ee871f92ba7fb5148285db644d9494 Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Thu, 21 Mar 2024 21:14:49 +0000 Subject: [PATCH 1/3] Update tests --- buildstockbatch/test/test_base.py | 2 +- buildstockbatch/test/test_docker_base.py | 2 +- .../test_openstudio_buildstock/resources/buildstock_good.csv | 4 ++-- .../test_openstudio_buildstock/resources/options_lookup.tsv | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/buildstockbatch/test/test_base.py b/buildstockbatch/test/test_base.py index 5dbefcbd..13bfa703 100644 --- a/buildstockbatch/test/test_base.py +++ b/buildstockbatch/test/test_base.py @@ -165,7 +165,7 @@ def test_upload_files(mocker, basic_residential_project_file): if call_function == "resource": assert call[1][0] in ["s3"] # call[1] is for the positional arguments if call_function == "Bucket": - assert call[1][0] == s3_bucket + assert call[1][0] == s3_bucket, call if call_function == "upload_file": source_file_path = call[1][0] destination_path = call[1][1] diff --git a/buildstockbatch/test/test_docker_base.py b/buildstockbatch/test/test_docker_base.py index 88e70f1a..3899fe3d 100644 --- a/buildstockbatch/test/test_docker_base.py +++ b/buildstockbatch/test/test_docker_base.py @@ -100,7 +100,7 @@ def test_get_epws_to_download(): } epws = DockerBatchBase.get_epws_to_download(sim_dir, jobs_d) - assert epws == set(["weather/G0100970.epw", "weather/G0100830.epw"]) + assert epws == set(["weather/G2500210.epw", "weather/G2601390.epw"]) def test_run_simulations(basic_residential_project_file): diff --git a/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_good.csv b/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_good.csv index d69de02c..0a98f57f 100644 --- a/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_good.csv +++ b/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/buildstock_good.csv @@ -1,6 +1,6 @@ Building,Bedroom,Location,Vintage,State,Insulation Wall,Insulation Slab,Zipcode,County 1,1,AL_Mobile-Rgnl.AP.722230,<1950,CO,Good Option,None,36608,County1 2,3,AL_Mobile-Rgnl.AP.722230,1940s,CO,Good Option,None,36601,County1 -3,2,AL_Mobile-Rgnl.AP.722230,2010s,VA,Good Option,None,36602,County1 +3,2,AL_Mobile-Rgnl.AP.722230,2010s,VA,Good Option,None,36602,County2 4,1,AL_Mobile-Rgnl.AP.722230,2000s,VA,Good Option,None,36603,County2 -5,2,AL_Mobile-Rgnl.AP.722230,1970s,VA,Good Option,None,36604,County2 +5,2,AL_Mobile-Rgnl.AP.722230,1970s,VA,Good Option,None,36604,County3 diff --git a/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/options_lookup.tsv b/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/options_lookup.tsv index 73032a93..39905259 100644 --- a/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/options_lookup.tsv +++ b/buildstockbatch/test/test_inputs/test_openstudio_buildstock/resources/options_lookup.tsv @@ -14,8 +14,9 @@ Vintage 2000s Vintage 2010s State VA State CO -County County1 weather_station_epw_filepath=weather/G0100970.epw -County County2 weather_station_epw_filepath=weather/G0100830.epw +County County1 weather_station_epw_filepath=weather/G2500210.epw +County County2 weather_station_epw_filepath=weather/G2601210.epw +County County3 weather_station_epw_filepath=weather/G2601390.epw Bedroom 1 Bedroom 2 Bedroom 3 From dfa459f235e695e1912384e3c4dc31bf47870104 Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Thu, 21 Mar 2024 21:22:04 +0000 Subject: [PATCH 2/3] Fix formatting --- buildstockbatch/sample_one_county.py | 1 + 1 file changed, 1 insertion(+) diff --git a/buildstockbatch/sample_one_county.py b/buildstockbatch/sample_one_county.py index f2550fcd..cae2041b 100644 --- a/buildstockbatch/sample_one_county.py +++ b/buildstockbatch/sample_one_county.py @@ -32,6 +32,7 @@ - County and PUMA depends only on the ASHRAE climate zone - Each County+PUMA fall entirely in one climate zone """ + import argparse import csv import os From 8a62303c91eb1714c35bc978aca7376e743849f8 Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Thu, 21 Mar 2024 21:57:47 +0000 Subject: [PATCH 3/3] Fix test --- buildstockbatch/postprocessing.py | 2 ++ buildstockbatch/test/test_base.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/buildstockbatch/postprocessing.py b/buildstockbatch/postprocessing.py index 37ed938c..d5baf37b 100644 --- a/buildstockbatch/postprocessing.py +++ b/buildstockbatch/postprocessing.py @@ -634,6 +634,7 @@ def upload_results(aws_conf, output_dir, results_dir, buildstock_csv_filename): s3_prefix_output = s3_prefix + "/" + output_folder_name + "/" s3 = boto3.resource("s3") + print(f"In upload_results: {s3_bucket}") bucket = s3.Bucket(s3_bucket) n_existing_files = len(list(bucket.objects.filter(Prefix=s3_prefix_output))) if n_existing_files > 0: @@ -643,6 +644,7 @@ def upload_results(aws_conf, output_dir, results_dir, buildstock_csv_filename): def upload_file(filepath, s3key=None): full_path = filepath if filepath.is_absolute() else parquet_dir.joinpath(filepath) s3 = boto3.resource("s3") + print(f"In upload_file: {s3_bucket}") bucket = s3.Bucket(s3_bucket) if s3key is None: s3key = Path(s3_prefix_output).joinpath(filepath).as_posix() diff --git a/buildstockbatch/test/test_base.py b/buildstockbatch/test/test_base.py index 13bfa703..e5980168 100644 --- a/buildstockbatch/test/test_base.py +++ b/buildstockbatch/test/test_base.py @@ -133,7 +133,7 @@ def test_upload_files(mocker, basic_residential_project_file): return_value={"Crawler": {"State": "READY", "LastCrawl": {"Status": "SUCCEEDED"}}} ) mocked_boto3.client = MagicMock(return_value=mocked_glueclient) - mocked_boto3.resource().Bucket().objects.filter.side_effect = [[], ["a", "b", "c"]] + mocked_boto3.resource("s3").Bucket(s3_bucket).objects.filter.side_effect = [[], ["a", "b", "c"]] project_filename, results_dir = basic_residential_project_file(upload_config) buildstock_csv_path = ( Path(results_dir).parent @@ -160,12 +160,12 @@ def test_upload_files(mocker, basic_residential_project_file): files_uploaded = [] crawler_created = False crawler_started = False - for call in mocked_boto3.mock_calls[2:] + mocked_boto3.client().mock_calls: + for call in mocked_boto3.mock_calls + mocked_boto3.client().mock_calls: call_function = call[0].split(".")[-1] # 0 is for the function name if call_function == "resource": assert call[1][0] in ["s3"] # call[1] is for the positional arguments if call_function == "Bucket": - assert call[1][0] == s3_bucket, call + assert call[1][0] == s3_bucket if call_function == "upload_file": source_file_path = call[1][0] destination_path = call[1][1]