From 917ab4f018e628daf186a36d2a365d0ef75b0ce6 Mon Sep 17 00:00:00 2001 From: Jordan Laser Date: Thu, 24 Oct 2024 14:38:54 -0600 Subject: [PATCH] pytz -> datetime.timezone --- .github/workflows/forcingprocessor.yml | 2 +- .../tests/test_forcingprocessor.py | 5 ++--- python_tools/tests/test_configurer.py | 22 +++++++++---------- .../checker/lambda_function.py | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/forcingprocessor.yml b/.github/workflows/forcingprocessor.yml index 2438c3d5..cb50d0ff 100644 --- a/.github/workflows/forcingprocessor.yml +++ b/.github/workflows/forcingprocessor.yml @@ -43,7 +43,7 @@ jobs: - name: Test with pytest run: | cd forcingprocessor - python -m pytest -vv --deselect="tests/test_forcingprocessor.py::test_google_cloud_storage" --deselect="tests/test_forcingprocessor.py::test_gcs" --deselect="tests/test_forcingprocessor.py::test_gs" --deselect="tests/test_forcingprocessor.py::test_ciroh_zarr" --deselect="tests/test_forcingprocessor.py::test_nomads_post_processed" --deselect="tests/test_forcingprocessor.py::test_retro_ciroh_zarr" --deselect="tests/test_forcingprocessor.py::test_noaa_nwm_pds_https_analysis_assim" --deselect="tests/test_hf2ds.py" --deselect="tests/test_plotter.py" + python -m pytest -vv --deselect="tests/test_forcingprocessor.py::test_google_cloud_storage" --deselect="tests/test_forcingprocessor.py::test_gcs" --deselect="tests/test_forcingprocessor.py::test_gs" --deselect="tests/test_forcingprocessor.py::test_ciroh_zarr" --deselect="tests/test_forcingprocessor.py::test_nomads_post_processed" --deselect="tests/test_forcingprocessor.py::test_retro_ciroh_zarr" --deselect="tests/test_hf2ds.py" --deselect="tests/test_plotter.py" python -m pytest -vv tests/test_hf2ds.py python -m pytest -vv tests/test_plotter.py python -m pytest -vv -k test_google_cloud_storage diff --git a/forcingprocessor/tests/test_forcingprocessor.py b/forcingprocessor/tests/test_forcingprocessor.py index 2b3ceac4..62342bd8 100644 --- a/forcingprocessor/tests/test_forcingprocessor.py +++ b/forcingprocessor/tests/test_forcingprocessor.py @@ -1,14 +1,13 @@ import os from pathlib import Path from datetime import datetime -from datetime import datetime +from datetime import timezone from forcingprocessor.processor import prep_ngen_data from forcingprocessor.nwm_filenames_generator import generate_nwmfiles -import pytz as tz import pytest HF_VERSION="v2.1.1" -date = datetime.now(tz.timezone('US/Eastern')) +date = datetime.now(timezone.utc) date = date.strftime('%Y%m%d') hourminute = '0000' test_dir = Path(__file__).parent diff --git a/python_tools/tests/test_configurer.py b/python_tools/tests/test_configurer.py index c15df8de..a1d05148 100644 --- a/python_tools/tests/test_configurer.py +++ b/python_tools/tests/test_configurer.py @@ -1,6 +1,5 @@ import os, pytest, json -from datetime import datetime -import pytz as tz +from datetime import datetime, timezone from python_tools.configure_datastream import create_confs SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -110,7 +109,7 @@ def test_conf_daily(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -142,7 +141,7 @@ def test_conf_daily_short_range(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -159,7 +158,7 @@ def test_conf_daily_medium_range(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -176,7 +175,7 @@ def test_conf_daily_noamds(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -193,7 +192,7 @@ def test_conf_daily_noamds_postprocessed(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -213,7 +212,7 @@ def test_conf_daily_assim_split_vpu_s3out(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) @@ -240,12 +239,13 @@ def test_conf_daily_assim_extend_split_vpu_s3out(): with open(REALIZATION_RUN,'r') as fp: data = json.load(fp) start = datetime.strptime(data['time']['start_time'],"%Y-%m-%d %H:%M:%S") - assert start.day == datetime.now(tz.timezone('US/Eastern')).day + assert start.day == datetime.now(timezone.utc).day with open(CONF_NWM,'r') as fp: data = json.load(fp) - assert data['urlbaseinput'] == 7 - assert data['runinput'] == 6 + assert data['urlbaseinput'] == 7 + assert data['runinput'] == 6 + assert data['fcst_cycle'][0] == 16 assert len(data['lead_time'] ) == 28 with open(CONF_FP,'r') as fp: diff --git a/research_datastream/terraform/lambda_functions/checker/lambda_function.py b/research_datastream/terraform/lambda_functions/checker/lambda_function.py index 94cb73aa..d0aec9e9 100644 --- a/research_datastream/terraform/lambda_functions/checker/lambda_function.py +++ b/research_datastream/terraform/lambda_functions/checker/lambda_function.py @@ -2,7 +2,7 @@ import time import re import datetime -import pytz as tz +from datetime import timezone client_s3 = boto3.client('s3') @@ -37,7 +37,7 @@ def lambda_handler(event, context): if bucket is None or prefix is None: raise Exception(f'User specified ii_check_s3, but no s3_bucket or s3_prefix were not found in commands') if "DAILY" in prefix: - prefix = re.sub(r"\DAILY",datetime.now(tz.timezone('US/Eastern')).strftime('%Y%m%d'),prefix) + prefix = re.sub(r"\DAILY",datetime.now(timezone.utc).strftime('%Y%m%d'),prefix) print(f'Checking if any objects with prefix {prefix} exists in {bucket}') wait_for_object_existence(bucket, prefix) else: