-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up NMR utils and add tests for Bruker reader
- Loading branch information
Showing
2 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from pydatalab.apps.nmr.utils import read_bruker_1d | ||
|
||
|
||
def _extract_example(filename, dir): | ||
with zipfile.ZipFile(filename, "r") as zip_ref: | ||
zip_ref.extractall(dir) | ||
return Path(dir) / filename.stem | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def nmr_1d_solution_example(tmpdir): | ||
zip_path = Path(__file__).parent.parent.parent / "example_data" / "NMR" / "1.zip" | ||
return _extract_example(zip_path, tmpdir) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def nmr_1d_solid_example(tmpdir): | ||
zip_path = Path(__file__).parent.parent.parent / "example_data" / "NMR" / "71.zip" | ||
return _extract_example(zip_path, tmpdir) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def nmr_2d_matpass_example(tmpdir): | ||
zip_path = Path(__file__).parent.parent.parent / "example_data" / "NMR" / "72.zip" | ||
return _extract_example(zip_path, tmpdir) | ||
|
||
|
||
def test_bruker_reader_solution(nmr_1d_solution_example): | ||
df, a_dic, topspin_title, shape = read_bruker_1d(nmr_1d_solution_example) | ||
assert df is not None | ||
assert a_dic | ||
assert topspin_title | ||
assert shape == (4096,) | ||
|
||
|
||
def test_bruker_reader_solid(nmr_1d_solid_example): | ||
df, a_dic, topspin_title, shape = read_bruker_1d(nmr_1d_solid_example) | ||
assert df is not None | ||
assert a_dic | ||
assert topspin_title | ||
assert shape == (9984,) | ||
|
||
|
||
def test_bruker_reader_2D(nmr_2d_matpass_example): | ||
df, a_dic, topspin_title, shape = read_bruker_1d(nmr_2d_matpass_example) | ||
assert df is None | ||
assert a_dic | ||
assert topspin_title | ||
assert shape == (8, 4096) |