Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
searscr committed Oct 2, 2023
1 parent f34bb74 commit 7f28602
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 35 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,9 @@ jobs:
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
- name: Test with pytest
run: |
# sed -i '/^sdatasearch.directories=/s/.*/datasearch.directories=\/home\/cloud\/_work\/LiquidsReflectometer\/LiquidsReflectometer\/tests\/data\/liquidsreflectometer-data\/nexus/' ~/.mantid/Mantid.user.properties
echo datasearch.directories=/home/cloud/_work/LiquidsReflectometer/LiquidsReflectometer/tests/data/liquidsreflectometer-data/nexus/ >> ~/.mantid/Mantid.user.properties
cat ~/.mantid/Mantid.user.properties
# sudo apt-get update
# sudo apt-get install git-lfs
dpkg -l git-lfs
python -m pip install -e . # install the application in editable mode
git submodule add --force https://code.ornl.gov/sns-hfir-scse/infrastructure/test-data/liquidsreflectometer-data.git tests/data/liquidsreflectometer-data
# git -C tests/data/liquidsreflectometer-data/ lfs install
# git -C tests/data/liquidsreflectometer-data/ pull
git submodule update --init
ls -al tests/data/liquidsreflectometer-data/nexus/
xvfb-run --server-args="-screen 0 1280x1024x16" --auto-servernum python -m pytest --cov=reduction --cov=scripts --cov-report=xml --cov-report=term
python -m pytest --cov=reduction --cov=scripts --cov-report=xml --cov-report=term -m datarepo
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
20 changes: 5 additions & 15 deletions tests/reduction/test_reduction.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import unittest
import os
import pytest
import sys
print(sys.path)

import mantid.simpleapi as mtd_api
import numpy as np
from mantid.kernel import ConfigService
from mantid.api import FileFinder
mantid.kernel.config.setLogLevel(3)

from reduction.lr_reduction import event_reduction, template, workflow

Expand All @@ -23,8 +21,6 @@ def setUp(self):
config.appendDataSearchDir(str(os.path.join(cwd, "data/liquidsreflectometer-data/nexus")))
print(config.getDataSearchDirs())


@classmethod
def test_full_reduction(self):
"""
Test the fill reduction chain
Expand All @@ -34,21 +30,15 @@ def test_full_reduction(self):
refl_all = []
d_refl_all = []
first_run = None
# file_prefix = "data/liquidsreflectometer-data/nexus/REF_L_{}.nxs.h5"
# print(oct(os.stat(filename).st_mode)[-3:])
# print(os.getcwd())
os.getcwd()

for run_number in range(198409, 198417):
file_loc = f"data/liquidsreflectometer-data/nexus/REF_L_{run_number}.nxs.h5"
file_name = FileFinder.findRuns("REF_L_%d" % int(run_number))[0]
print(f'foundfile: {file_name}')
ws_sc = mtd_api.Load(Filename=file_loc)
ws_sc = mtd_api.Load("REF_L_%s" % run_number)
qz_mid, refl, d_refl = template.process_from_template_ws(ws_sc, template_path)

if first_run is None:
first_run = run_number
resolution = event_reduction.compute_resolution(ws_sc)
print(resolution)

for i in range(len(qz_mid)):
qz_all.append(qz_mid[i])
refl_all.append(refl[i])
Expand All @@ -63,7 +53,7 @@ def test_full_reduction(self):
refl_all = np.take_along_axis(refl_all, idx, axis=None)
d_refl_all = np.take_along_axis(d_refl_all, idx, axis=None)

# assert(resolution == 0.02785205863936946)
assert(resolution == 0.02785205863936946)
ref_data = np.loadtxt("data/reference_rq.txt").T
assert len(ref_data[1]) == len(refl_all)
assert np.fabs(np.sum(ref_data[1] - refl_all)) < 1e-10
Expand Down
4 changes: 1 addition & 3 deletions tests/reduction/test_time_resolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@pytest.mark.datarepo()
class TimeResolvedTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
if os.getcwd().endswith("LiquidsReflectometer"):
os.chdir("tests")
Expand All @@ -17,14 +16,13 @@ def setUpClass(cls):
config.appendDataSearchDir(str(os.path.join(cwd, "data/liquidsreflectometer-data/nexus")))
print(config.getDataSearchDirs())

@classmethod
def test_reduce_workflow(self):
"""
Test the time-resolved reduction that uses a measured reference.
It is generally used at 30 Hz but it also works at 60 Hz.
"""
template_path = "data/template.xml"
output_dir = "/tmp"
output_dir = "results"
reduced_path = "data/reference_rq_avg_overlap.txt"
ref_data = np.loadtxt(reduced_path).T

Expand Down
4 changes: 1 addition & 3 deletions tests/scripts/test_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from scripts.autoreduce.peak_finding import find_peaks, peak_prominences, peak_widths


@pytest.mark.scripts()
@pytest.mark.datarepo()
class ScanPeaksTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
if os.getcwd().endswith("LiquidsReflectometer"):
os.chdir("tests")
Expand All @@ -22,7 +21,6 @@ def setUpClass(cls):
config.appendDataSearchDir(str(os.path.join(cwd, "data/liquidsreflectometer-data/nexus")))
print(config.getDataSearchDirs())

@classmethod
def test_peak_finding(self):
def scan_peaks(x):
f1 = ndimage.gaussian_filter(x, 3)
Expand Down
4 changes: 1 addition & 3 deletions tests/scripts/test_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@pytest.mark.scripts()
class TestScalingFactor(unittest.TestCase):
@classmethod
def setUpClass(cls):
if os.getcwd().endswith("LiquidsReflectometer"):
os.chdir("tests")
Expand All @@ -17,8 +16,7 @@ def setUpClass(cls):
config.appendDataSearchDir(str(os.path.join(cwd, "data/liquidsreflectometer-data/nexus")))
print(config.getDataSearchDirs())

@classmethod
def test_scaling_factor(self):
sf = ScalingFactor(run_list=range(184975, 184990), sf_file="/tmp/sf_184975_air.cfg", medium="air")
sf = ScalingFactor(run_list=range(184975, 184990), sf_file="results/sf_184975_air.cfg", medium="air")

sf.execute()

0 comments on commit 7f28602

Please sign in to comment.