@@ -26,19 +26,19 @@ def dumper(data):
2626 store = SyncStore (loader , dumper )
2727
2828 # Set
29- store [' key' ] = ' value'
30- assert store [' key' ] == ' value'
31- assert data_holder [0 ][' key' ] == ' value'
29+ store [" key" ] = " value"
30+ assert store [" key" ] == " value"
31+ assert data_holder [0 ][" key" ] == " value"
3232
3333 # Delete
34- del store [' key' ]
35- assert ' key' not in store
36- assert ' key' not in data_holder [0 ]
34+ del store [" key" ]
35+ assert " key" not in store
36+ assert " key" not in data_holder [0 ]
3737
3838 # Iteration
39- store ['a' ] = 1
40- store ['b' ] = 2
41- assert set (store ) == {'a' , 'b' }
39+ store ["a" ] = 1
40+ store ["b" ] = 2
41+ assert set (store ) == {"a" , "b" }
4242
4343 # Length
4444 assert len (store ) == 2
@@ -58,13 +58,13 @@ def dumper(data):
5858
5959 store = SyncStore (loader , dumper )
6060
61- store ['a' ] = 1
61+ store ["a" ] = 1
6262 assert sync_count [0 ] == 1
6363
64- store ['b' ] = 2
64+ store ["b" ] = 2
6565 assert sync_count [0 ] == 2
6666
67- del store ['a' ]
67+ del store ["a" ]
6868 assert sync_count [0 ] == 3
6969
7070
@@ -84,13 +84,13 @@ def dumper(data):
8484
8585 # Batch operations
8686 with store :
87- store ['a' ] = 1
88- store ['b' ] = 2
89- store ['c' ] = 3
87+ store ["a" ] = 1
88+ store ["b" ] = 2
89+ store ["c" ] = 3
9090 assert sync_count [0 ] == 0 # Not synced yet
9191
9292 assert sync_count [0 ] == 1 # Synced once on exit
93- assert data_holder [0 ] == {'a' : 1 , 'b' : 2 , 'c' : 3 }
93+ assert data_holder [0 ] == {"a" : 1 , "b" : 2 , "c" : 3 }
9494
9595
9696def test_sync_store_manual_flush ():
@@ -108,111 +108,111 @@ def dumper(data):
108108 store = SyncStore (loader , dumper )
109109
110110 with store :
111- store ['a' ] = 1
111+ store ["a" ] = 1
112112 assert sync_count [0 ] == 0
113113
114114 store .flush () # Manual flush
115115 assert sync_count [0 ] == 1
116116
117- store ['b' ] = 2
117+ store ["b" ] = 2
118118 assert sync_count [0 ] == 1 # Still in context, not auto-synced
119119
120120 assert sync_count [0 ] == 2 # Final flush on exit
121121
122122
123123def test_file_store_json ():
124124 """Test FileStore with JSON file."""
125- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
125+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
126126 f .write ('{"key": "value"}' )
127127 temp_file = f .name
128128
129129 try :
130130 store = FileStore (temp_file )
131131
132132 # Read
133- assert store [' key' ] == ' value'
133+ assert store [" key" ] == " value"
134134
135135 # Write
136- store [' new_key' ] = ' new_value'
136+ store [" new_key" ] = " new_value"
137137
138138 # Verify persistence
139139 with open (temp_file ) as f :
140140 data = json .load (f )
141- assert data [' new_key' ] == ' new_value'
141+ assert data [" new_key" ] == " new_value"
142142
143143 # Delete
144- del store [' key' ]
145- assert ' key' not in store
144+ del store [" key" ]
145+ assert " key" not in store
146146
147147 finally :
148148 Path (temp_file ).unlink ()
149149
150150
151151def test_file_store_key_path ():
152152 """Test FileStore with nested key_path."""
153- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
153+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
154154 f .write ('{"section1": {"a": 1}, "section2": {"b": 2}}' )
155155 temp_file = f .name
156156
157157 try :
158158 # Work with section1 only
159- section1 = FileStore (temp_file , key_path = ' section1' )
159+ section1 = FileStore (temp_file , key_path = " section1" )
160160
161- assert section1 ['a' ] == 1
162- section1 ['c' ] = 3
163- assert 'c' in section1
161+ assert section1 ["a" ] == 1
162+ section1 ["c" ] = 3
163+ assert "c" in section1
164164
165165 # Verify section2 untouched
166166 with open (temp_file ) as f :
167167 data = json .load (f )
168- assert data [' section2' ] == {'b' : 2 }
169- assert data [' section1' ][ 'c' ] == 3
168+ assert data [" section2" ] == {"b" : 2 }
169+ assert data [" section1" ][ "c" ] == 3
170170
171171 finally :
172172 Path (temp_file ).unlink ()
173173
174174
175175def test_file_store_dotted_key_path ():
176176 """Test FileStore with dotted key_path notation."""
177- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
177+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
178178 f .write ('{"a": {"b": {"c": {}}}}' )
179179 temp_file = f .name
180180
181181 try :
182- nested = FileStore (temp_file , key_path = ' a.b.c' )
183- nested [' key' ] = ' value'
182+ nested = FileStore (temp_file , key_path = " a.b.c" )
183+ nested [" key" ] = " value"
184184
185185 with open (temp_file ) as f :
186186 data = json .load (f )
187- assert data ['a' ][ 'b' ][ 'c' ][ ' key' ] == ' value'
187+ assert data ["a" ][ "b" ][ "c" ][ " key" ] == " value"
188188
189189 finally :
190190 Path (temp_file ).unlink ()
191191
192192
193193def test_json_store ():
194194 """Test JsonStore with defaults."""
195- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
195+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
196196 f .write ('{"key": "value"}' )
197197 temp_file = f .name
198198
199199 try :
200200 store = JsonStore (temp_file )
201- store [' new' ] = ' data'
201+ store [" new" ] = " data"
202202
203203 # Check formatting (indent=2 by default)
204204 with open (temp_file ) as f :
205205 content = f .read ()
206- assert ' ' in content # Should have indentation
206+ assert " " in content # Should have indentation
207207
208208 finally :
209209 Path (temp_file ).unlink ()
210210
211211
212212def test_file_store_batch_operations ():
213213 """Test that batch operations work efficiently."""
214- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
215- f .write ('{}' )
214+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
215+ f .write ("{}" )
216216 temp_file = f .name
217217
218218 try :
@@ -221,13 +221,13 @@ def test_file_store_batch_operations():
221221 # Batch mode - only one write
222222 with store :
223223 for i in range (100 ):
224- store [f' key_{ i } ' ] = i
224+ store [f" key_{ i } " ] = i
225225
226226 # Verify all written
227227 with open (temp_file ) as f :
228228 data = json .load (f )
229229 assert len (data ) == 100
230- assert data [' key_42' ] == 42
230+ assert data [" key_42" ] == 42
231231
232232 finally :
233233 Path (temp_file ).unlink ()
@@ -238,20 +238,20 @@ def test_extension_registry():
238238
239239 # Register custom format
240240 def custom_loader (content ):
241- return {' loaded' : content }
241+ return {" loaded" : content }
242242
243243 def custom_dumper (data ):
244244 return str (data )
245245
246- register_extension (' .custom' , custom_loader , custom_dumper )
246+ register_extension (" .custom" , custom_loader , custom_dumper )
247247
248- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .custom' , delete = False ) as f :
249- f .write (' test content' )
248+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .custom" , delete = False ) as f :
249+ f .write (" test content" )
250250 temp_file = f .name
251251
252252 try :
253253 store = FileStore (temp_file )
254- assert store [' loaded' ] == ' test content'
254+ assert store [" loaded" ] == " test content"
255255
256256 finally :
257257 Path (temp_file ).unlink ()
@@ -261,27 +261,27 @@ def test_store_repr():
261261 """Test string representations."""
262262 data_holder = [{}]
263263 store = SyncStore (lambda : data_holder [0 ], lambda d : None )
264- assert ' SyncStore' in repr (store )
264+ assert " SyncStore" in repr (store )
265265
266- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .json' , delete = False ) as f :
266+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .json" , delete = False ) as f :
267267 f .write ('{"section": {}}' ) # Include section key
268268 temp_file = f .name
269269
270270 try :
271271 file_store = FileStore (temp_file )
272- assert ' FileStore' in repr (file_store )
272+ assert " FileStore" in repr (file_store )
273273 assert temp_file in repr (file_store )
274274
275- file_store_with_path = FileStore (temp_file , key_path = ' section' )
276- assert ' key_path' in repr (file_store_with_path )
275+ file_store_with_path = FileStore (temp_file , key_path = " section" )
276+ assert " key_path" in repr (file_store_with_path )
277277
278278 finally :
279279 Path (temp_file ).unlink ()
280280
281281
282- if __name__ == ' __main__' :
282+ if __name__ == " __main__" :
283283 if PYTEST_AVAILABLE :
284- pytest .main ([__file__ , '-v' ])
284+ pytest .main ([__file__ , "-v" ])
285285 else :
286286 # Run tests manually
287287 print ("Running tests without pytest..." )
0 commit comments