Skip to content

Commit

Permalink
per #2096, move tests for find_and_check_output_file to CommandBuilde…
Browse files Browse the repository at this point in the history
…r tests and add tests to demonstrate bug that incorrectly skips grid_stat runs when a given valid time has already been processed
  • Loading branch information
georgemccabe committed Mar 22, 2023
1 parent f24db75 commit 5242fb6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,60 @@ def test_get_field_info_extra(metplus_config, extra, expected_value):
add_curly_braces=False
)[0]
assert actual_value == expected_value


@pytest.mark.parametrize(
'exists, skip, is_dir, use_prefix, run', [
(True, True, False, True, False),
(True, False, False, True, True),
(False, True, False, True, True),
(False, False, False, True, True),
(True, True, True, True, False),
(True, False, True, True, True),
(False, True, True, True, True),
(False, False, True, True, True),
(True, True, False, False, False),
(True, False, False, False, True),
(False, True, False, False, True),
(False, False, False, False, True),
(True, True, True, False, False),
(True, False, True, False, True),
(False, True, True, False, True),
(False, False, True, False, True),
]
)
@pytest.mark.wrapper
def test_find_and_check_output_file_skip(metplus_config, exists, skip, is_dir,
use_prefix, run):
app_name = 'command_builder'
config = metplus_config
if use_prefix:
config.set('config', f'{app_name.upper()}_OUTPUT_PREFIX', 'prefix')
wrapper = CommandBuilder(config)
wrapper.app_name = app_name
prefix = f'{app_name}_prefix' if use_prefix else app_name
exist_file = f'{prefix}_120000L_20190201_000000V.stat'
non_exist_file = f'{prefix}_240000L_20190201_000000V.stat'

# create fake file to test
create_fullpath = os.path.join(config.getdir('OUTPUT_BASE'), exist_file)
open(create_fullpath, 'a').close()

# set time_info, output template/dir, skip if output exists flag
task_info = {'valid': datetime.datetime(2019, 2, 1, 0)}
if is_dir:
task_info['lead_hours'] = 12 if exists else 24

time_info = ti_calculate(task_info)
wrapper.c_dict['OUTPUT_DIR'] = wrapper.config.getdir('OUTPUT_BASE')

wrapper.c_dict['SKIP_IF_OUTPUT_EXISTS'] = skip
if is_dir:
wrapper.c_dict['OUTPUT_TEMPLATE'] = ''
else:
wrapper.c_dict['OUTPUT_TEMPLATE'] = exist_file if exists else non_exist_file

result = wrapper.find_and_check_output_file(time_info, is_directory=is_dir)

# cast result to bool because None isn't equal to False
assert bool(result) == run
35 changes: 0 additions & 35 deletions internal/tests/pytests/wrappers/pb2nc/test_pb2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,6 @@ def pb2nc_wrapper(metplus_config):
return PB2NCWrapper(config)


@pytest.mark.parametrize(
'exists, skip, run', [
(True, True, False),
(True, False, True),
(False, True, True),
(False, False, True),
]
)
@pytest.mark.wrapper
def test_find_and_check_output_file_skip(metplus_config, exists, skip, run):
pb = pb2nc_wrapper(metplus_config)
exist_file = 'wackyfilenametocreate'
non_exist_file = 'wackyfilethatdoesntexist'

# create fake file to test
create_fullpath = os.path.join(pb.config.getdir('OUTPUT_BASE'), exist_file)
open(create_fullpath, 'a').close()

# set time_info, output template/dir, skip if output exists flag
time_info = { 'valid' : datetime.datetime(2019, 2, 1, 0) }
pb.c_dict['OUTPUT_DIR'] = pb.config.getdir('OUTPUT_BASE')

pb.c_dict['SKIP_IF_OUTPUT_EXISTS'] = skip

if exists:
pb.c_dict['OUTPUT_TEMPLATE'] = exist_file
else:
pb.c_dict['OUTPUT_TEMPLATE'] = non_exist_file

result = pb.find_and_check_output_file(time_info)

# cast result to bool because None isn't equal to False
assert bool(result) == run


# ---------------------
# test_get_command
# test that command is generated correctly
Expand Down

0 comments on commit 5242fb6

Please sign in to comment.