Skip to content

Commit

Permalink
fixed regression in test
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepearson committed Aug 8, 2024
1 parent 8326f4e commit ae07267
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_dem_generation_local_2/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,47 @@ def tearDownClass(cls):
gc.collect()
cls.clean_data_folder()

@classmethod
def clean_data_folder(cls):
"""Remove all generated or downloaded files from the data directory,
but with only warnings if files can't be removed."""

assert cls.cache_dir.exists(), (
"The data directory that should include the comparison benchmark dem file "
"doesn't exist"
)

# Cycle through all folders within the cache dir deleting their contents
for path in cls.cache_dir.iterdir():
if path.is_dir():
for file in path.glob("*"): # only files
if file.is_file():
try:
file.unlink()
except (Exception, PermissionError) as caught_exception:
logging.warning(
f"Caught error {caught_exception} during "
f"rmtree of {file}. Supressing error. You "
"will have to manually delete."
)
elif file.is_dir():
try:
shutil.rmtree(file)
except (Exception, PermissionError) as caught_exception:
logging.warning(
f"Caught error {caught_exception} during "
f"rmtree of {file}. Supressing error. You "
"will have to manually delete."
)
try:
shutil.rmtree(path)
except (Exception, PermissionError) as caught_exception:
logging.warning(
f"Caught error {caught_exception} during rmtree of "
f"{path}. Supressing error. You will have to manually "
"delete."
)

def test_result_dem(self):
"""A basic comparison between the generated and benchmark DEM"""

Expand Down

0 comments on commit ae07267

Please sign in to comment.