Skip to content

Commit 3bc4bc5

Browse files
committed
minor cleanup
1 parent 29bb5e2 commit 3bc4bc5

7 files changed

Lines changed: 12 additions & 27 deletions

File tree

banzai/cache/replication.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from sqlalchemy import text, create_engine
2-
from banzai import dbs
32
from banzai.logs import get_logger
43

54
# PostgreSQL logical replication is managed via server-level DDL commands

banzai/dbs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sqlalchemy import create_engine, pool, func, make_url
1515
from sqlalchemy.exc import IntegrityError
1616
from sqlalchemy.orm import sessionmaker
17-
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean, CHAR, JSON, UniqueConstraint, Float, Text
17+
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean, CHAR, JSON, UniqueConstraint, Float
1818
from sqlalchemy.ext.declarative import declarative_base
1919
from sqlalchemy.sql.expression import true
2020
from contextlib import contextmanager
@@ -117,7 +117,6 @@ class ProcessedImage(Base):
117117
tries = Column(Integer, default=0)
118118

119119

120-
121120
class StackFrame(Base):
122121
__tablename__ = 'stack_frames'
123122
id = Column(Integer, primary_key=True, autoincrement=True)

banzai/scheduling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import traceback
32
from datetime import datetime, timedelta, timezone
43
from dateutil.parser import parse
54

@@ -303,4 +302,4 @@ def process_subframe(self, body: dict, runtime_context: dict):
303302
except Retry:
304303
raise
305304
except Exception:
306-
logger.error(f'Error processing subframe: {traceback.format_exc()}')
305+
logger.error("Error processing subframe: {error}".format(error=logs.format_exception()))

banzai/tests/site_e2e/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import subprocess
77
import time
88
from pathlib import Path
9+
from sqlalchemy import create_engine, text as sa_text
10+
from kombu import Connection, Queue
911

1012
import pytest
1113

@@ -67,7 +69,6 @@ def poll_until(predicate, timeout, interval=5):
6769

6870
def publish_to_queue(queue_name, body, broker_url='amqp://localhost:5672'):
6971
"""Publish a JSON message to a RabbitMQ queue."""
70-
from kombu import Connection, Queue
7172
with Connection(broker_url) as conn:
7273
queue = Queue(queue_name, channel=conn.channel())
7374
queue.declare()
@@ -142,7 +143,6 @@ def check():
142143

143144
def wait_for_subscription_active(timeout=60):
144145
"""Wait for the replication subscription to be enabled with an active worker."""
145-
from sqlalchemy import create_engine, text as sa_text
146146

147147
engine = create_engine(LOCAL_DB_ADDRESS)
148148

banzai/tests/site_e2e/test_site_e2e.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def test_07_reduction_completes(self, site_deployment):
212212
@pytest.mark.e2e_site_reduction
213213
def test_08_reduction_used_cached_calibrations(self, site_deployment):
214214
"""Verify reduced frames used calibrations that exist in the local cache and DB."""
215-
from astropy.io import fits
216215

217216
output_dir = DATA_DIR / 'output'
218217
reduced_files = list(output_dir.rglob('*-e91.fits.fz'))
@@ -291,7 +290,6 @@ def test_11_cache_updated(self):
291290
@pytest.mark.e2e_site_reduction
292291
def test_12_subframe_stack_completes(self, site_deployment):
293292
"""Verify subframe stacking processes a frame end-to-end."""
294-
from astropy.io import fits
295293

296294
raw_dir = DATA_DIR / 'raw'
297295
src_path = raw_dir / RAW_FRAME_FILENAME

banzai/tests/test_download_worker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _attrs_for_type(cal_type, **overrides):
128128
return attrs
129129

130130

131-
def test_returns_top_2_per_config(db_address, tmp_path):
131+
def test_returns_top_2_per_config(db_address):
132132
inst_id = _seed_db(db_address)
133133
bias_attrs = _attrs_for_type('BIAS', configuration_mode='default', binning='1x1')
134134
with dbs.get_session(db_address) as session:
@@ -140,7 +140,7 @@ def test_returns_top_2_per_config(db_address, tmp_path):
140140
assert filenames == {'mid.fits', 'new.fits'}
141141

142142

143-
def test_partitions_independently_by_config(db_address, tmp_path):
143+
def test_partitions_independently_by_config(db_address):
144144
inst_id = _seed_db(db_address)
145145
with dbs.get_session(db_address) as session:
146146
for i, binning in enumerate(['1x1', '2x2']):
@@ -154,7 +154,7 @@ def test_partitions_independently_by_config(db_address, tmp_path):
154154
'bias_2x2_1.fits', 'bias_2x2_2.fits'}
155155

156156

157-
def test_filters_by_instrument_type(db_address, tmp_path):
157+
def test_filters_by_instrument_type(db_address):
158158
sinistro_id = _seed_db(db_address, camera='fa01', inst_type='1m0-SciCam-Sinistro')
159159
floyds_id = _seed_db(db_address, camera='en01', inst_type='2m0-FLOYDS-SciCam')
160160
bias_attrs = _attrs_for_type('BIAS', configuration_mode='default', binning='1x1')
@@ -167,7 +167,7 @@ def test_filters_by_instrument_type(db_address, tmp_path):
167167
assert filenames == {'sinistro.fits'}
168168

169169

170-
def test_wildcard_returns_all_instrument_types(db_address, tmp_path):
170+
def test_wildcard_returns_all_instrument_types(db_address):
171171
sinistro_id = _seed_db(db_address, camera='fa01', inst_type='1m0-SciCam-Sinistro')
172172
floyds_id = _seed_db(db_address, camera='en01', inst_type='2m0-FLOYDS-SciCam')
173173
bias_attrs = _attrs_for_type('BIAS', configuration_mode='default', binning='1x1')
@@ -179,7 +179,7 @@ def test_wildcard_returns_all_instrument_types(db_address, tmp_path):
179179
assert filenames == {'sinistro.fits', 'floyds.fits'}
180180

181181

182-
def test_biases_ignore_filter(db_address, tmp_path):
182+
def test_biases_ignore_filter(db_address):
183183
"""Biases taken with different filters should be grouped together."""
184184
inst_id = _seed_db(db_address)
185185
bias_attrs = _attrs_for_type('BIAS', configuration_mode='default', binning='1x1')
@@ -192,7 +192,7 @@ def test_biases_ignore_filter(db_address, tmp_path):
192192
assert filenames == {'bias_B.fits', 'bias_R.fits'}
193193

194194

195-
def test_darks_partitioned_by_temperature(db_address, tmp_path):
195+
def test_darks_partitioned_by_temperature(db_address):
196196
inst_id = _seed_db(db_address)
197197
with dbs.get_session(db_address) as session:
198198
for i, temp in enumerate(['5', '10']):
@@ -207,7 +207,7 @@ def test_darks_partitioned_by_temperature(db_address, tmp_path):
207207
'dark_t10_1.fits', 'dark_t10_2.fits'}
208208

209209

210-
def test_skyflats_partitioned_by_filter(db_address, tmp_path):
210+
def test_skyflats_partitioned_by_filter(db_address):
211211
inst_id = _seed_db(db_address)
212212
with dbs.get_session(db_address) as session:
213213
for i, filt in enumerate(['V', 'B']):

banzai/tests/test_smart_stacking.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
push_notification, drain_notifications, REDIS_KEY_PREFIX,
1414
process_notifications, finalize_stack, check_timeout,
1515
discover_cameras, StackingSupervisor)
16+
from banzai.scheduling import process_subframe
1617
from banzai.main import SubframeListener
1718

1819
pytestmark = pytest.mark.smart_stacking
@@ -48,7 +49,6 @@ def mock_redis():
4849
# Database operations
4950
# ---------------------------------------------------------------------------
5051

51-
@pytest.mark.smart_stacking
5252
class TestDBOperations:
5353

5454
def test_insert_and_query(self, db_address):
@@ -100,7 +100,6 @@ def test_update_stack_frame_filepath(self, db_address):
100100
# Status transitions
101101
# ---------------------------------------------------------------------------
102102

103-
@pytest.mark.smart_stacking
104103
class TestStatusTransitions:
105104

106105
def test_status_active_to_complete(self, db_address):
@@ -134,7 +133,6 @@ def test_status_active_to_timeout(self, db_address):
134133
# Timeout
135134
# ---------------------------------------------------------------------------
136135

137-
@pytest.mark.smart_stacking
138136
class TestTimeout:
139137

140138
def test_timeout_finalizes_stale_stacks(self, db_address):
@@ -154,7 +152,6 @@ def test_timeout_finalizes_stale_stacks(self, db_address):
154152
# Redis notifications
155153
# ---------------------------------------------------------------------------
156154

157-
@pytest.mark.smart_stacking
158155
class TestRedisNotifications:
159156

160157
def test_push_notification(self, mock_redis):
@@ -175,7 +172,6 @@ def test_drain_for_camera(self, mock_redis):
175172
# Multiple concurrent stacks
176173
# ---------------------------------------------------------------------------
177174

178-
@pytest.mark.smart_stacking
179175
class TestConcurrentStacks:
180176

181177
def test_concurrent_stacks_same_camera(self, db_address):
@@ -203,7 +199,6 @@ def test_concurrent_stacks_same_camera(self, db_address):
203199
# check_stack_complete
204200
# ---------------------------------------------------------------------------
205201

206-
@pytest.mark.smart_stacking
207202
class TestCheckStackComplete:
208203

209204
@staticmethod
@@ -237,7 +232,6 @@ def test_empty_frames(self):
237232
# Retention / cleanup
238233
# ---------------------------------------------------------------------------
239234

240-
@pytest.mark.smart_stacking
241235
class TestRetention:
242236

243237
def test_cleanup_old_records(self, db_address):
@@ -276,7 +270,6 @@ def test_cleanup_preserves_recent(self, db_address):
276270
# SubframeListener on_message
277271
# ---------------------------------------------------------------------------
278272

279-
@pytest.mark.smart_stacking
280273
class TestSubframeListenerOnMessage:
281274
"""on_message dispatches to Celery; no FITS I/O or DB work here."""
282275

@@ -320,7 +313,6 @@ def test_on_message_invalid_no_dispatch(self, mock_task):
320313
# process_subframe Celery task
321314
# ---------------------------------------------------------------------------
322315

323-
@pytest.mark.smart_stacking
324316
class TestProcessSubframe:
325317
"""Test the Celery task that does the actual subframe processing."""
326318

@@ -352,7 +344,6 @@ def _make_mock_image(output_dir='/data/processed', output_filename='frame-e09.fi
352344
])
353345
@patch('banzai.scheduling.stage_utils.run_pipeline_stages')
354346
def test_process_subframe(self, mock_run_stages, last_frame_val, expected_is_last, db_address, mock_redis):
355-
from banzai.scheduling import process_subframe
356347

357348
mock_image = self._make_mock_image()
358349
mock_run_stages.return_value = [mock_image]
@@ -385,7 +376,6 @@ def test_process_subframe(self, mock_run_stages, last_frame_val, expected_is_las
385376
# Supervisor
386377
# ---------------------------------------------------------------------------
387378

388-
@pytest.mark.smart_stacking
389379
class TestSupervisor:
390380

391381
def test_discover_cameras(self, db_address):

0 commit comments

Comments
 (0)