Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jul 26, 2023
1 parent b12fd52 commit cd1d2fa
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions autotest/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,71 +141,59 @@ def test_previous_assets():
@pytest.mark.dependency("mfexes")
@flaky(max_runs=RERUNS)
@pytest.mark.requests
def test_mfexes_download_and_unzip_and_zip(module_tmpdir):
def test_mfexes_download_and_unzip_and_zip(function_tmpdir):
exclude_files = [
"code.json",
"prms_constants.f90",
"prms_summary.f90",
"prms_time.f90",
"utils_prms.f90",
]
pymake.getmfexes(module_tmpdir, verbose=True)
for f in os.listdir(module_tmpdir):
fpth = os.path.join(module_tmpdir, f)
pymake.getmfexes(function_tmpdir, verbose=True)
for f in os.listdir(function_tmpdir):
fpth = os.path.join(function_tmpdir, f)
if not os.path.isdir(fpth) and f not in exclude_files:
errmsg = f"{fpth} not executable"
assert which(fpth) is not None, errmsg

# zip up exe's using files
zip_pth = os.path.join(
f"temp_mfexes_{os.path.basename(__file__).replace('.py', '')}",
"ziptest01.zip",
)
zip_pth = function_tmpdir / "ziptest01.zip"
print(f"creating '{zip_pth}'")
success = pymake.zip_all(
zip_pth,
str(zip_pth),
file_pths=[
os.path.join(module_tmpdir, e) for e in os.listdir(module_tmpdir)
os.path.join(function_tmpdir, e)
for e in os.listdir(function_tmpdir)
],
)
assert success, "could not create zipfile using file names"
os.remove(zip_pth)

# zip up exe's using directories
zip_pth = os.path.join(
f"temp_mfexes_{os.path.basename(__file__).replace('.py', '')}",
"ziptest02.zip",
)
zip_pth = function_tmpdir / "ziptest02.zip"
print(f"creating '{zip_pth}'")
success = pymake.zip_all(zip_pth, dir_pths=module_tmpdir)
success = pymake.zip_all(str(zip_pth), dir_pths=function_tmpdir)
assert success, "could not create zipfile using directories"
os.remove(zip_pth)

# zip up exe's using directories and a pattern
zip_pth = os.path.join(
f"temp_mfexes_{os.path.basename(__file__).replace('.py', '')}",
"ziptest03.zip",
)
zip_pth = function_tmpdir / "ziptest03.zip"
print(f"creating '{zip_pth}'")
success = pymake.zip_all(zip_pth, dir_pths=module_tmpdir, patterns="mf")
success = pymake.zip_all(
str(zip_pth), dir_pths=function_tmpdir, patterns="mf"
)
assert success, "could not create zipfile using directories and a pattern"
os.remove(zip_pth)

# zip up exe's using files and directories
zip_pth = os.path.join(
f"temp_mfexes_{os.path.basename(__file__).replace('.py', '')}",
"ziptest04.zip",
)
zip_pth = function_tmpdir / "ziptest04.zip"
print(f"creating '{zip_pth}'")
success = pymake.zip_all(
zip_pth,
str(zip_pth),
file_pths=[
os.path.join(module_tmpdir, e) for e in os.listdir(module_tmpdir)
os.path.join(function_tmpdir, e)
for e in os.listdir(function_tmpdir)
],
dir_pths=module_tmpdir,
dir_pths=function_tmpdir,
)
assert success, "could not create zipfile using files and directories"
os.remove(zip_pth)


@pytest.mark.dependency("nightly_download")
Expand Down Expand Up @@ -260,9 +248,9 @@ def test_target_keys():
@pytest.mark.dependency("export_json")
@flaky(max_runs=RERUNS)
@pytest.mark.requests
def test_usgsprograms_export_json():
def test_usgsprograms_export_json(module_tmpdir):
# export code.json and return json file path
fpth = export_code_json(file_name="code.export.json")
fpth = export_code_json(module_tmpdir, file_name="code.export.json")

# test the json export
with open(fpth, "r") as f:
Expand Down Expand Up @@ -305,9 +293,9 @@ def test_usgsprograms_load_json_error(module_tmpdir):
@pytest.mark.dependency("load_json")
@flaky(max_runs=RERUNS)
@pytest.mark.requests
def test_usgsprograms_load_json():
def test_usgsprograms_load_json(module_tmpdir):
# export code.json and return json file path
fpth = export_code_json(file_name="code.load.json")
fpth = export_code_json(module_tmpdir, file_name="code.load.json")

json_dict = pymake.usgs_program_data.load_json(fpth)

Expand All @@ -328,8 +316,8 @@ def test_usgsprograms_list_json_error(module_tmpdir):
@pytest.mark.dependency("list_json")
@flaky(max_runs=RERUNS)
@pytest.mark.requests
def test_usgsprograms_list_json():
fpth = export_code_json(file_name="code.list.json")
def test_usgsprograms_list_json(module_tmpdir):
fpth = export_code_json(module_tmpdir, file_name="code.list.json")
pymake.usgs_program_data.list_json(fpth=fpth)


Expand Down

0 comments on commit cd1d2fa

Please sign in to comment.