|
1 | 1 | import numpy as np
|
| 2 | +import pandas as pd |
2 | 3 | import pytest
|
3 | 4 | from napari_deeplabcut import _reader
|
4 | 5 | from skimage.io import imsave
|
@@ -60,6 +61,39 @@ def test_read_config(config_path):
|
60 | 61 | assert config_path.startswith(dict_["metadata"]["project"])
|
61 | 62 |
|
62 | 63 |
|
| 64 | +def test_read_hdf_old_index(tmp_path_factory, fake_keypoints): |
| 65 | + path = str(tmp_path_factory.mktemp("folder") / "data.h5") |
| 66 | + old_index = [ |
| 67 | + f"labeled-data/video/img{i}.png" |
| 68 | + for i in range(fake_keypoints.shape[0]) |
| 69 | + ] |
| 70 | + fake_keypoints.index = old_index |
| 71 | + fake_keypoints.to_hdf(path, key="data") |
| 72 | + layers = _reader.read_hdf(path) |
| 73 | + assert len(layers) == 1 |
| 74 | + image_paths = layers[0][1]["metadata"]["paths"] |
| 75 | + assert len(image_paths) == len(fake_keypoints) |
| 76 | + assert isinstance(image_paths[0], str) |
| 77 | + assert "labeled-data" in image_paths[0] |
| 78 | + |
| 79 | + |
| 80 | +def test_read_hdf_new_index(tmp_path_factory, fake_keypoints): |
| 81 | + path = str(tmp_path_factory.mktemp("folder") / "data.h5") |
| 82 | + new_index = pd.MultiIndex.from_product([ |
| 83 | + ["labeled-data"], |
| 84 | + ["video"], |
| 85 | + [f"img{i}.png" for i in range(fake_keypoints.shape[0])] |
| 86 | + ]) |
| 87 | + fake_keypoints.index = new_index |
| 88 | + fake_keypoints.to_hdf(path, key="data") |
| 89 | + layers = _reader.read_hdf(path) |
| 90 | + assert len(layers) == 1 |
| 91 | + image_paths = layers[0][1]["metadata"]["paths"] |
| 92 | + assert len(image_paths) == len(fake_keypoints) |
| 93 | + assert isinstance(image_paths[0], str) |
| 94 | + assert "labeled-data" in image_paths[0] |
| 95 | + |
| 96 | + |
63 | 97 | def test_video(video_path):
|
64 | 98 | video = _reader.Video(video_path)
|
65 | 99 | video.close()
|
|
0 commit comments