1313# Helpers
1414# ---------------------------------------------------------------------------
1515
16+
1617class DummyZMQPort :
1718 """Minimal stand-in for ZeroMQPort used in ZMQ read tests."""
1819
@@ -33,22 +34,24 @@ def recv_json_with_retry(self):
3334# File-based read tests
3435# ---------------------------------------------------------------------------
3536
37+
3638class TestReadFileSuccess :
3739 """read() on a valid file returns (data, True) with SUCCESS status."""
3840
3941 @pytest .fixture (autouse = True )
4042 def setup (self , temp_dir , monkeypatch ):
4143 import concore
44+
4245 self .concore = concore
43- monkeypatch .setattr (concore , ' delay' , 0 )
46+ monkeypatch .setattr (concore , " delay" , 0 )
4447
4548 # Create ./in1/ym with valid data: [simtime, value]
4649 in_dir = os .path .join (temp_dir , "in1" )
4750 os .makedirs (in_dir , exist_ok = True )
4851 with open (os .path .join (in_dir , "ym" ), "w" ) as f :
4952 f .write ("[10, 3.14]" )
5053
51- monkeypatch .setattr (concore , ' inpath' , os .path .join (temp_dir , "in" ))
54+ monkeypatch .setattr (concore , " inpath" , os .path .join (temp_dir , "in" ))
5255
5356 def test_returns_data_and_true (self ):
5457 data , ok = self .concore .read (1 , "ym" , "[0, 0.0]" )
@@ -66,10 +69,11 @@ class TestReadFileMissing:
6669 @pytest .fixture (autouse = True )
6770 def setup (self , temp_dir , monkeypatch ):
6871 import concore
72+
6973 self .concore = concore
70- monkeypatch .setattr (concore , ' delay' , 0 )
74+ monkeypatch .setattr (concore , " delay" , 0 )
7175 # Point to a directory that does NOT have the file
72- monkeypatch .setattr (concore , ' inpath' , os .path .join (temp_dir , "in" ))
76+ monkeypatch .setattr (concore , " inpath" , os .path .join (temp_dir , "in" ))
7377
7478 def test_returns_default_and_false (self ):
7579 data , ok = self .concore .read (1 , "nonexistent" , "[0, 0.0]" )
@@ -86,15 +90,16 @@ class TestReadFileParseError:
8690 @pytest .fixture (autouse = True )
8791 def setup (self , temp_dir , monkeypatch ):
8892 import concore
93+
8994 self .concore = concore
90- monkeypatch .setattr (concore , ' delay' , 0 )
95+ monkeypatch .setattr (concore , " delay" , 0 )
9196
9297 in_dir = os .path .join (temp_dir , "in1" )
9398 os .makedirs (in_dir , exist_ok = True )
9499 with open (os .path .join (in_dir , "ym" ), "w" ) as f :
95100 f .write ("NOT_VALID_PYTHON{{{" )
96101
97- monkeypatch .setattr (concore , ' inpath' , os .path .join (temp_dir , "in" ))
102+ monkeypatch .setattr (concore , " inpath" , os .path .join (temp_dir , "in" ))
98103
99104 def test_returns_default_and_false (self ):
100105 data , ok = self .concore .read (1 , "ym" , "[0, 0.0]" )
@@ -111,16 +116,17 @@ class TestReadFileRetriesExceeded:
111116 @pytest .fixture (autouse = True )
112117 def setup (self , temp_dir , monkeypatch ):
113118 import concore
119+
114120 self .concore = concore
115- monkeypatch .setattr (concore , ' delay' , 0 )
121+ monkeypatch .setattr (concore , " delay" , 0 )
116122
117123 # Create an empty file
118124 in_dir = os .path .join (temp_dir , "in1" )
119125 os .makedirs (in_dir , exist_ok = True )
120126 with open (os .path .join (in_dir , "ym" ), "w" ) as f :
121127 pass # empty
122128
123- monkeypatch .setattr (concore , ' inpath' , os .path .join (temp_dir , "in" ))
129+ monkeypatch .setattr (concore , " inpath" , os .path .join (temp_dir , "in" ))
124130
125131 def test_returns_default_and_false (self ):
126132 data , ok = self .concore .read (1 , "ym" , "[0, 0.0]" )
@@ -135,12 +141,14 @@ def test_last_read_status_is_retries_exceeded(self):
135141# ZMQ read tests
136142# ---------------------------------------------------------------------------
137143
144+
138145class TestReadZMQSuccess :
139146 """Successful ZMQ read returns (data, True)."""
140147
141148 @pytest .fixture (autouse = True )
142149 def setup (self , monkeypatch ):
143150 import concore
151+
144152 self .concore = concore
145153 self .original_ports = concore .zmq_ports .copy ()
146154 yield
@@ -164,6 +172,7 @@ class TestReadZMQTimeout:
164172 @pytest .fixture (autouse = True )
165173 def setup (self , monkeypatch ):
166174 import concore
175+
167176 self .concore = concore
168177 self .original_ports = concore .zmq_ports .copy ()
169178 yield
@@ -185,6 +194,7 @@ class TestReadZMQError:
185194 @pytest .fixture (autouse = True )
186195 def setup (self , monkeypatch ):
187196 import concore
197+
188198 self .concore = concore
189199 self .original_ports = concore .zmq_ports .copy ()
190200 yield
@@ -193,6 +203,7 @@ def setup(self, monkeypatch):
193203
194204 def test_zmq_error_returns_default_and_false (self ):
195205 import zmq
206+
196207 dummy = DummyZMQPort (raise_on_recv = zmq .error .ZMQError ("test error" ))
197208 self .concore .zmq_ports ["test_port" ] = dummy
198209
@@ -205,21 +216,23 @@ def test_zmq_error_returns_default_and_false(self):
205216# Backward compatibility
206217# ---------------------------------------------------------------------------
207218
219+
208220class TestReadBackwardCompatibility :
209221 """Legacy callers can use isinstance check on the result."""
210222
211223 @pytest .fixture (autouse = True )
212224 def setup (self , temp_dir , monkeypatch ):
213225 import concore
226+
214227 self .concore = concore
215- monkeypatch .setattr (concore , ' delay' , 0 )
228+ monkeypatch .setattr (concore , " delay" , 0 )
216229
217230 in_dir = os .path .join (temp_dir , "in1" )
218231 os .makedirs (in_dir , exist_ok = True )
219232 with open (os .path .join (in_dir , "ym" ), "w" ) as f :
220233 f .write ("[10, 42.0]" )
221234
222- monkeypatch .setattr (concore , ' inpath' , os .path .join (temp_dir , "in" ))
235+ monkeypatch .setattr (concore , " inpath" , os .path .join (temp_dir , "in" ))
223236
224237 def test_legacy_unpack_pattern (self ):
225238 """The recommended migration pattern works correctly."""
@@ -245,17 +258,24 @@ def test_tuple_unpack(self):
245258# last_read_status exposed on module
246259# ---------------------------------------------------------------------------
247260
261+
248262class TestLastReadStatusExposed :
249263 """concore.last_read_status is publicly accessible."""
250264
251265 def test_attribute_exists (self ):
252266 import concore
253- assert hasattr (concore , 'last_read_status' )
267+
268+ assert hasattr (concore , "last_read_status" )
254269
255270 def test_initial_value_is_success (self ):
256271 import concore
272+
257273 # Before any read, default is SUCCESS
258274 assert concore .last_read_status in (
259- "SUCCESS" , "FILE_NOT_FOUND" , "TIMEOUT" ,
260- "PARSE_ERROR" , "EMPTY_DATA" , "RETRIES_EXCEEDED" ,
275+ "SUCCESS" ,
276+ "FILE_NOT_FOUND" ,
277+ "TIMEOUT" ,
278+ "PARSE_ERROR" ,
279+ "EMPTY_DATA" ,
280+ "RETRIES_EXCEEDED" ,
261281 )
0 commit comments