Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Jun 27, 2024
1 parent d839fb3 commit 94e51e3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion h5rdmtoolbox/convention/standard_names/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_snt(snt: Union[str, dict, StandardNameTable]) -> StandardNameTable:
if snt[0] == '{':
return StandardNameTable.from_dict(json.loads(snt))
if 'zenodo.' in snt:
return StandardNameTable.from_zenodo(snt)
return StandardNameTable.from_zenodo(source=snt)

fname = pathlib.Path(snt)
logger.debug(f'Reading standard name table from file {snt}')
Expand Down
7 changes: 4 additions & 3 deletions h5rdmtoolbox/tutorial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Tutorial module providing easy access to particular data.
"""
import numpy as np
import os
import pathlib
from typing import List

import numpy as np
import xarray as xr
from rdflib import FOAF
from typing import List

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox.convention.standard_names.table import StandardNameTable
Expand Down Expand Up @@ -361,7 +362,7 @@ def _upload_tutorial_data_to_zenodo():
A valid Zenodo (not sandbox!) token with write permission is needed!"""
from h5rdmtoolbox.repository import zenodo

repo = zenodo.ZenodoRecord(12541214)
repo = zenodo.ZenodoRecord(TutorialConventionZenodoRecordID)

description = """<p>A YAML file containing definitions of standard attributes used as part of the documentation of the <a href="http://h5rdmtoolbox.readthedocs.io/">h5RDMtoolbox</a>. It serves as a <a href="https://h5rdmtoolbox.readthedocs.io/en/latest/userguide/convention/index.html">convention</a> on how attributes are used in HDF5 files.</p>
<p>Works with h5RDMtoolbox&gt;v1.0.0.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import unittest

import matplotlib.pyplot as plt
import numpy as np
import unittest
import xarray as xr

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox.convention.standard_names import HDF5StandardNameInterface
from h5rdmtoolbox.repository import zenodo
from h5rdmtoolbox.tutorial import TutorialConventionZenodoRecordID


class TestStandardAttributes(unittest.TestCase):

def setUp(self) -> None:
# cv = h5tbx.convention.from_zenodo(doi_or_recid=10428822, overwrite=True)
repo = zenodo.ZenodoRecord(10428822)
repo = zenodo.ZenodoRecord(TutorialConventionZenodoRecordID)
cv = h5tbx.convention.from_repo(repo,
name='tutorial_convention.yaml',
take_existing=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import requests
import unittest
import warnings

import requests

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox import errors
from h5rdmtoolbox import tutorial
from h5rdmtoolbox.convention.standard_names import StandardName
from h5rdmtoolbox.convention.standard_names.transformation import Transformation
from h5rdmtoolbox.tutorial import TutorialSNTZenodoRecordID


def maximum_of(match, snt):
Expand Down Expand Up @@ -41,9 +43,9 @@ def setUp(self) -> None:
self.snt = h5tbx.tutorial.get_standard_name_table()

def test_adding_transformation(self):
snt = h5tbx.convention.standard_names.StandardNameTable.from_zenodo(doi_or_recid=10428795)
snt = h5tbx.convention.standard_names.StandardNameTable.from_zenodo(source=TutorialSNTZenodoRecordID)
from h5rdmtoolbox.repository.zenodo import ZenodoRecord
z = ZenodoRecord(rec_id=10428795)
z = ZenodoRecord(source=TutorialSNTZenodoRecordID)
self.assertTrue(z.exists())

# check if the problem really exists:
Expand Down
16 changes: 5 additions & 11 deletions tests/conventions/standard_attributes/test_standard_names.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import requests
import unittest
import warnings

import requests

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox import tutorial
from h5rdmtoolbox.tutorial import TutorialSNTZenodoRecordID
from h5rdmtoolbox.convention.errors import StandardNameError, StandardAttributeError
from h5rdmtoolbox.convention.standard_names import utils
from h5rdmtoolbox.convention.standard_names.name import StandardName
Expand Down Expand Up @@ -219,9 +221,9 @@ def test_to_html(self):

def test_from_zenodo(self):
if self.connected:
snt = StandardNameTable.from_zenodo(doi_or_recid=10428795)
snt = StandardNameTable.from_zenodo(siurce=TutorialSNTZenodoRecordID)
self.assertIsInstance(snt, StandardNameTable)
filename = h5tbx.UserDir['standard_name_tables'] / f'10428795.yaml'
filename = h5tbx.UserDir['standard_name_tables'] / f'{TutorialSNTZenodoRecordID}.yaml'
self.assertTrue(filename.exists())
# filename.unlink(missing_ok=True)

Expand Down Expand Up @@ -249,11 +251,3 @@ def test_from_yaml(self):

with self.assertRaises(StandardAttributeError):
h5.create_dataset('velocity', data=2.3, units='m/s', standard_name='velocity')

def test_snt_jsonld_dump(self):
cv = h5tbx.convention.from_yaml(tutorial.get_convention_yaml_filename(), overwrite=True)
h5tbx.use(cv)
with h5tbx.File() as h5:
h5.attrs['standard_name_table'] = "https://zenodo.org/records/10428795/file/fan_standard_name_table.yaml"
print(h5.dump_jsonld())
h5tbx.use(None)

0 comments on commit 94e51e3

Please sign in to comment.