Skip to content

Commit

Permalink
#350: override file_location
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh committed Dec 19, 2024
1 parent 3af1fab commit c23b1f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion py_mmd_tools/nc_to_mmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,10 @@ def to_mmd(
platform : dict
A dictionary specifying the platform according to MMD
guidelines.
file_location : str
An alternative to the current file location. This can
be used if the NetCDF file will be moved after the
MMD file has been created.
This list can be extended but requires some new code...
"""
Expand All @@ -1671,6 +1675,7 @@ def to_mmd(
geographic_extent_rectangle = overrides.pop("geographic_extent_rectangle", None)
dataset_citation = overrides.pop("dataset_citation", None)
platform = overrides.pop("platform", None)
file_location = overrides.pop("file_location", os.path.dirname(self.netcdf_file))

# Get ncin object from instance
ncin = self.ncin
Expand Down Expand Up @@ -1836,7 +1841,7 @@ def to_mmd(
# Set storage_information
self.metadata["storage_information"] = {
"file_name": os.path.basename(self.netcdf_file),
"file_location": os.path.dirname(self.netcdf_file),
"file_location": file_location,
"file_format": "NetCDF-CF",
"file_size": "%.2f" % self.file_size,
"file_size_unit": "MB",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_nc_to_mmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def test_parent_keyword_arg(dataDir):
assert str(ve.value) == "UUID part of the parent ID is not valid"


@pytest.mark.py_mmd_tools
def test_file_location_in_overrides(dataDir):
"""Test that over-riding the file location works as expected.
"""
md = Nc_to_mmd(os.path.join(dataDir, "reference_nc.nc"), check_only=True)
req, msg = md.to_mmd()
assert md.metadata["storage_information"]["file_location"] == dataDir
md = Nc_to_mmd(os.path.join(dataDir, "reference_nc.nc"), check_only=True)
req, msg = md.to_mmd(overrides={"file_location": "/some/where/else",})
assert md.metadata["storage_information"]["file_location"] == "/some/where/else"


@pytest.mark.py_mmd_tools
def test_platform_in_overrides(dataDir):
"""Test that over-riding the platform attribute works as expected.
Expand Down

0 comments on commit c23b1f3

Please sign in to comment.