From 1680f5a14b0fa81562eef60a1b822a90e2cc8325 Mon Sep 17 00:00:00 2001 From: Alexander Steppke Date: Tue, 17 Jan 2023 13:05:54 +0100 Subject: [PATCH] fixed test suite --- pytest.ini | 3 +++ src/cristallina/analysis.py | 10 +++++++++- src/cristallina/utils.py | 7 ++----- tests/test_utils.py | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..8691cae --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +filterwarnings = + ignore::UserWarning diff --git a/src/cristallina/analysis.py b/src/cristallina/analysis.py index 62ede27..c736ab3 100644 --- a/src/cristallina/analysis.py +++ b/src/cristallina/analysis.py @@ -13,6 +13,9 @@ from joblib import Parallel, delayed, Memory from . import utils from .utils import ROI +# Ideally we automatically determine the cache directory tied to the p-group +# If this fails we try with a fixed path for now, and finally use the +# current temporary directory. try: pgroup = utils.heuristic_extract_pgroup() location = f"/das/work/units/cristallina/p{pgroup}/cachedir" @@ -20,7 +23,12 @@ except KeyError as e: print(e) location = "/das/work/units/cristallina/p19739/cachedir" -memory = Memory(location, verbose=0, compress=2) +try: + memory = Memory(location, verbose=0, compress=2) +except PermissionError as e: + location = "/tmp" + memory = Memory(location, verbose=0, compress=2) + @memory.cache(ignore=["batch_size"]) # we ignore batch_size for caching purposes diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index b0e2ec8..018913c 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -8,7 +8,7 @@ from sfdata import SFDataFiles, sfdatafile, SFScanInfo, SFProcFile from xraydb import material_mu from joblib import Parallel, delayed, cpu_count -def scan_info(run_number,base_path=None,small_data=True): +def scan_info(run_number, base_path=None, small_data=True): """Returns SFScanInfo object for a given run number. If there is are small data channels, they will be added (small_data=False to suppress their loading). """ @@ -45,10 +45,7 @@ def print_run_info( Extra verbose output contains all files and pids. """ - # if base_path == None: - # base_path = heuristic_extract_base_path() - # scan = SFScanInfo(f"{base_path}/run{run_number:04}/meta/scan.json") - scan = scan_info(run_number,base_path=base_path) + scan = scan_info(run_number, base_path=base_path) short = {} for key, value in scan.info.items(): if isinstance(value, list): diff --git a/tests/test_utils.py b/tests/test_utils.py index cabf9c5..7551aa5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,7 +6,10 @@ from cristallina.utils import ROI, print_run_info, heuristic_extract_pgroup, gau __author__ = "Alexander Steppke" def test_print(capsys): + # this currently works only if the heuristic p-group extraction works + # TODO: fix this shortcoming and use base_path throughout + os.chdir("/sf/cristallina/data/p19739/") print_run_info(247) captured = capsys.readouterr() assert "15453208940" in captured.out