Skip to content

Commit

Permalink
use exceptions to avoid PermissionError for removing old test files
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Jan 20, 2025
1 parent 1ef664e commit ab469b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
22 changes: 16 additions & 6 deletions tests/rr/test_fnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,11 @@ def test_fnm_save_as_with_recurse_correctly_copies_subfiles():
target_path = test_output_dir / name

if target_path.exists() and target_path.is_dir():
shutil.rmtree(target_path)
target_path.mkdir()
try:
shutil.rmtree(target_path)
except PermissionError:
pass
target_path.mkdir(exist_ok=True)

with file_load_context() as context:
context.push_new_parent(source_path_parent, ResolveRelativeMode.ToParent)
Expand Down Expand Up @@ -359,8 +362,12 @@ def test_fnm_save_without_recurse_only_copies_fnm_file():
target_path = test_output_dir / name

if target_path.exists() and target_path.is_dir():
shutil.rmtree(target_path)
target_path.mkdir()
try:
shutil.rmtree(target_path)
except PermissionError:
pass

target_path.mkdir(exist_ok=True)

with file_load_context() as context:
context.push_new_parent(source_path_parent, ResolveRelativeMode.ToParent)
Expand All @@ -387,8 +394,11 @@ def test_dimr_model_save_with_recurse_correctly_copies_rr_sub_files():
target_path = test_output_dir / name

if target_path.exists() and target_path.is_dir():
shutil.rmtree(target_path)
target_path.mkdir()
try:
shutil.rmtree(target_path)
except PermissionError:
pass
target_path.mkdir(exist_ok=True)

with file_load_context() as context:
context.push_new_parent(source_path_parent, ResolveRelativeMode.ToParent)
Expand Down
14 changes: 10 additions & 4 deletions tests/test_basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ def test_save_and_load_maintains_correct_paths(
)

if _external_path.exists():
shutil.rmtree(_external_path)
try:
shutil.rmtree(_external_path)
except PermissionError:
pass

if output_dir.exists():
shutil.rmtree(output_dir)
try:
shutil.rmtree(output_dir)
except PermissionError:
pass

model_path = output_dir / "fm.mdu"

Expand Down Expand Up @@ -403,7 +409,7 @@ def create_bc_file(self, tmp_path: Path, name: str):
Name = global
Function = timeseries
Time-interpolation = linear
Quantity = time
Quantity = time
Unit = minutes since 2006-12-25 0:00:00
Quantity = rainfall_rate
Unit = mm day-1
Expand Down Expand Up @@ -431,7 +437,7 @@ def change_bc_file(self, tmp_path: Path, name: str):
Name = little_change_to_the_file
Function = timeseries
Time-interpolation = linear
Quantity = time
Quantity = time
Unit = minutes since 2006-12-25 0:00:00
Quantity = rainfall_rate
Unit = mm day-1
Expand Down
5 changes: 4 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def test_mdu_model():
output_fn = output_dir / FMModel._generate_name()

if output_dir.exists():
shutil.rmtree(output_dir)
try:
shutil.rmtree(output_dir)
except PermissionError:
pass

model.save(filepath=output_fn, recurse=True)

Expand Down

0 comments on commit ab469b9

Please sign in to comment.