Skip to content

Commit df9da44

Browse files
committed
Add writer-level tests for second-wavelength export
1 parent e4ed34d commit df9da44

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

‎tests/unit/easydiffraction/io/cif/test_iucr_writer.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,58 @@ def test_write_iucr_cif_emits_powder_cwl_blocks(tmp_path):
352352
assert '_pd_meas.info_author_' not in text
353353

354354

355+
def test_write_iucr_cif_disabled_second_wavelength_stays_scalar(tmp_path):
356+
from easydiffraction.io.cif.iucr_writer import write_iucr_cif
357+
358+
# Second wavelength recorded but disabled (ratio == 0): the report
359+
# keeps the single-row scalar wavelength and omits the disabled λ₂.
360+
experiment = _powder_experiment('disabled')
361+
experiment.instrument.setup_wavelength_2 = _descriptor(1.5444)
362+
experiment.instrument.setup_wavelength_2_to_1_ratio = _descriptor(0.0)
363+
364+
project = _project(
365+
'disabled',
366+
tmp_path,
367+
_collection(_structure()),
368+
_collection(experiment),
369+
)
370+
371+
text = write_iucr_cif(project).read_text(encoding='utf-8')
372+
373+
assert '_diffrn_radiation_wavelength.value' in text
374+
assert '_diffrn_radiation_wavelength.wt' in text
375+
assert '1.5444' not in text
376+
377+
378+
def test_write_iucr_cif_active_doublet_emits_wavelength_loop(tmp_path):
379+
from easydiffraction.io.cif.iucr_writer import write_iucr_cif
380+
381+
# Active doublet: the report emits the two-row
382+
# _diffrn_radiation_wavelength loop with both wavelengths.
383+
experiment = _powder_experiment('doublet')
384+
experiment.instrument.setup_wavelength_2 = _descriptor(1.5444)
385+
experiment.instrument.setup_wavelength_2_to_1_ratio = _descriptor(0.5)
386+
387+
project = _project(
388+
'doublet',
389+
tmp_path,
390+
_collection(_structure()),
391+
_collection(experiment),
392+
)
393+
394+
text = write_iucr_cif(project).read_text(encoding='utf-8')
395+
396+
assert (
397+
'loop_\n'
398+
'_diffrn_radiation_wavelength.id\n'
399+
'_diffrn_radiation_wavelength.value\n'
400+
'_diffrn_radiation_wavelength.wt\n'
401+
) in text
402+
# Both components present: id 1 at λ1 and id 2 at λ2.
403+
assert '1.5406' in text
404+
assert '1.5444' in text
405+
406+
355407
def test_write_iucr_cif_emits_joint_tof_pattern_blocks(tmp_path):
356408
from easydiffraction.io.cif.iucr_writer import write_iucr_cif
357409

0 commit comments

Comments
 (0)