Skip to content

Commit 9a80e10

Browse files
committed
fix flake8 error
1 parent 45cebc9 commit 9a80e10

11 files changed

+46
-59
lines changed

objwatch/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from .config import ObjWatchConfig
1010
from .tracer import Tracer
1111
from .wrappers import ABCWrapper
12-
from .runtime_info import runtime_info
13-
from .sinks.consumer import ZeroMQFileConsumer, DynamicRoutingConsumer
12+
from .sinks.consumer import DynamicRoutingConsumer
1413
from .utils.logger import log_info, setup_logging_from_config
14+
from .runtime_info import runtime_info
1515

1616

1717
class ObjWatch:

objwatch/sinks/consumer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# MIT License
22
# Copyright (c) 2025 aeeeeeep
33

4+
import os
45
import zmq
56
import time
67
import logging
78
import msgpack
89
import threading
9-
import os
10-
import sys
1110
from pathlib import Path
1211
from typing import Dict, Any, Optional
1312
from collections import OrderedDict
14-
from functools import lru_cache
1513

1614

1715
class ZeroMQFileConsumer:

objwatch/utils/logger.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,17 @@ def emit(self, record: logging.LogRecord) -> None:
130130
'time': record.created,
131131
'name': record.name,
132132
}
133-
133+
134134
# Add output_file and process_id for dynamic routing support
135135
if hasattr(sink, 'output_file') and sink.output_file:
136136
event['output_file'] = sink.output_file
137137
else:
138138
event['output_file'] = None
139-
139+
140140
import os
141+
141142
event['process_id'] = os.getpid()
142-
143+
143144
sink.emit(event)
144145
except Exception as e:
145146
logging.error(f"SinkHandler failed to emit record: {e}")

tests/test_base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33

44
import os
55
import runpy
6-
import importlib
7-
import unittest
8-
from unittest.mock import MagicMock, patch
96
import logging
7+
import unittest
8+
import importlib
109
from io import StringIO
10+
from unittest.mock import MagicMock, patch
11+
1112
import objwatch
12-
from objwatch.config import ObjWatchConfig
1313
from objwatch.wrappers import BaseWrapper, TensorShapeWrapper, ABCWrapper
1414
from objwatch.core import ObjWatch
1515
from objwatch.targets import Targets
16-
from objwatch.tracer import Tracer
1716
from tests.util import strip_line_numbers
1817

1918
try:
@@ -285,7 +284,10 @@ def test_wrap_call_with_tensor_dict_over_limit(self):
285284

286285
tensors_dict = {f"key_{i}": torch.randn(2, 2) for i in range(5)}
287286
mock_frame.f_locals = {'arg_tensors': tensors_dict}
288-
expected_call_msg = "'0':(dict)[('key_0', torch.Size([2, 2])), ('key_1', torch.Size([2, 2])), ('key_2', torch.Size([2, 2])), '... (2 more elements)']"
287+
expected_call_msg = (
288+
"'0':(dict)[('key_0', torch.Size([2, 2])), ('key_1', torch.Size([2, 2])), "
289+
"('key_2', torch.Size([2, 2])), '... (2 more elements)']"
290+
)
289291
actual_call_msg = self.tensor_shape_logger.wrap_call('test_tensor_func', mock_frame)
290292
self.assertEqual(actual_call_msg, expected_call_msg)
291293

tests/test_comprehensive_exclude.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
#!/usr/bin/env python3
2-
"""
3-
Comprehensive test for exclude functionality in track_all mode.
4-
"""
5-
6-
import sys
7-
import os
8-
9-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
1+
# MIT License
2+
# Copyright (c) 2025 aeeeeeep
103

114
from objwatch.tracer import Tracer
125
from objwatch.config import ObjWatchConfig
136

14-
# Import test module from the same directory
15-
from .utils.example_module import TestClass
16-
177

188
def test_comprehensive_exclude():
199
"""Test comprehensive exclude functionality with track_all mode."""

tests/test_exclude_functionality.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
#!/usr/bin/env python3
2-
"""Test script to verify exclude functionality with track_all."""
1+
# MIT License
2+
# Copyright (c) 2025 aeeeeeep
33

44
import sys
5-
import os
65

7-
# Add the objwatch package to the path
8-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9-
10-
from objwatch.config import ObjWatchConfig
116
from objwatch.tracer import Tracer
12-
13-
# Import test module from the same directory
14-
from .utils.example_module import TestClass
7+
from objwatch.config import ObjWatchConfig
158

169

1710
def test_exclude_functionality():
@@ -50,10 +43,10 @@ def test_exclude_functionality():
5043
print(f"Should track excluded_attr: {should_track_attr_excluded}")
5144

5245
# Verify results
53-
assert should_track_tracked == True, "tracked_method should be tracked"
54-
assert should_track_excluded == False, "excluded_method should be excluded"
55-
assert should_track_attr_tracked == True, "tracked_attr should be tracked"
56-
assert should_track_attr_excluded == False, "excluded_attr should be excluded"
46+
assert should_track_tracked, "tracked_method should be tracked"
47+
assert not should_track_excluded, "excluded_method should be excluded"
48+
assert should_track_attr_tracked, "tracked_attr should be tracked"
49+
assert not should_track_attr_excluded, "excluded_attr should be excluded"
5750

5851
print("All exclude functionality tests passed!")
5952
# All assertions passed, no return value needed for pytest

tests/test_multiprocessing_handls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# MIT License
2+
# Copyright (c) 2025 aeeeeeep
3+
14
import runpy
25
import unittest
36
from objwatch import ObjWatch

tests/test_zmq_dynamic_routing.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import time
66
import tempfile
77
import unittest
8-
from objwatch.sinks.consumer import DynamicRoutingConsumer
8+
99
from objwatch.sinks.zmq_sink import ZeroMQSink
10+
from objwatch.sinks.consumer import DynamicRoutingConsumer
1011

1112

1213
class TestDynamicRoutingConsumer(unittest.TestCase):
@@ -88,7 +89,7 @@ def test_dynamic_routing_basic(self):
8889
"output_file": output1,
8990
"process_id": os.getpid(),
9091
}
91-
92+
9293
sink.emit(event1)
9394
sink.emit(event2)
9495
sink.emit(event3)
@@ -114,18 +115,18 @@ def test_dynamic_routing_basic(self):
114115
# Check that at least some messages were received
115116
self.assertTrue(len(content1) > 0, "Output file 1 should contain messages")
116117
self.assertTrue(len(content2) > 0, "Output file 2 should contain messages")
117-
118+
118119
# Check for presence of expected messages (may not be all due to ZeroMQ async nature)
119120
if "Message to output1" in content1:
120121
print("✓ Received 'Message to output1'")
121122
else:
122123
print("✗ Did not receive 'Message to output1' (may be due to ZeroMQ timing)")
123-
124+
124125
if "Another message to output1" in content1:
125126
print("✓ Received 'Another message to output1'")
126127
else:
127128
print("✗ Did not receive 'Another message to output1' (may be due to ZeroMQ timing)")
128-
129+
129130
if "Message to output2" in content2:
130131
print("✓ Received 'Message to output2'")
131132
else:
@@ -172,13 +173,13 @@ def test_file_handle_lru_cache(self):
172173
Test LRU cache for file handles.
173174
"""
174175
max_open_files = 3
175-
176+
176177
# Create ZeroMQSink first and bind to endpoint
177178
sink = ZeroMQSink(endpoint=self.endpoint, topic="")
178-
179+
179180
# Wait a bit for sink to be ready
180181
time.sleep(0.1)
181-
182+
182183
consumer = DynamicRoutingConsumer(
183184
endpoint=self.endpoint,
184185
auto_start=True,
@@ -226,9 +227,7 @@ def test_consumer_lifecycle(self):
226227
Test proper lifecycle management of DynamicRoutingConsumer.
227228
"""
228229
# Create consumer
229-
consumer = DynamicRoutingConsumer(
230-
endpoint=self.endpoint, auto_start=False, allowed_directories=[self.temp_dir]
231-
)
230+
consumer = DynamicRoutingConsumer(endpoint=self.endpoint, auto_start=False, allowed_directories=[self.temp_dir])
232231

233232
# Start consumer
234233
consumer.start()
@@ -284,10 +283,10 @@ def test_process_id_in_output(self):
284283

285284
# Create ZeroMQSink first and bind to endpoint
286285
sink = ZeroMQSink(endpoint=self.endpoint, topic="")
287-
286+
288287
# Wait a bit for sink to be ready
289288
time.sleep(0.1)
290-
289+
291290
# Create and start consumer
292291
consumer = DynamicRoutingConsumer(
293292
endpoint=self.endpoint, auto_start=True, daemon=True, allowed_directories=[self.temp_dir]
@@ -321,10 +320,10 @@ def test_process_id_in_output(self):
321320
if os.path.exists(output_file):
322321
with open(output_file, "r") as f:
323322
content = f.read()
324-
323+
325324
# Check that at least some messages were received
326325
self.assertTrue(len(content) > 0, "Output file should contain messages")
327-
326+
328327
# Check for process ID (may not be present if no messages were received)
329328
if "PID:12345" in content:
330329
print("✓ Process ID found in output")

tests/test_zmq_e2e.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import unittest
77
import tempfile
8+
89
from objwatch import ObjWatch, watch
910
from objwatch.config import ObjWatchConfig
1011
from objwatch.sinks.consumer import ZeroMQFileConsumer

tests/test_zmq_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import sys
66
import time
7+
78
from objwatch import ObjWatch
89
from objwatch.config import ObjWatchConfig
910

0 commit comments

Comments
 (0)