Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix METADATA attribute #82

Merged
merged 6 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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