From 92635615c8d766e69e23082a2c52c673307ae2a5 Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Sat, 18 Feb 2023 10:22:14 -0500 Subject: [PATCH 1/2] Fix broad exception statement single-line bug --- src/PyHyperScattering/SST1RSoXSDB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PyHyperScattering/SST1RSoXSDB.py b/src/PyHyperScattering/SST1RSoXSDB.py index 26af581b..34989b38 100644 --- a/src/PyHyperScattering/SST1RSoXSDB.py +++ b/src/PyHyperScattering/SST1RSoXSDB.py @@ -20,7 +20,7 @@ import tiled import dask from databroker.queries import RawMongo, Key, FullText, Contains, Regex -except: +except Exception: print( "Imports failed. Are you running on a machine with proper libraries for databroker, tiled, etc.?" ) From 7c8559b1c1186b6fb0d7bd99f4432dbef018c3c2 Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Sat, 18 Feb 2023 10:22:34 -0500 Subject: [PATCH 2/2] Initial set of tests for DB loader. --- tests/test_SST1DBLoader.py | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test_SST1DBLoader.py diff --git a/tests/test_SST1DBLoader.py b/tests/test_SST1DBLoader.py new file mode 100644 index 00000000..9345c385 --- /dev/null +++ b/tests/test_SST1DBLoader.py @@ -0,0 +1,57 @@ +import sys +sys.path.append("src/") + +try: + import tiled + import tiled.client + try: + client = tiled.client.from_profile('rsoxs') + from PyHyperScattering.load import SST1RSoXSDB + SKIP_DB_TESTING=False + except tiled.profiles.ProfileNotFound: + SKIP_DB_TESTING=True +except ImportError: + SKIP_DB_TESTING=True + + + + +import numpy as np +import pandas as pd +import xarray as xr +import pytest + +must_have_tiled = pytest.mark.skipif(SKIP_DB_TESTING,reason='Connection to Tiled server not possible in this environment.') + + +@pytest.fixture(autouse=True,scope='module') +def sstdb(): + sstdb = SST1RSoXSDB(corr_mode='none') + return sstdb + +@must_have_tiled +def test_SST1DB_load_single_scan_legacy_hinted_dims(sstdb): + run = sstdb.loadRun(21792).unstack('system') + assert 'energy' in run.indexes + +@must_have_tiled +def test_SST1DB_load_single_scan_legacy_explicit_dims(sstdb): + run = sstdb.loadRun(21792,dims=['energy','polarization']).unstack('system') + assert type(run) == xr.DataArray + assert 'energy' in run.indexes + assert 'polarization' in run.indexes + +@must_have_tiled +def test_SST1DB_load_snake_scan_hinted_dims(sstdb): + run = sstdb.loadRun(48812,dims=['sam_th','polarization']).unstack('system') + assert type(run) == xr.DataArray + assert 'sam_th' in run.indexes + assert 'polarization' in run.indexes + + +@must_have_tiled +def test_SST1DB_load_snake_scan_explicit_dims(sstdb): + run = sstdb.loadRun(48812).unstack('system') + assert type(run) == xr.DataArray + assert 'sam_th' in run.indexes + assert 'polarization' in run.indexes