Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7dddabb
add sample datasets to git
valeriupredoi Oct 8, 2025
7fda631
remove previously gitted file
valeriupredoi Oct 9, 2025
71c7add
remove previously gitted file
valeriupredoi Oct 9, 2025
1ba9788
remove previously gitted file
valeriupredoi Oct 9, 2025
15a5e71
use tmp dir factory to write temp hdf5 files
valeriupredoi Oct 9, 2025
034b3fd
add modular temp dir to conftest
valeriupredoi Oct 9, 2025
4166aec
remove identical fixture from two test modules since now it is in con…
valeriupredoi Oct 9, 2025
11632c6
remove file that gets created on the fly
valeriupredoi Oct 10, 2025
864ccae
arrange file creation on the fly
valeriupredoi Oct 10, 2025
c53fc5c
move file in test
valeriupredoi Oct 10, 2025
1069df5
move files to data dir
valeriupredoi Oct 10, 2025
cee6acb
remove file
valeriupredoi Oct 10, 2025
1c53afa
remove file
valeriupredoi Oct 10, 2025
45c57e1
run with moved file
valeriupredoi Oct 10, 2025
866ef03
move file
valeriupredoi Oct 10, 2025
05a0dc1
remove file
valeriupredoi Oct 10, 2025
41098b5
ove test file in test
valeriupredoi Oct 10, 2025
800a0ca
remove file
valeriupredoi Oct 10, 2025
33d8c1f
move file to data
valeriupredoi Oct 10, 2025
3c36d86
correct path in test
valeriupredoi Oct 10, 2025
374a93d
use new path in test
valeriupredoi Oct 10, 2025
ac03056
move file
valeriupredoi Oct 10, 2025
d3f8e29
move file
valeriupredoi Oct 10, 2025
347c8ec
new pathed file
valeriupredoi Oct 10, 2025
a595514
move file
valeriupredoi Oct 10, 2025
36d03e8
move file
valeriupredoi Oct 10, 2025
c55cd31
move all other hdf5 files
valeriupredoi Oct 10, 2025
e479e8b
move files
valeriupredoi Oct 10, 2025
21cd30a
add hdf5 files
valeriupredoi Oct 10, 2025
2b61ab9
use file from data
valeriupredoi Oct 10, 2025
61ec6e4
move file
valeriupredoi Oct 10, 2025
07cbc1f
move file
valeriupredoi Oct 10, 2025
58dd9e2
move file
valeriupredoi Oct 10, 2025
6f75eb2
rm file
valeriupredoi Oct 10, 2025
d0fbf70
last two test changes
valeriupredoi Oct 10, 2025
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
Binary file removed tests/attr_datatypes_2.hdf5
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ def s3fs_s3(s3_base):
s3.invalidate_cache()

yield s3


@pytest.fixture(scope="module")
def modular_tmp_path(tmp_path_factory):
return tmp_path_factory.mktemp("temp")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified tests/data/enum_variable.hdf5
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed tests/enum_variable.hdf5
Binary file not shown.
114 changes: 62 additions & 52 deletions tests/make_attr_datatypes_file_2.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
#! /usr/bin/env python

""" Create a HDF5 file with all the supported attribute types (2)"""
import sys

import h5py
import numpy as np

from pathlib import Path

with h5py.File('attr_datatypes_2.hdf5', 'w') as ds:
dt = h5py.string_dtype("utf-8")
unicode = "unicodé"
ds.attrs["unicode"] = unicode
ds.attrs["unicode_0dim"] = np.array(unicode, dtype=dt)
ds.attrs["unicode_1dim"] = np.array([unicode], dtype=dt)
ds.attrs["unicode_arrary"] = np.array([unicode, "foobár"], dtype=dt)
ds.attrs["unicode_list"] = [unicode]

dt = h5py.string_dtype("ascii")
# if dtype is ascii it's irrelevant if the data is provided as bytes or string
ascii = "ascii"
ds.attrs["ascii"] = ascii
ds.attrs["ascii_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["ascii_array"] = np.array([ascii, "foobar"], dtype=dt)
ds.attrs["ascii_list"] = [ascii]

ascii = b"ascii"
ds.attrs["bytes"] = ascii
ds.attrs["bytes_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["bytes_array"] = np.array([ascii, b"foobar"], dtype=dt)
ds.attrs["bytes_list"] = [ascii]

dt = h5py.string_dtype("utf-8", 10)
# unicode needs to be encoded properly for fixed size string type
ds.attrs["unicode_fixed"] = np.array(unicode.encode("utf-8"), dtype=dt)
ds.attrs["unicode_fixed_0dim"] = np.array(unicode.encode("utf-8"), dtype=dt)
ds.attrs["unicode_fixed_1dim"] = np.array([unicode.encode("utf-8")], dtype=dt)
ds.attrs["unicode_fixed_arrary"] = np.array(
[unicode.encode("utf-8"), "foobár".encode()], dtype=dt
)

dt = h5py.string_dtype("ascii", 10)
ascii = "ascii"
ds.attrs["ascii_fixed"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_fixed_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_fixed_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["ascii_fixed_array"] = np.array([ascii, "foobar"], dtype=dt)

ascii = b"ascii"
ds.attrs["bytes_fixed"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_fixed_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_fixed_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["bytes_fixed_array"] = np.array([ascii, b"foobar"], dtype=dt)

ds.attrs["int"] = 1
ds.attrs["intlist"] = [1]
ds.attrs["int_array"] = np.arange(10)
ds.attrs["empty_list"] = []
ds.attrs["empty_array"] = np.array([])

def create_file(fpath):
with h5py.File(fpath, 'w') as ds:
dt = h5py.string_dtype("utf-8")
unicode = "unicodé"
ds.attrs["unicode"] = unicode
ds.attrs["unicode_0dim"] = np.array(unicode, dtype=dt)
ds.attrs["unicode_1dim"] = np.array([unicode], dtype=dt)
ds.attrs["unicode_arrary"] = np.array([unicode, "foobár"], dtype=dt)
ds.attrs["unicode_list"] = [unicode]

dt = h5py.string_dtype("ascii")
# if dtype is ascii it's irrelevant if the data is provided as bytes or string
ascii = "ascii"
ds.attrs["ascii"] = ascii
ds.attrs["ascii_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["ascii_array"] = np.array([ascii, "foobar"], dtype=dt)
ds.attrs["ascii_list"] = [ascii]

ascii = b"ascii"
ds.attrs["bytes"] = ascii
ds.attrs["bytes_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["bytes_array"] = np.array([ascii, b"foobar"], dtype=dt)
ds.attrs["bytes_list"] = [ascii]

dt = h5py.string_dtype("utf-8", 10)
# unicode needs to be encoded properly for fixed size string type
ds.attrs["unicode_fixed"] = np.array(unicode.encode("utf-8"), dtype=dt)
ds.attrs["unicode_fixed_0dim"] = np.array(unicode.encode("utf-8"), dtype=dt)
ds.attrs["unicode_fixed_1dim"] = np.array([unicode.encode("utf-8")], dtype=dt)
ds.attrs["unicode_fixed_arrary"] = np.array(
[unicode.encode("utf-8"), "foobár".encode()], dtype=dt
)

dt = h5py.string_dtype("ascii", 10)
ascii = "ascii"
ds.attrs["ascii_fixed"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_fixed_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["ascii_fixed_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["ascii_fixed_array"] = np.array([ascii, "foobar"], dtype=dt)

ascii = b"ascii"
ds.attrs["bytes_fixed"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_fixed_0dim"] = np.array(ascii, dtype=dt)
ds.attrs["bytes_fixed_1dim"] = np.array([ascii], dtype=dt)
ds.attrs["bytes_fixed_array"] = np.array([ascii, b"foobar"], dtype=dt)

ds.attrs["int"] = 1
ds.attrs["intlist"] = [1]
ds.attrs["int_array"] = np.arange(10)
ds.attrs["empty_list"] = []
ds.attrs["empty_array"] = np.array([])


if __name__ == "__main__":
default_path = Path(__file__).parent / "attr_datatypes_2.hdf5"
filepath = Path(sys.argv[1]) if len(sys.argv) > 1 else default_path
create_file(filepath)
15 changes: 12 additions & 3 deletions tests/test_attr_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
ATTR_DATATYPES_HDF5_FILE = os.path.join(DIRNAME, 'attr_datatypes.hdf5')
ATTR_DATATYPES_HDF5_FILE = os.path.join(DIRNAME, "data", 'attr_datatypes.hdf5')
MAKE_ATTR_DATATYPES_SCRIPT = os.path.join(DIRNAME, 'make_attr_datatypes_file.py')
ATTR_DATATYPES_HDF5_FILE_2 = os.path.join(DIRNAME, 'attr_datatypes_2.hdf5')
MAKE_ATTR_DATATYPES_SCRIPT_2 = os.path.join(DIRNAME, 'make_attr_datatypes_file_2.py')


@pytest.fixture(scope="module")
Expand All @@ -23,6 +24,14 @@ def attr_datatypes_hdf5(tmp_path_factory):
return str(path)


@pytest.fixture(scope="module")
def attr_datatypes_hdf5_2(tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("attr_datatypes")
path = tmp_dir / "attr_datatypes_2.hdf5"
subprocess.run([sys.executable, MAKE_ATTR_DATATYPES_SCRIPT_2, str(path)], check=True)
return str(path)


def test_numeric_scalar_attr_datatypes():

with pyfive.File(ATTR_DATATYPES_HDF5_FILE) as hfile:
Expand Down Expand Up @@ -156,12 +165,12 @@ def test_empty_string_datatypes(attr_datatypes_hdf5):
assert enum_attr.dtype == np.dtype('|S1')


def test_attributes_2():
def test_attributes_2(attr_datatypes_hdf5_2):

ascii = "ascii"
unicode = "unicodé"

with pyfive.File(ATTR_DATATYPES_HDF5_FILE_2) as ds:
with pyfive.File(attr_datatypes_hdf5_2) as ds:
foobar = "foobár"
assert isinstance(ds.attrs["unicode"], str)
assert ds.attrs["unicode"] == unicode
Expand Down
2 changes: 1 addition & 1 deletion tests/test_chunked.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
DATASET_CHUNKED_HDF5_FILE = os.path.join(DIRNAME, 'chunked.hdf5')
DATASET_CHUNKED_HDF5_FILE = os.path.join(DIRNAME, "data", 'chunked.hdf5')


def test_chunked_dataset():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def data():


@pytest.fixture(scope='module')
def name(data):
name = os.path.join(os.path.dirname(__file__), 'compact.hdf5')
def name(data, modular_tmp_path):
name = modular_tmp_path / 'compact.hdf5'

f = h5py.File(name, 'w', libver='earliest')
dtype = h5py.h5t.NATIVE_INT32
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compressed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
DATASET_COMPRESSED_HDF5_FILE = os.path.join(DIRNAME, 'compressed.hdf5')
DATASET_COMPRESSED_HDF5_FILE = os.path.join(DIRNAME, "data", 'compressed.hdf5')


def test_compressed_dataset():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compressed_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
DATASET_COMPRESSED_HDF5_FILE = os.path.join(DIRNAME, 'compressed_v1.hdf5')
DATASET_COMPRESSED_HDF5_FILE = os.path.join(DIRNAME, 'data', 'compressed_v1.hdf5')


def test_compressed_v1_dataset():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataset_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
DATASET_DATATYPES_HDF5_FILE = os.path.join(DIRNAME, 'dataset_datatypes.hdf5')
DATASET_DATATYPES_HDF5_FILE = os.path.join(DIRNAME, 'data', 'dataset_datatypes.hdf5')
MAKE_DATASET_DATATYPES_SCRIPT = os.path.join(DIRNAME, 'make_dataset_datatypes_file.py')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_dim_scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
DIM_SCALES_HDF5_FILE = os.path.join(DIRNAME, './dim_scales.hdf5')
DIM_SCALES_HDF5_FILE = os.path.join(DIRNAME, 'data', 'dim_scales.hdf5')


def test_dim_labels():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_earliest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
EARLIEST_HDF5_FILE = os.path.join(DIRNAME, 'earliest.hdf5')
EARLIEST_HDF5_FILE = os.path.join(DIRNAME, 'data', 'earliest.hdf5')

# Polygot string type for representing unicode
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_enum_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
ENUMVAR_NC_FILE = os.path.join(DIRNAME, 'enum_variable.nc')
ENUMVAR_H5_FILE = os.path.join(DIRNAME, 'enum_variable.hdf5')
ENUMVAR_NC_FILE = os.path.join(DIRNAME, "data", 'enum_variable.nc')
ENUMVAR_H5_FILE = os.path.join(DIRNAME, "data", 'enum_variable.hdf5')
MAKE_ENUM_VARIABLE_SCRIPT = os.path.join(DIRNAME, 'make_enum_file.py')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_file_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
LATEST_HDF5_FILE = os.path.join(DIRNAME, 'latest.hdf5')
LATEST_HDF5_FILE = os.path.join(DIRNAME, 'data', 'latest.hdf5')

# Polygot string type for representing unicode
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fillvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

DIRNAME = os.path.dirname(__file__)
DATASET_FILLVALUE_EARLIEST_HDF5_FILE = os.path.join(
DIRNAME, 'fillvalue_earliest.hdf5')
DIRNAME, 'data', 'fillvalue_earliest.hdf5')
DATASET_FILLVALUE_LATEST_HDF5_FILE = os.path.join(
DIRNAME, 'fillvalue_latest.hdf5')
DIRNAME, 'data', 'fillvalue_latest.hdf5')


def test_dataset_fillvalue_earliest():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filter_pipeline_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
FILTER_PIPELINE_V2_FILE = os.path.join(DIRNAME, 'filter_pipeline_v2.hdf5')
FILTER_PIPELINE_V2_FILE = os.path.join(DIRNAME, 'data', 'filter_pipeline_v2.hdf5')


def test_filter_pipeline_descr_v2():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fletcher32.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyfive.btree import BTreeV1RawDataChunks

DIRNAME = os.path.dirname(__file__)
DATASET_FLETCHER_HDF5_FILE = os.path.join(DIRNAME, 'fletcher32.hdf5')
DATASET_FLETCHER_HDF5_FILE = os.path.join(DIRNAME, 'data', 'fletcher32.hdf5')


def test_fletcher32_datasets():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
GROUPS_HDF5_FILE = os.path.join(DIRNAME, 'groups.hdf5')
GROUPS_HDF5_FILE = os.path.join(DIRNAME, 'data', 'groups.hdf5')


def test_groups():
Expand Down
5 changes: 4 additions & 1 deletion tests/test_h5d.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os

import h5py
import pyfive
from pathlib import Path
import pytest
from operator import mul


mypath = Path(__file__).parent
filename = 'compressed.hdf5'
filename = os.path.join(mypath, "data", 'compressed.hdf5')
variable_name = 'dataset3'
breaking_address=(2,0)

Expand Down
7 changes: 5 additions & 2 deletions tests/test_h5netcdf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# tests the variables found in the file h5netcdf_test.hdf5,
# which is produced by the write_h5netcdf test routine in the h5netcdf package
#
import os

import pyfive
import h5py
import warnings
Expand All @@ -9,8 +11,9 @@
DIRNAME = Path(__file__).parent

def test_file_contents():
p5file = pyfive.File(DIRNAME/'h5netcdf_test.hdf5')
h5file = h5py.File(DIRNAME/'h5netcdf_test.hdf5')
fpath = os.path.join(DIRNAME, 'data', 'h5netcdf_test.hdf5')
p5file = pyfive.File(fpath)
h5file = h5py.File(fpath)

expected_variables = [
"foo",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
EARLIEST_HDF5_FILE = os.path.join(DIRNAME, 'earliest.hdf5')
EARLIEST_HDF5_FILE = os.path.join(DIRNAME, 'data', 'earliest.hdf5')

# Polyglot string type for representing unicode
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
LATEST_HDF5_FILE = os.path.join(DIRNAME, 'latest.hdf5')
LATEST_HDF5_FILE = os.path.join(DIRNAME, 'data', 'latest.hdf5')

# Polygot string type for representing unicode
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_netcd4_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
NETCDF4_CLASSIC_FILE = os.path.join(DIRNAME, 'netcdf4_classic.nc')
NETCDF4_CLASSIC_FILE = os.path.join(DIRNAME, "data", 'netcdf4_classic.nc')


def test_read_netcdf4_classic():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_new_style_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pyfive

DIRNAME = os.path.dirname(__file__)
NEW_STYLE_GROUPS_HDF5_FILE = os.path.join(DIRNAME, "new_style_groups.hdf5")
NEW_STYLE_GROUPS_HDF5_FILE = os.path.join(DIRNAME, "data", "new_style_groups.hdf5")


def test_groups():
Expand Down
10 changes: 4 additions & 6 deletions tests/test_opaque.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ def test_opaque_dataset2_fixed(really_opaque):
assert pyfive.check_enum_dtype(dset.dtype) is None




@pytest.fixture(scope='module')
def really_opaque():
def really_opaque(modular_tmp_path):
""" Create an HDF5 file with a fixed size opaque dataset. """
name = os.path.join(os.path.dirname(__file__), "opaque_fixed.hdf5")
name = modular_tmp_path / "opaque_fixed.hdf5"

with h5py.File(name, "w") as f:
# Define a fixed-size opaque dtype as NumPy void
Expand Down Expand Up @@ -127,9 +125,9 @@ def data():


@pytest.fixture(scope='module')
def name(data):
def name(data, modular_tmp_path):
"""Create an HDF5 file with datetime64 data stored as opaque."""
name = os.path.join(os.path.dirname(__file__), "opaque_datetime.hdf5")
name = modular_tmp_path / "opaque_datetime.hdf5"

(ordinary_data, string_data, opdata) = data

Expand Down
Loading
Loading