test_post_request.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Tests for PostRequestGenerator — the single canonical POST-manifest builder.
  3. Regression guard for the "points < 1" bug: a divergent GUI copy of this logic
  4. put raw ADC-window durations (seconds, e.g. 0.002) into ``iadc.points`` instead
  5. of sample counts ``int(window_s * srate)``, so int(0.002) collapsed to 0.
  6. """
  7. from __future__ import annotations
  8. from seq_interp.src.core.synchronizer import Synchronizer
  9. from seq_interp.src.hardware.constraints import HardwareConstraints
  10. from seq_interp.src.interfaces.post_request_generator import PostRequestGenerator
  11. from seq_interp.src.interfaces.xml_generator import XMLGenerator
  12. def _adc_windows(make_seq, specs, tmp_path):
  13. hw = HardwareConstraints()
  14. sync_data = Synchronizer(hw).process(make_seq(specs))
  15. adc_vals, _ = XMLGenerator().generate(sync_data, str(tmp_path / "s.xml"), hw)
  16. return adc_vals
  17. def test_points_are_sample_counts_not_seconds(make_seq, tmp_path):
  18. """points must be int(window_s * srate), i.e. >= 1 for a real ADC window."""
  19. adc_vals = _adc_windows(make_seq, [{"adc": True, "dur": 2e-3}], tmp_path)
  20. srate = 8_000_000
  21. payload = PostRequestGenerator().build(
  22. seq_data={}, adc_values=adc_vals, sequence_path="seq.seq",
  23. output_dir=str(tmp_path), hw_cfg={"iadc": {"srate": srate}},
  24. rf_raster_time=1e-6,
  25. )
  26. points = payload["info"]["iadc"]["points"]
  27. assert points == [int(2e-3 * srate)] # 16000
  28. assert all(isinstance(p, int) and p >= 1 for p in points)
  29. def test_points_track_split_full_window(make_seq, tmp_path):
  30. """A split long ADC still yields one window -> one (large) sample count."""
  31. adc_vals = _adc_windows(make_seq, [{"adc": True, "dur": 50e-3}], tmp_path)
  32. srate = 8_000_000
  33. payload = PostRequestGenerator().build(
  34. seq_data={}, adc_values=adc_vals, sequence_path="seq.seq",
  35. output_dir=str(tmp_path), hw_cfg={"iadc": {"srate": srate}},
  36. rf_raster_time=1e-6,
  37. )
  38. points = payload["info"]["iadc"]["points"]
  39. assert points == [int(50e-3 * srate)] # 400000