From edd8f373115a9f543cecfa33871e54c3bdf81081 Mon Sep 17 00:00:00 2001 From: Brian Koopman Date: Thu, 17 Oct 2024 12:58:46 -0400 Subject: [PATCH] Skip scan if has already passed --- src/sorunlib/seq.py | 4 ++++ tests/test_seq.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/sorunlib/seq.py b/src/sorunlib/seq.py index 6fe880c..7d3b4d0 100644 --- a/src/sorunlib/seq.py +++ b/src/sorunlib/seq.py @@ -32,6 +32,10 @@ def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None, now = dt.datetime.now(dt.timezone.utc) scan_stop = _timestamp_to_utc_datetime(stop_time) + # Check stop time has not already passed + if now > scan_stop: + return + # Check there is enough time to perform scan if min_duration is not None: start_by_time = scan_stop - dt.timedelta(seconds=min_duration) diff --git a/tests/test_seq.py b/tests/test_seq.py index 74dbaab..0a09015 100644 --- a/tests/test_seq.py +++ b/tests/test_seq.py @@ -24,6 +24,14 @@ def test_scan(patch_clients): seq.scan(description='test', stop_time=target.isoformat(), width=20.) +@patch('sorunlib._internal.time.sleep', MagicMock()) +def test_scan_passed_stop_time(patch_clients): + # This affects test runtime duration keep it short + target = dt.datetime.now(dt.timezone.utc) - dt.timedelta(seconds=10) + seq.scan(description='test', stop_time=target.isoformat(), width=20.) + seq.run.CLIENTS['acu'].generate_scan.start.assert_not_called() + + @patch('sorunlib._internal.time.sleep', MagicMock()) def test_scan_passed_min_duration(patch_clients): # This affects test runtime duration keep it short