Skip to content

Commit

Permalink
Fixed deprecated methods in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaruland committed Jul 29, 2024
1 parent c99adfd commit 14536e2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
28 changes: 16 additions & 12 deletions aimm_adapters/heald_labview.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import xraydb
from tiled.adapters.dataframe import DataFrameAdapter
from tiled.adapters.mapping import MapAdapter
from tiled.server.object_cache import with_object_cache

# from tiled.server.object_cache import with_object_cache

_EDGE_ENERGY_DICT = {
xraydb.atomic_symbol(i): [i, xraydb.xray_edges(i)] for i in range(1, 99)
Expand Down Expand Up @@ -309,8 +310,9 @@ def iter_subdirectory(mapping, path, normalize=False):
filepaths[i].name
] = norm_node.read()
else:
cache_key = (Path(__file__).stem, filepaths[i])
end_node = with_object_cache(cache_key, build_reader, filepaths[i])
# cache_key = (Path(__file__).stem, filepaths[i])
# end_node = with_object_cache(cache_key, build_reader, filepaths[i])
end_node = build_reader(filepaths[i])
if end_node is not None:
experiment_group[filepaths[i].stem][filepaths[i].name] = end_node

Expand Down Expand Up @@ -358,8 +360,9 @@ def complete_tree_iter_subdirectory(mapping, path):
experiment_group[filepaths[i].stem]
)

cache_key = (Path(__file__).stem, filepaths[i])
end_node = with_object_cache(cache_key, complete_build_reader, filepaths[i])
# cache_key = (Path(__file__).stem, filepaths[i])
# end_node = with_object_cache(cache_key, complete_build_reader, filepaths[i])
end_node = complete_build_reader(filepaths[i])
if end_node is not None:
experiment_group[filepaths[i].stem][filepaths[i].name] = end_node

Expand Down Expand Up @@ -568,16 +571,17 @@ def from_directory(cls, directory):

class NormalizedReader:
def __init__(self, filepath):
cache_key = (
Path(__file__).stem,
filepath,
) # exact same key you used for build_reader
# cache_key = (
# Path(__file__).stem,
# filepath,
# ) # exact same key you used for build_reader
# Make an UNnoramlized reader first.
# Use the cache so that this unnormalized reader can be shared across
# a normalized tree and an unnormalized tree.
self._unnormalized_reader = with_object_cache(
cache_key, build_reader, filepath, no_device=True
)
# self._unnormalized_reader = with_object_cache(
# cache_key, build_reader, filepath, no_device=True
# )
self._unnormalized_reader = build_reader(filepath, no_device=True)
self._current_filepath = filepath

def read(self):
Expand Down
24 changes: 18 additions & 6 deletions aimm_adapters/tests/test_heald.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

import pytest
from tiled.adapters.mapping import MapAdapter
from tiled.client import from_tree
from tiled.client import Context, from_context
from tiled.server.app import build_app

from ..heald_labview import HealdLabViewTree


@pytest.fixture(scope="module")
def context():
here = Path(__file__).parent
files = here / ".." / "files"
tree = MapAdapter(
{
"A": HealdLabViewTree.from_directory(files),
}
)
app = build_app(tree)
with Context.from_app(app) as context:
yield context


@pytest.mark.parametrize(
"filename, expected_size",
[("test_data.01", (2, 4))],
)
def test_heald_labview(filename, expected_size):
here = Path(__file__).parent # directory containing this module
files = here / ".." / "files"
tree = MapAdapter({"A": HealdLabViewTree.from_directory(files)})
client = from_tree(tree)
def test_heald_labview(filename, expected_size, context):
client = from_context(context)
arr = client["A"][filename].read()
assert arr.shape == expected_size

0 comments on commit 14536e2

Please sign in to comment.