From 463b1d4d289cb4b1a7b3653c88481b34130e60cb Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 08:40:36 -0400 Subject: [PATCH 1/7] Copied code block to convert data to 15 minutes prior to storing from the standalone getUSGS_CDA to the cwms-cli version. --- cwmscli/usgs/getusgs_cda.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index 19db973..ca97068 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -370,6 +370,16 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): office = row["office-id"] values["quality-code"] = 0 + + # 15 minute conversion + if ts_id.split(".")[3] == "15Minutes": + values_dt = values.copy() + values_dt['date-time'] = pd.to_datetime(values_dt['date-time']) + values_dt.set_index('date-time', inplace=True) + values15 = values_dt.resample('15min').first() + values = values15.reset_index() + + # write values to CWMS database try: data = cwms.timeseries_df_to_json( From a168ba420ab4d806e55d5209704afa56c1db06e6 Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 09:00:44 -0400 Subject: [PATCH 2/7] Updated comment to better reflect the purpose of the 15 minute conversion code. --- cwmscli/usgs/getusgs_cda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index ca97068..aab4805 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -371,7 +371,7 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): values["quality-code"] = 0 - # 15 minute conversion + # 15 minute conversion to allow storing smaller interval data (eg. 5 minute) as 15 minute data if ts_id.split(".")[3] == "15Minutes": values_dt = values.copy() values_dt['date-time'] = pd.to_datetime(values_dt['date-time']) From 85a3db14b3e6f07dd8f3423e9ec3c89ce1c06d47 Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 09:41:30 -0400 Subject: [PATCH 3/7] Reformatted code to standard. --- cwmscli/usgs/getusgs_cda.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index aab4805..81b1f6f 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -373,11 +373,13 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): # 15 minute conversion to allow storing smaller interval data (eg. 5 minute) as 15 minute data if ts_id.split(".")[3] == "15Minutes": - values_dt = values.copy() - values_dt['date-time'] = pd.to_datetime(values_dt['date-time']) - values_dt.set_index('date-time', inplace=True) - values15 = values_dt.resample('15min').first() - values = values15.reset_index() + values_dt = values.copy() + values_dt["date-time"] = pd.to_datetime( + values_dt["date-time"] + ) + values_dt.set_index("date-time", inplace=True) + values15 = values_dt.resample("15min").first() + values = values15.reset_index() # write values to CWMS database From 20cc807ac8e214b434cf682dc7b2e7c081eccd47 Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 10:50:03 -0400 Subject: [PATCH 4/7] Test new yaml --- .pre-commit-config.yaml | 20 ++++--- cwmscli/commands/commands_cwms.py | 12 ++-- cwmscli/usgs/getusgs_cda.py | 2 - tests/usgs/test_rating_ini_file_import.py | 72 +++++++++++++++-------- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26cf21b..e31c51a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,26 +3,30 @@ repos: hooks: - id: black name: black - entry: poetry run black - language: system + entry: black + language: python + additional_dependencies: [black] types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: isort name: isort - entry: poetry run isort - language: system + entry: isort + language: python + additional_dependencies: [isort] types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: yamlfix name: yamlfix - entry: poetry run yamlfix - language: system + entry: yamlfix + language: python + additional_dependencies: [yamlfix] types: [file, yaml] - id: ownership-sync name: generated ownership files - entry: poetry run python scripts/sync_ownership.py --check - language: system + entry: python scripts/sync_ownership.py --check + language: python + additional_dependencies: [poetry] pass_filenames: false diff --git a/cwmscli/commands/commands_cwms.py b/cwmscli/commands/commands_cwms.py index a2901fc..b076d02 100644 --- a/cwmscli/commands/commands_cwms.py +++ b/cwmscli/commands/commands_cwms.py @@ -492,13 +492,15 @@ def update_cli_cmd(target_version: Optional[str], pre: bool, yes: bool) -> None: @click.group( "blob", help="Manage CWMS Blobs (upload, download, delete, update, list)", - epilog=textwrap.dedent(""" + epilog=textwrap.dedent( + """ Example Usage:\n - Store a PDF/image as a CWMS blob with optional description\n - Download a blob by id to your local filesystem\n - Update a blob's name/description/mime-type\n - Bulk list blobs for an office -"""), +""" + ), ) def blob_group(): pass @@ -706,12 +708,14 @@ def list_cmd(**kwargs): @click.group( "clob", help="Manage CWMS Clobs (upload, download, delete, update, list)", - epilog=textwrap.dedent(""" + epilog=textwrap.dedent( + """ Example Usage:\n - Download a clob by id to your local filesystem\n - Update a clob's name/description/mime-type\n - Bulk list clobs for an office -"""), +""" + ), ) @requires(reqs.cwms) def clob_group(): diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index 81b1f6f..1db3350 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -370,7 +370,6 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): office = row["office-id"] values["quality-code"] = 0 - # 15 minute conversion to allow storing smaller interval data (eg. 5 minute) as 15 minute data if ts_id.split(".")[3] == "15Minutes": values_dt = values.copy() @@ -381,7 +380,6 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): values15 = values_dt.resample("15min").first() values = values15.reset_index() - # write values to CWMS database try: data = cwms.timeseries_df_to_json( diff --git a/tests/usgs/test_rating_ini_file_import.py b/tests/usgs/test_rating_ini_file_import.py index 5a913e3..15bd7c0 100644 --- a/tests/usgs/test_rating_ini_file_import.py +++ b/tests/usgs/test_rating_ini_file_import.py @@ -259,13 +259,15 @@ def test_import_with_real_file(self, mock_update, mock_init_cwms): def test_import_with_simple_ini_file(self): """Test import with a simple temporary INI file.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(""" + f.write( + """ # Test config cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -284,14 +286,16 @@ def test_import_with_simple_ini_file(self): def test_import_parameter_parsing(self): """Test that import correctly parses configuration parameters.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" cwms_office=MVP db_base=BASE_\$localid.SPEC db_exsa=EXSA_\$localid.SPEC db_corr=CORR_\$localid.SPEC localid=TESTLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -315,14 +319,16 @@ def test_import_parameter_parsing(self): def test_import_skips_comments(self): """Test that import correctly skips commented lines.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(""" + f.write( + """ cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS db_exsa=$localid.Stage;Flow.USGS-EXSA.USGS-NWIS localid=LOC1 #store_corr $($db_corr) store_exsa $($db_exsa) -""") +""" + ) temp_file = f.name try: @@ -341,12 +347,14 @@ def test_import_skips_comments(self): def test_import_handles_inline_comments(self): """Test that import correctly handles inline comments.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(""" + f.write( + """ cwms_office=MVP # This is the office db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC # Location identifier store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -366,12 +374,14 @@ def test_import_handles_inline_comments(self): def test_import_office_id_uppercase(self): """Test that office_id is converted to uppercase.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(""" + f.write( + """ cwms_office=mvp db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -391,14 +401,16 @@ def test_import_office_id_uppercase(self): def test_import_handles_multiple_locations(self): """Test that import correctly processes multiple location blocks.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(""" + f.write( + """ cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=LOC1 store_corr $($db_corr) localid=LOC2 store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -417,12 +429,14 @@ def test_import_handles_multiple_locations(self): def test_import_localid_substitution(self): """Test that $localid is correctly substituted in specifications.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=MYLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -444,7 +458,8 @@ def test_import_localid_substitution(self): def test_import_cwmsid_substitution_with_nae_format(self): """Test NAE format with cwmsid and flexible db references (db_tail, db_river).""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" CWMS_OFFICE=NAE CWMS_DATABASE=local db_tail=\$cwmsid.Stage-TAILWATER;Flow.USGS-EXSA.USGS-NWIS @@ -459,7 +474,8 @@ def test_import_cwmsid_substitution_with_nae_format(self): usgsid=01151500 replace_exsa $(textfile) store_exsa $($db_river) -""") +""" + ) temp_file = f.name try: @@ -491,12 +507,14 @@ def test_import_cwmsid_substitution_with_nae_format(self): def test_dry_run_mode_calls_update_with_flag(self): """Test that dry_run mode calls update_rating_spec with dry_run=True.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -518,7 +536,8 @@ def test_dry_run_mode_calls_update_with_flag(self): def test_dry_run_mode_with_multiple_entries(self): """Test that dry_run processes all entries with dry_run flag.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" CWMS_OFFICE=NAE CWMS_DATABASE=local db_tail=\$cwmsid.Stage-TAILWATER;Flow.USGS-EXSA.USGS-NWIS @@ -535,7 +554,8 @@ def test_dry_run_mode_with_multiple_entries(self): cwmsid=NSD usgsid=01153000 store_exsa $($db_tail) -""") +""" + ) temp_file = f.name try: @@ -558,13 +578,15 @@ def test_dry_run_mode_with_multiple_entries(self): def test_import_custom_tag_substitution(self): """Test that custom tags (not just localid/cwmsid) are substituted.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" cwms_office=MVP db_corr=\$location.\$parameter.USGS-CORR.USGS-NWIS location=TESTLOC parameter=Stage;Flow store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: @@ -589,12 +611,14 @@ def test_import_custom_tag_substitution(self): def test_normal_mode_calls_updates(self): """Test that normal mode (not dry_run) calls update_rating_spec with dry_run=False.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write(r""" + f.write( + r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""") +""" + ) temp_file = f.name try: From ead115516737f64f8d337cc35e9d6c7f4bbf0e17 Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 10:53:28 -0400 Subject: [PATCH 5/7] Poetry checks passed. --- .pre-commit-config.yaml.org | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .pre-commit-config.yaml.org diff --git a/.pre-commit-config.yaml.org b/.pre-commit-config.yaml.org new file mode 100644 index 0000000..26cf21b --- /dev/null +++ b/.pre-commit-config.yaml.org @@ -0,0 +1,28 @@ +repos: + - repo: local + hooks: + - id: black + name: black + entry: poetry run black + language: system + types: [file, python] + exclude: ^cwmscli/_generated/ownership_data\.py$ + + - id: isort + name: isort + entry: poetry run isort + language: system + types: [file, python] + exclude: ^cwmscli/_generated/ownership_data\.py$ + + - id: yamlfix + name: yamlfix + entry: poetry run yamlfix + language: system + types: [file, yaml] + + - id: ownership-sync + name: generated ownership files + entry: poetry run python scripts/sync_ownership.py --check + language: system + pass_filenames: false From a07ec811d18a937278d8dd2ece17cd30794fdb60 Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 11:24:49 -0400 Subject: [PATCH 6/7] Revert "Test new yaml" This reverts commit 20cc807ac8e214b434cf682dc7b2e7c081eccd47. --- .pre-commit-config.yaml | 20 +++---- cwmscli/commands/commands_cwms.py | 12 ++-- cwmscli/usgs/getusgs_cda.py | 2 + tests/usgs/test_rating_ini_file_import.py | 72 ++++++++--------------- 4 files changed, 38 insertions(+), 68 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e31c51a..26cf21b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,30 +3,26 @@ repos: hooks: - id: black name: black - entry: black - language: python - additional_dependencies: [black] + entry: poetry run black + language: system types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: isort name: isort - entry: isort - language: python - additional_dependencies: [isort] + entry: poetry run isort + language: system types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: yamlfix name: yamlfix - entry: yamlfix - language: python - additional_dependencies: [yamlfix] + entry: poetry run yamlfix + language: system types: [file, yaml] - id: ownership-sync name: generated ownership files - entry: python scripts/sync_ownership.py --check - language: python - additional_dependencies: [poetry] + entry: poetry run python scripts/sync_ownership.py --check + language: system pass_filenames: false diff --git a/cwmscli/commands/commands_cwms.py b/cwmscli/commands/commands_cwms.py index b076d02..a2901fc 100644 --- a/cwmscli/commands/commands_cwms.py +++ b/cwmscli/commands/commands_cwms.py @@ -492,15 +492,13 @@ def update_cli_cmd(target_version: Optional[str], pre: bool, yes: bool) -> None: @click.group( "blob", help="Manage CWMS Blobs (upload, download, delete, update, list)", - epilog=textwrap.dedent( - """ + epilog=textwrap.dedent(""" Example Usage:\n - Store a PDF/image as a CWMS blob with optional description\n - Download a blob by id to your local filesystem\n - Update a blob's name/description/mime-type\n - Bulk list blobs for an office -""" - ), +"""), ) def blob_group(): pass @@ -708,14 +706,12 @@ def list_cmd(**kwargs): @click.group( "clob", help="Manage CWMS Clobs (upload, download, delete, update, list)", - epilog=textwrap.dedent( - """ + epilog=textwrap.dedent(""" Example Usage:\n - Download a clob by id to your local filesystem\n - Update a clob's name/description/mime-type\n - Bulk list clobs for an office -""" - ), +"""), ) @requires(reqs.cwms) def clob_group(): diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index 1db3350..81b1f6f 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -370,6 +370,7 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): office = row["office-id"] values["quality-code"] = 0 + # 15 minute conversion to allow storing smaller interval data (eg. 5 minute) as 15 minute data if ts_id.split(".")[3] == "15Minutes": values_dt = values.copy() @@ -380,6 +381,7 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): values15 = values_dt.resample("15min").first() values = values15.reset_index() + # write values to CWMS database try: data = cwms.timeseries_df_to_json( diff --git a/tests/usgs/test_rating_ini_file_import.py b/tests/usgs/test_rating_ini_file_import.py index 15bd7c0..5a913e3 100644 --- a/tests/usgs/test_rating_ini_file_import.py +++ b/tests/usgs/test_rating_ini_file_import.py @@ -259,15 +259,13 @@ def test_import_with_real_file(self, mock_update, mock_init_cwms): def test_import_with_simple_ini_file(self): """Test import with a simple temporary INI file.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - """ + f.write(""" # Test config cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -286,16 +284,14 @@ def test_import_with_simple_ini_file(self): def test_import_parameter_parsing(self): """Test that import correctly parses configuration parameters.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" cwms_office=MVP db_base=BASE_\$localid.SPEC db_exsa=EXSA_\$localid.SPEC db_corr=CORR_\$localid.SPEC localid=TESTLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -319,16 +315,14 @@ def test_import_parameter_parsing(self): def test_import_skips_comments(self): """Test that import correctly skips commented lines.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - """ + f.write(""" cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS db_exsa=$localid.Stage;Flow.USGS-EXSA.USGS-NWIS localid=LOC1 #store_corr $($db_corr) store_exsa $($db_exsa) -""" - ) +""") temp_file = f.name try: @@ -347,14 +341,12 @@ def test_import_skips_comments(self): def test_import_handles_inline_comments(self): """Test that import correctly handles inline comments.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - """ + f.write(""" cwms_office=MVP # This is the office db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC # Location identifier store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -374,14 +366,12 @@ def test_import_handles_inline_comments(self): def test_import_office_id_uppercase(self): """Test that office_id is converted to uppercase.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - """ + f.write(""" cwms_office=mvp db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -401,16 +391,14 @@ def test_import_office_id_uppercase(self): def test_import_handles_multiple_locations(self): """Test that import correctly processes multiple location blocks.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - """ + f.write(""" cwms_office=MVP db_corr=$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=LOC1 store_corr $($db_corr) localid=LOC2 store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -429,14 +417,12 @@ def test_import_handles_multiple_locations(self): def test_import_localid_substitution(self): """Test that $localid is correctly substituted in specifications.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=MYLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -458,8 +444,7 @@ def test_import_localid_substitution(self): def test_import_cwmsid_substitution_with_nae_format(self): """Test NAE format with cwmsid and flexible db references (db_tail, db_river).""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" CWMS_OFFICE=NAE CWMS_DATABASE=local db_tail=\$cwmsid.Stage-TAILWATER;Flow.USGS-EXSA.USGS-NWIS @@ -474,8 +459,7 @@ def test_import_cwmsid_substitution_with_nae_format(self): usgsid=01151500 replace_exsa $(textfile) store_exsa $($db_river) -""" - ) +""") temp_file = f.name try: @@ -507,14 +491,12 @@ def test_import_cwmsid_substitution_with_nae_format(self): def test_dry_run_mode_calls_update_with_flag(self): """Test that dry_run mode calls update_rating_spec with dry_run=True.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -536,8 +518,7 @@ def test_dry_run_mode_calls_update_with_flag(self): def test_dry_run_mode_with_multiple_entries(self): """Test that dry_run processes all entries with dry_run flag.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" CWMS_OFFICE=NAE CWMS_DATABASE=local db_tail=\$cwmsid.Stage-TAILWATER;Flow.USGS-EXSA.USGS-NWIS @@ -554,8 +535,7 @@ def test_dry_run_mode_with_multiple_entries(self): cwmsid=NSD usgsid=01153000 store_exsa $($db_tail) -""" - ) +""") temp_file = f.name try: @@ -578,15 +558,13 @@ def test_dry_run_mode_with_multiple_entries(self): def test_import_custom_tag_substitution(self): """Test that custom tags (not just localid/cwmsid) are substituted.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" cwms_office=MVP db_corr=\$location.\$parameter.USGS-CORR.USGS-NWIS location=TESTLOC parameter=Stage;Flow store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: @@ -611,14 +589,12 @@ def test_import_custom_tag_substitution(self): def test_normal_mode_calls_updates(self): """Test that normal mode (not dry_run) calls update_rating_spec with dry_run=False.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ini", delete=False) as f: - f.write( - r""" + f.write(r""" cwms_office=MVP db_corr=\$localid.Stage;Flow.USGS-CORR.USGS-NWIS localid=TESTLOC store_corr $($db_corr) -""" - ) +""") temp_file = f.name try: From 77794e0d92657a3f074920febf559d7b05e3fb4b Mon Sep 17 00:00:00 2001 From: Thomas Ressin Date: Mon, 6 Jul 2026 11:49:53 -0400 Subject: [PATCH 7/7] Fix getusgs_cda --- .pre-commit-config.yaml | 20 ++++++++++++-------- cwmscli/usgs/getusgs_cda.py | 2 -- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26cf21b..e31c51a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,26 +3,30 @@ repos: hooks: - id: black name: black - entry: poetry run black - language: system + entry: black + language: python + additional_dependencies: [black] types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: isort name: isort - entry: poetry run isort - language: system + entry: isort + language: python + additional_dependencies: [isort] types: [file, python] exclude: ^cwmscli/_generated/ownership_data\.py$ - id: yamlfix name: yamlfix - entry: poetry run yamlfix - language: system + entry: yamlfix + language: python + additional_dependencies: [yamlfix] types: [file, yaml] - id: ownership-sync name: generated ownership files - entry: poetry run python scripts/sync_ownership.py --check - language: system + entry: python scripts/sync_ownership.py --check + language: python + additional_dependencies: [poetry] pass_filenames: false diff --git a/cwmscli/usgs/getusgs_cda.py b/cwmscli/usgs/getusgs_cda.py index 81b1f6f..1db3350 100644 --- a/cwmscli/usgs/getusgs_cda.py +++ b/cwmscli/usgs/getusgs_cda.py @@ -370,7 +370,6 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): office = row["office-id"] values["quality-code"] = 0 - # 15 minute conversion to allow storing smaller interval data (eg. 5 minute) as 15 minute data if ts_id.split(".")[3] == "15Minutes": values_dt = values.copy() @@ -381,7 +380,6 @@ def CWMS_writeData(USGS_ts, USGS_data, USGS_data_method, days_back): values15 = values_dt.resample("15min").first() values = values15.reset_index() - # write values to CWMS database try: data = cwms.timeseries_df_to_json(