forked from PtyLab/PtyLab.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_io.py
More file actions
53 lines (38 loc) · 1.71 KB
/
Copy pathtest_io.py
File metadata and controls
53 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Tests for I/O module.
Migrated from:
- PtyLabX/io/test/test_example_loader.py
- PtyLabX/io/test/test_get_example_data_folder.py
- PtyLabX/io/test/test_loadInputData.py
"""
import os
import pytest
from PtyLabX.io import getExampleDataFolder
SIMU_DATA = os.path.join(os.path.dirname(__file__), "..", "example_data", "simu.hdf5")
has_simu_data = os.path.exists(SIMU_DATA)
class TestExampleDataFolder:
def test_example_folder_exists(self):
"""Test that the path returned by getExampleDataFolder exists."""
example_data_folder = getExampleDataFolder()
assert example_data_folder.exists(), "example data folder does not exist"
class TestExampleLoader:
"""Tests for reading example datasets."""
def test_list_examples(self):
"""Check that listExamples runs without error."""
from PtyLabX.io import readExample
readExample.listExamples()
@pytest.mark.skipif(not has_simu_data, reason="Simulation data not available")
def test_load_simulation_cpm(self):
"""Check that simulation_cpm example can be loaded."""
from PtyLabX.io import readExample
archive = readExample.loadExample("example:simulation_cpm")
assert "Nd" in archive or "ptychogram" in archive
@pytest.mark.skipif(
not (getExampleDataFolder() / "fourier_simulation.hdf5").exists(),
reason="fourier_simulation.hdf5 not available",
)
def test_load_fourier_simulation(self):
"""Load Fourier simulation data and verify shape."""
from PtyLabX.io.readHdf5 import loadInputData
filename = getExampleDataFolder() / "fourier_simulation.hdf5"
result = loadInputData(filename)
assert result["ptychogram"].shape == (49, 256, 256)