[writer] non-deterministic NXdata order
When asked to create an NXdata with channels of different detector shapes, the writer will split the channels in multiple NXdata's, grouped by detector shape. The names of these multiple NXdata groups is f"{name}{i}"
where i
is the index after sorting. But the sorting is not deterministic because it is based on the detector shape, which can be variable (e.g. the samples of a sampling diode).
In the writer tests, there is an expected order of split NXdata's. Because the order is not deterministic, some writer tests may fail as follows:
_________________________________________________________________ test_nxw_mtopmaster_base_nopolicy __________________________________________________________________
nexus_writer_base_nopolicy = {'alt': False, 'config': False, 'policy': False, 'session': <bliss.common.session.Session object at 0x7f612a329f10>, ...}
def test_nxw_mtopmaster_base_nopolicy(nexus_writer_base_nopolicy):
> _test_nxw_mtopmaster(**nexus_writer_base_nopolicy)
tests/nexus_writer/test_nxw_mtopmaster.py:35:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/nexus_writer/helpers/nxw_test_utils.py:300: in inner
func(*args, **kwargs)
tests/nexus_writer/test_nxw_mtopmaster.py:40: in _test_nxw_mtopmaster
_test_aloopscan(**kwargs)
tests/nexus_writer/test_nxw_mtopmaster.py:98: in _test_aloopscan
**kwargs,
tests/nexus_writer/helpers/nxw_test_data.py:29: in assert_scan_data
validate_scan_data(scan, **kwargs)
tests/nexus_writer/helpers/nxw_test_data.py:145: in validate_scan_data
save_images=save_images,
tests/nexus_writer/helpers/nxw_test_data.py:472: in validate_plots
save_images=save_images,
tests/nexus_writer/helpers/nxw_test_data.py:566: in validate_nxdata
assert_set_equal(set(signals), set(expected_signals), msg=nxdata.name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
actual = {'spectrum_det0', 'spectrum_det1', 'spectrum_det2', 'spectrum_det3'}, expected = {'diode9alias_samples'}
msg = "/1.2/plot1D_unknown1D1\nnot expected: ['spectrum_det0', 'spectrum_det1', 'spectrum_det2', 'spectrum_det3']\nnot present: ['diode9alias_samples']"
def assert_set_equal(actual, expected, msg=""):
"""
Assert equal sets with message
:param set actual:
:param set expected:
:param str msg:
"""
diff = actual.difference(expected)
if diff:
msg += "\nnot expected: " + repr(sorted(diff))
diff = expected.difference(actual)
if diff:
msg += "\nnot present: " + repr(sorted(diff))
> assert actual == expected, msg
E AssertionError: /1.2/plot1D_unknown1D1
E not expected: ['spectrum_det0', 'spectrum_det1', 'spectrum_det2', 'spectrum_det3']
E not present: ['diode9alias_samples']
tests/nexus_writer/helpers/nxw_test_data.py:1201: AssertionError