Skip to content

Commit fd93781

Browse files
committed
fix: fix lint errors
1 parent c4304bc commit fd93781

File tree

2 files changed

+52
-56
lines changed

2 files changed

+52
-56
lines changed

test/unit/base/test_subscription_controller_u.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
from ibind.base.subscription_controller import (
55
SubscriptionController,
6-
SubscriptionProcessor,
7-
DEFAULT_SUBSCRIPTION_RETRIES,
8-
DEFAULT_SUBSCRIPTION_TIMEOUT
6+
SubscriptionProcessor
97
)
108
from ibind.support.py_utils import UNDEFINED
119

@@ -61,24 +59,24 @@ def create_subscription(
6159
'needs_confirmation': needs_confirmation,
6260
'subscription_processor': subscription_processor
6361
}
64-
62+
6563
# Pre-defined common subscription types
6664
create_subscription.active = lambda processor=None, data=None: create_subscription(
6765
status=True, data=data, needs_confirmation=True, subscription_processor=processor
6866
)
69-
67+
7068
create_subscription.inactive = lambda processor=None, data=None: create_subscription(
7169
status=False, data=data, needs_confirmation=True, subscription_processor=processor
7270
)
73-
71+
7472
create_subscription.active_no_confirm = lambda processor=None, data=None: create_subscription(
7573
status=True, data=data, needs_confirmation=False, subscription_processor=processor
7674
)
77-
75+
7876
create_subscription.inactive_no_confirm = lambda processor=None, data=None: create_subscription(
7977
status=False, data=data, needs_confirmation=False, subscription_processor=processor
8078
)
81-
79+
8280
return create_subscription
8381

8482

@@ -110,10 +108,10 @@ def common_subscription_sets(subscription_factory):
110108
def controller_with_mixed_subscriptions(subscription_factory):
111109
"""Create a SubscriptionController with mixed active and inactive subscriptions using factory."""
112110
controller = SubscriptionController(subscription_processor=MagicMock())
113-
111+
114112
mock_processor1 = MagicMock()
115113
mock_processor2 = MagicMock()
116-
114+
117115
controller._subscriptions = {
118116
'active_1': subscription_factory.active(
119117
processor=mock_processor1,
@@ -132,7 +130,7 @@ def controller_with_mixed_subscriptions(subscription_factory):
132130
data={'inactive': 'data2'}
133131
)
134132
}
135-
133+
136134
# Add send method since SubscriptionController is a mixin expecting WsClient
137135
controller.send = MagicMock(return_value=True)
138136
controller.running = True # Default to running state
@@ -143,11 +141,11 @@ def test_is_subscription_active_with_factory(subscription_controller, subscripti
143141
# Test active subscription
144142
subscription_controller._subscriptions['test_active'] = subscription_factory.active()
145143
assert subscription_controller.is_subscription_active('test_active') is True
146-
147-
# Test inactive subscription
144+
145+
# Test inactive subscription
148146
subscription_controller._subscriptions['test_inactive'] = subscription_factory.inactive()
149147
assert subscription_controller.is_subscription_active('test_inactive') is False
150-
148+
151149
# Test subscription without status (missing status key)
152150
incomplete_sub = subscription_factory.inactive()
153151
del incomplete_sub['status']
@@ -163,15 +161,15 @@ def test_has_active_subscriptions_with_factory(subscription_controller, subscrip
163161
'inactive_channel': subscription_factory.inactive(data=None)
164162
}
165163
assert subscription_controller.has_active_subscriptions() is True
166-
164+
167165
# Test with all inactive subscriptions - should return False
168166
subscription_controller._subscriptions = common_subscription_sets['all_inactive']
169167
assert subscription_controller.has_active_subscriptions() is False
170-
171-
# Test with empty subscriptions - should return False
168+
169+
# Test with empty subscriptions - should return False
172170
subscription_controller._subscriptions = {}
173171
assert subscription_controller.has_active_subscriptions() is False
174-
172+
175173
# Test with all active subscriptions - should return True
176174
subscription_controller._subscriptions = common_subscription_sets['all_active']
177175
assert subscription_controller.has_active_subscriptions() is True
@@ -184,10 +182,10 @@ def test_has_subscription_with_factory(subscription_controller, subscription_fac
184182
'existing_channel': subscription_factory.active(data=None)
185183
}
186184
assert subscription_controller.has_subscription('existing_channel') is True
187-
185+
188186
# Test with non-existing channel
189187
assert subscription_controller.has_subscription('non_existing_channel') is False
190-
188+
191189
# Test with empty subscriptions
192190
subscription_controller._subscriptions = {}
193191
assert subscription_controller.has_subscription('any_channel') is False
@@ -286,7 +284,7 @@ def test_attempt_unsubscribing_repeated_retry_logic_integration(subscription_con
286284
test_channel = 'test_channel'
287285
test_payload = 'unsubscribe_payload'
288286
subscription_controller._subscription_retries = retries
289-
287+
290288
# Mock only external dependencies - test real _send_payload behavior
291289
mock_ws_send = MagicMock(return_value=True)
292290
monkeypatch.setattr(subscription_controller, 'send', mock_ws_send)
@@ -320,11 +318,11 @@ def test_recreate_subscriptions_basic_functionality_integration(subscription_con
320318
# Mock only external dependencies - test real subscribe behavior
321319
mock_ws_send = MagicMock(return_value=subscribe_success)
322320
monkeypatch.setattr(subscription_controller, 'send', mock_ws_send)
323-
321+
324322
# Mock subscription processor to create predictable payloads
325323
mock_processor = subscription_controller._subscription_processor
326324
mock_processor.make_subscribe_payload = MagicMock(return_value='test_payload')
327-
325+
328326
# Mock wait_until - simplified approach
329327
# In real usage, wait_until waits for external WebSocket handler to set status=True
330328
# For testing, we just return the desired result without complex simulation
@@ -361,7 +359,7 @@ def test_recreate_subscriptions_basic_functionality_integration(subscription_con
361359
assert subscription_controller._subscriptions[channel]['status'] is True
362360
else:
363361
assert subscription_controller._subscriptions[channel]['status'] is False
364-
362+
365363
# Verify we attempted subscriptions for inactive channels
366364
# Note: Actual call count may be higher due to retries
367365
assert mock_ws_send.call_count >= inactive_count
@@ -371,7 +369,7 @@ def test_recreate_subscriptions_with_failures_integration(subscription_controlle
371369
# Arrange
372370
mock_processor = MagicMock()
373371
mock_processor.make_subscribe_payload = MagicMock(return_value='test_payload')
374-
372+
375373
original_subscriptions = {
376374
'inactive_channel_1': subscription_factory.inactive(
377375
processor=mock_processor,
@@ -387,15 +385,15 @@ def test_recreate_subscriptions_with_failures_integration(subscription_controlle
387385
# Mock external dependencies based on failure scenario
388386
if failure_scenario == "partial":
389387
# For partial failure: send succeeds, but wait_until fails for confirmation-requiring channels
390-
mock_ws_send = MagicMock(return_value=True)
388+
mock_ws_send = MagicMock(return_value=True)
391389
mock_wait_until = MagicMock(return_value=False) # Confirmation fails
392390
else: # all failures
393391
mock_ws_send = MagicMock(return_value=False) # WebSocket send fails
394392
mock_wait_until = MagicMock(return_value=False)
395393

396394
monkeypatch.setattr(subscription_controller, 'send', mock_ws_send)
397395
monkeypatch.setattr('ibind.base.subscription_controller.wait_until', mock_wait_until)
398-
396+
399397
# Set up default processor for channels without specific processor
400398
subscription_controller._subscription_processor.make_subscribe_payload = MagicMock(return_value='default_payload')
401399

@@ -425,7 +423,7 @@ def test_recreate_subscriptions_preserves_subscription_processor_integration(sub
425423
# Arrange
426424
original_processor = MagicMock()
427425
original_processor.make_subscribe_payload = MagicMock(return_value='original_payload')
428-
426+
429427
subscription_controller._subscriptions = {
430428
'test_channel': subscription_factory.inactive(
431429
processor=original_processor,
@@ -450,15 +448,15 @@ def test_recreate_subscriptions_handles_missing_processor_key_integration(subscr
450448
test_subscription = subscription_factory.inactive(data={'test': 'data'})
451449
# Remove the processor key to simulate missing processor
452450
del test_subscription['subscription_processor']
453-
451+
454452
subscription_controller._subscriptions = {
455453
'test_channel': test_subscription
456454
}
457455

458456
# Mock external dependencies to simulate failure
459457
mock_ws_send = MagicMock(return_value=False) # WebSocket send fails
460458
monkeypatch.setattr(subscription_controller, 'send', mock_ws_send)
461-
459+
462460
# Set up default processor
463461
subscription_controller._subscription_processor.make_subscribe_payload = MagicMock(return_value='default_payload')
464462

test/unit/support/test_logs_u.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import datetime
21
import logging
32
import pytest
4-
from pathlib import Path
53
from unittest.mock import patch, MagicMock, mock_open
64

75
from ibind.support.logs import (
@@ -258,56 +256,56 @@ def test_daily_rotating_file_handler_open():
258256
# Mock only file operations and Path.mkdir, not the entire Path class
259257
with patch('builtins.open', mock_open()) as mock_file_open, \
260258
patch('pathlib.Path.mkdir') as mock_mkdir:
261-
259+
262260
handler = DailyRotatingFileHandler(base_filename)
263-
261+
264262
# Test real get_timestamp behavior by using a fixed date
265263
with patch.object(handler, 'get_timestamp', return_value='2024-01-15'):
266264
# Act - Test real _open behavior
267-
file_obj = handler._open()
265+
handler._open()
268266

269-
# Assert
270-
assert handler.timestamp == '2024-01-15'
271-
expected_path = '/tmp/test.log__2024-01-15.txt' # noqa: S108
272-
273-
# Verify real get_filename behavior was used
274-
assert handler.get_filename('2024-01-15') == expected_path
275-
276-
# Verify directory creation and file opening
277-
mock_mkdir.assert_called_with(parents=True, exist_ok=True)
278-
mock_file_open.assert_called_with(expected_path, 'a', encoding='utf-8')
267+
# Assert
268+
assert handler.timestamp == '2024-01-15'
269+
expected_path = '/tmp/test.log__2024-01-15.txt' # noqa: S108
270+
271+
# Verify real get_filename behavior was used
272+
assert handler.get_filename('2024-01-15') == expected_path
273+
274+
# Verify directory creation and file opening
275+
mock_mkdir.assert_called_with(parents=True, exist_ok=True)
276+
mock_file_open.assert_called_with(expected_path, 'a', encoding='utf-8')
279277

280278

281279
def test_daily_rotating_file_handler_emit_rotation():
282280
# Arrange
283281
base_filename = '/tmp/test.log' # noqa: S108
284-
285-
with patch('builtins.open', mock_open()) as mock_file_open, \
286-
patch('pathlib.Path.mkdir') as mock_mkdir:
287-
282+
283+
with patch('builtins.open', mock_open()), \
284+
patch('pathlib.Path.mkdir'):
285+
288286
handler = DailyRotatingFileHandler(base_filename)
289287
handler.timestamp = '2024-01-15' # Set initial timestamp
290-
288+
291289
# Create a mock stream to simulate file being open
292290
mock_stream = MagicMock()
293291
handler.stream = mock_stream
294-
292+
295293
# Create test log record
296294
record = logging.LogRecord('test', logging.INFO, 'path', 1, 'test message', (), None)
297-
295+
298296
# Test case 1: Same timestamp - no rotation
299297
with patch.object(handler, 'get_timestamp', return_value='2024-01-15'):
300298
handler.emit(record)
301-
299+
302300
# Should not have called close or _open
303301
mock_stream.close.assert_not_called()
304-
302+
305303
# Test case 2: Different timestamp - should rotate
306304
with patch.object(handler, 'get_timestamp', return_value='2024-01-16'), \
307305
patch.object(handler, '_open', return_value=MagicMock()) as mock_open_method:
308-
306+
309307
handler.emit(record)
310-
308+
311309
# Should have closed old file and opened new one
312310
mock_stream.close.assert_called_once()
313311
mock_open_method.assert_called_once()

0 commit comments

Comments
 (0)