Skip to content

Commit

Permalink
Merge pull request #81 from usnistgov/70-build-tests-for-sst1rsoxsdb-…
Browse files Browse the repository at this point in the history
…loader

add CI tests for sst1rsoxsdb loader
  • Loading branch information
BijalBPatel authored Aug 3, 2023
2 parents 6018306 + a166137 commit 8e56991
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/PyHyperScattering/SST1RSoXSDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
from httpx import HTTPStatusError
import tiled
import dask
from databroker.queries import RawMongo, Key, FullText, Contains, Regex, ScanIDRange
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
except:
from databroker.queries import RawMongo, Key, FullText, Contains, Regex
except Exception:
print(
"Imports failed. Are you running on a machine with proper libraries for databroker, tiled, etc.?"
)
Expand Down
57 changes: 57 additions & 0 deletions tests/test_SST1DBLoader.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8e56991

Please sign in to comment.