Skip to content

Commit

Permalink
fix: incorrect path from METADATA attribute
Browse files Browse the repository at this point in the history
Merge pull request #82 from csdms/mcflugen/fix-metadata-dir
  • Loading branch information
mcflugen authored May 14, 2019
2 parents 556eb6e + 9137210 commit 53b174b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pymt/framework/bmi_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def find_model_metadata(plugin):
Path to the folder that contains the plugin's metadata.
"""
try:
model_metadata_dir = plugin.METADATA
model_metadata_dir = plugin.METADATA or "."
except AttributeError:
if isinstance(plugin, six.string_types):
plugin_name = plugin
Expand All @@ -87,11 +87,14 @@ def find_model_metadata(plugin):

path_to_mmd = bmi_data_dir(plugin_name)
else:
path_to_mmd = pkg_resources.resource_filename(
plugin.__module__, model_metadata_dir
)
if not os.path.isabs(model_metadata_dir):
path_to_mmd = pkg_resources.resource_filename(
plugin.__module__, model_metadata_dir
)
else:
path_to_mmd = model_metadata_dir

return path_to_mmd
return os.path.abspath(path_to_mmd)


class PluginMetadata(ModelMetadata):
Expand Down
2 changes: 1 addition & 1 deletion pymt/printers/nc/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def set_variable(self, name, *args, **kwds):
else:
variable[n_times] = array[0]
else:
variable[:] = array.flat
variable[:] = array.reshape(variable.shape)

def data_variable(self, name):
return self.root.variables[name]
Expand Down
14 changes: 14 additions & 0 deletions tests/framework/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import pytest

from pymt.framework.bmi_setup import _parse_author_info
from pymt.framework.bmi_metadata import find_model_metadata


@pytest.mark.parametrize("key", ("author", "authors"))
Expand All @@ -25,3 +27,15 @@ def test_author_multiple_authors(key, iter):
"John Cleese",
"Eric Idle",
)


@pytest.mark.parametrize("path_to_meta", ("", ".", "meta", "/usr/local/share"))
def test_find_metadata(path_to_meta):
expected = os.path.abspath(os.path.join(os.path.dirname(__file__), path_to_meta))
if expected.endswith(os.path.sep):
expected = expected[:-1]

class _MyBmi:
METADATA = path_to_meta

assert find_model_metadata(_MyBmi) == expected

0 comments on commit 53b174b

Please sign in to comment.