Skip to content

Commit

Permalink
#337: raise exception and resolve flake errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh committed Oct 2, 2024
1 parent 6515696 commit ab47412
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions py_mmd_tools/mmd_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<https://github.com/metno/py-mmd-tools/blob/master/LICENSE>
"""
import os
import re
import pytz
import uuid
import shutil
Expand Down Expand Up @@ -159,11 +158,7 @@ def move_data(mmd_repository_path, old_file_location_base, new_file_location_bas
# Error message
emsg = ""
nfl = new_file_location(nc_file, new_file_location_base, old_file_location_base)
try:
mmd_orig = get_local_mmd_git_path(nc_file, mmd_repository_path)
except Exception as e:
not_updated[nc_file] = f"Could not get MMD path of {nc_file}.\nError: {str(e)}"
continue
mmd_orig = get_local_mmd_git_path(nc_file, mmd_repository_path)

# Check permissions before doing anything
remove_file_allowed = os.access(nc_file, os.W_OK)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_mmd_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ class MockResponse:
def raise_(ex):
raise ex

# Test
# Test that an error is raised if we cannot find the MMD path
mp.setattr("py_mmd_tools.mmd_operations.datetime_glob.walk",
lambda *a, **k: mock_walk(*a, **k))
mp.setattr("py_mmd_tools.mmd_operations.get_local_mmd_git_path",
lambda *a, **k: raise_(Exception("No path")))
not_updated, updated = move_data(mmd_repository_path, old_file_location_base,
new_file_location_base, pattern)
assert "Could not get MMD path" in not_updated[list(not_updated.keys())[0]]
with pytest.raises(Exception):
not_updated, updated = move_data(mmd_repository_path, old_file_location_base,
new_file_location_base, pattern)

# Test os.access, remove_file_allowed is False
mock_access = Mock()
Expand Down Expand Up @@ -284,13 +284,13 @@ class MockResponse:
assert found is False
assert msg == "Could not find dataset in CSW catalog: /some/file.nc (id: no.met:123)"

class MockResponse:
class MockResponse2:

status_code = 200

with monkeypatch.context() as mp:
mp.setattr("py_mmd_tools.mmd_operations.requests.get",
lambda *a, **k: MockResponse())
lambda *a, **k: MockResponse2())
found, msg = check_csw_catalog(ds_id, nc_file, urls, env)
assert found is True
assert msg == ""
Expand Down

0 comments on commit ab47412

Please sign in to comment.