From 042b3948528e97b60d1361e6d582fc3bcc94396c Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Tue, 6 Jun 2023 13:39:13 -0600 Subject: [PATCH] Feature #1610 first round of SonarQube fixes (#2200) --- .github/actions/run_tests/entrypoint.sh | 2 +- .../config_metplus/test_config_metplus.py | 4 +- .../string_manip/test_util_string_manip.py | 12 + .../stat_analysis/test_stat_analysis.py | 2 +- metplus/util/config_metplus.py | 291 +- metplus/util/config_validate.py | 153 +- metplus/util/diff_util.py | 0 metplus/util/doc_util.py | 297 +- metplus/util/field_util.py | 149 +- metplus/util/met_config.py | 154 +- metplus/util/run_util.py | 184 +- metplus/util/string_manip.py | 19 +- metplus/util/string_template_substitution.py | 17 +- metplus/util/system_util.py | 19 +- metplus/wrappers/command_builder.py | 264 +- metplus/wrappers/command_runner.py | 23 +- metplus/wrappers/compare_gridded_wrapper.py | 2 +- metplus/wrappers/cyclone_plotter_wrapper.py | 80 +- metplus/wrappers/ensemble_stat_wrapper.py | 47 +- metplus/wrappers/gfdl_tracker_wrapper.py | 35 +- metplus/wrappers/pcp_combine_wrapper.py | 17 +- metplus/wrappers/py_embed_ingest_wrapper.py | 3 - metplus/wrappers/reformat_gridded_wrapper.py | 1 - metplus/wrappers/series_analysis_wrapper.py | 8 +- metplus/wrappers/stat_analysis_wrapper.py | 86 +- metplus/wrappers/tc_gen_wrapper.py | 8 +- metplus/wrappers/tc_pairs_wrapper.py | 41 +- produtil/cluster.py | 152 +- produtil/config.py | 171 +- produtil/datastore.py | 25 +- produtil/fileop.py | 77 +- produtil/locking.py | 2 +- produtil/log.py | 9 +- produtil/mpi_impl/__init__.py | 57 +- produtil/mpi_impl/mpi_impl_base.py | 30 +- produtil/mpi_impl/srun.py | 18 +- produtil/mpiprog.py | 57 +- produtil/numerics.py | 88 +- produtil/pipeline.py | 111 +- produtil/prog.py | 12 +- produtil/retry.py | 12 +- produtil/run.py | 8 +- produtil/testing/__init__.py | 12 - produtil/testing/parse.py | 1434 --------- produtil/testing/parsetree.py | 2781 ----------------- produtil/testing/rocoto.py | 740 ----- produtil/testing/script.py | 374 --- produtil/testing/setarith.py | 290 -- produtil/testing/testgen.py | 171 - produtil/testing/tokenize.py | 275 -- produtil/testing/utilities.py | 304 -- 51 files changed, 1474 insertions(+), 7654 deletions(-) mode change 100644 => 100755 metplus/util/diff_util.py delete mode 100644 produtil/testing/__init__.py delete mode 100644 produtil/testing/parse.py delete mode 100644 produtil/testing/parsetree.py delete mode 100644 produtil/testing/rocoto.py delete mode 100644 produtil/testing/script.py delete mode 100644 produtil/testing/setarith.py delete mode 100644 produtil/testing/testgen.py delete mode 100644 produtil/testing/tokenize.py delete mode 100644 produtil/testing/utilities.py diff --git a/.github/actions/run_tests/entrypoint.sh b/.github/actions/run_tests/entrypoint.sh index 6c5da65ea2..bd2aa579dc 100644 --- a/.github/actions/run_tests/entrypoint.sh +++ b/.github/actions/run_tests/entrypoint.sh @@ -61,7 +61,7 @@ if [[ "$INPUT_CATEGORIES" == pytests* ]]; then for x in `cat $PYTESTS_GROUPS_FILEPATH`; do marker="${x//_or_/ or }" marker="${marker//not_/not }" - command+="/usr/local/conda/envs/${METPLUS_ENV_TAG}/bin/pytest -vv --cov=../../../metplus -m \"$marker\"" + command+="/usr/local/conda/envs/${METPLUS_ENV_TAG}/bin/pytest -vv --cov=../../../metplus --cov-append -m \"$marker\"" command+=";if [ \$? != 0 ]; then status=1; fi;" done command+="if [ \$status != 0 ]; then echo ERROR: Some pytests failed. Search for FAILED to review; false; fi" diff --git a/internal/tests/pytests/util/config_metplus/test_config_metplus.py b/internal/tests/pytests/util/config_metplus/test_config_metplus.py index 8dda66dea1..ca6daf44f6 100644 --- a/internal/tests/pytests/util/config_metplus/test_config_metplus.py +++ b/internal/tests/pytests/util/config_metplus/test_config_metplus.py @@ -162,8 +162,8 @@ def test_find_var_indices_fcst(metplus_config, ) @pytest.mark.util def test_get_field_search_prefixes(data_type, met_tool, expected_out): - assert(config_metplus.get_field_search_prefixes(data_type, - met_tool) == expected_out) + assert(config_metplus._get_field_search_prefixes(data_type, + met_tool) == expected_out) # search prefixes are valid prefixes to append to field info variables diff --git a/internal/tests/pytests/util/string_manip/test_util_string_manip.py b/internal/tests/pytests/util/string_manip/test_util_string_manip.py index d53f19b469..38eb260440 100644 --- a/internal/tests/pytests/util/string_manip/test_util_string_manip.py +++ b/internal/tests/pytests/util/string_manip/test_util_string_manip.py @@ -8,6 +8,18 @@ from metplus.util.string_manip import * from metplus.util.string_manip import _fix_list +@pytest.mark.parametrize( + 'template, expected_output', [ + ('', ''), + ('{init?fmt=%Y%m%d}_i{init?fmt=%H%M}_m0_f*', + r'{init?fmt=%Y%m%d}_i{init?fmt=%H%M}_m0_f*'), + ('pgbf{lead?fmt=%HHH}.gfs.{init?fmt=%Y%m%d%H}', + r'pgbf.*\.gfs\.{init?fmt=%Y%m%d%H}'), + ] +) +@pytest.mark.util +def test_template_to_regex(template, expected_output): + assert template_to_regex(template) == expected_output @pytest.mark.parametrize( 'subset_definition, expected_result', [ diff --git a/internal/tests/pytests/wrappers/stat_analysis/test_stat_analysis.py b/internal/tests/pytests/wrappers/stat_analysis/test_stat_analysis.py index 1ef38667f1..de609612ab 100644 --- a/internal/tests/pytests/wrappers/stat_analysis/test_stat_analysis.py +++ b/internal/tests/pytests/wrappers/stat_analysis/test_stat_analysis.py @@ -198,7 +198,7 @@ def test_valid_init_env_vars(metplus_config, config_overrides, runtime_settings_dict_list = wrapper._get_all_runtime_settings(time_input) assert runtime_settings_dict_list - first_runtime_only = [runtime_settings_dict_list[0]] + first_runtime_only = runtime_settings_dict_list[0] wrapper._run_stat_analysis_job(first_runtime_only) all_cmds = wrapper.all_commands diff --git a/metplus/util/config_metplus.py b/metplus/util/config_metplus.py index 988472d630..f90aeed939 100644 --- a/metplus/util/config_metplus.py +++ b/metplus/util/config_metplus.py @@ -160,7 +160,7 @@ def _parse_launch_args(args): bad = False for arg in args: m = re.match(r'''(?x) - (?P
[a-zA-Z][a-zA-Z0-9_]*) + (?P
[a-zA-Z]\w*) \.(?P