|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import json |
16 | | -import sys |
17 | 16 |
|
18 | 17 | import numpy as np |
19 | 18 | import pandas as pd |
@@ -227,76 +226,3 @@ def test_json_arrow_record_batch(): |
227 | 226 | == '{"null_field":null,"order":{"address":{"city":"Anytown","street":"123 Main St"},"items":["book","pen","computer"],"total":15}}' |
228 | 227 | ) |
229 | 228 | assert s[6] == "null" |
230 | | - |
231 | | - |
232 | | -@pytest.fixture |
233 | | -def cleanup_json_module_for_reload(): |
234 | | - """ |
235 | | - Fixture to ensure db_dtypes.json is registered and then removed |
236 | | - from sys.modules to allow testing the registration except block via reload. |
237 | | - """ |
238 | | - |
239 | | - json_module_name = "db_dtypes.json" |
240 | | - original_module = sys.modules.get(json_module_name) |
241 | | - |
242 | | - # Ensure the type is registered initially (usually by the first import) |
243 | | - try: |
244 | | - # Make sure the module is loaded so the type exists |
245 | | - import db_dtypes.json |
246 | | - |
247 | | - # Explicitly register just in case it wasn't, or was cleaned up elsewhere. |
248 | | - # This might raise ArrowKeyError itself if already registered, which is fine here. |
249 | | - pa.register_extension_type(db_dtypes.json.JSONArrowType()) |
250 | | - |
251 | | - except pa.ArrowKeyError: |
252 | | - pass # Already registered is the state we want before the test runs |
253 | | - |
254 | | - # Remove the module from sys.modules so importlib.reload which will happen |
255 | | - # after the yield statement will re-execute it |
256 | | - if json_module_name in sys.modules: # pragma: NO COVER |
257 | | - del sys.modules[json_module_name] |
258 | | - |
259 | | - yield # Run the test that uses this fixture |
260 | | - |
261 | | - # Cleanup: Put the original module back if it existed |
262 | | - # This helps isolate from other tests that might import db_dtypes.json |
263 | | - if original_module: |
264 | | - sys.modules[json_module_name] = original_module |
265 | | - elif json_module_name in sys.modules: # pragma: NO COVER |
266 | | - # If the test re-imported it but it wasn't there originally, remove it |
267 | | - del sys.modules[json_module_name] |
268 | | - |
269 | | - # Note: PyArrow doesn't have a public API to unregister types easily, |
270 | | - # thus we are using the testing pattern of module isolation/reloading. |
271 | | - |
272 | | - |
273 | | -# Test specifically for the fixture's pre-yield removal logic |
274 | | -def test_fixture_removes_module_if_present(cleanup_json_module_for_reload): |
275 | | - """ |
276 | | - Tests that the cleanup_json_module_for_reload fixture removes |
277 | | - db_dtypes.json from sys.modules before yielding to the test. |
278 | | - This specifically targets the 'if json_module_name in sys.modules:' block. |
279 | | - """ |
280 | | - # This test runs *after* the fixture's `yield`. |
281 | | - # The fixture should have removed the module if it was present. |
282 | | - |
283 | | - json_module_name = "db_dtypes.json" |
284 | | - |
285 | | - assert ( |
286 | | - json_module_name not in sys.modules |
287 | | - ), f"The fixture cleanup_json_module_for_reload should have removed {json_module_name}" |
288 | | - |
289 | | - |
290 | | -def test_json_arrow_type_reregistration_is_handled(cleanup_json_module_for_reload): |
291 | | - """ |
292 | | - Verify that attempting to re-register JSONArrowType via module reload |
293 | | - is caught by the except block and does not raise an error. |
294 | | - """ |
295 | | - |
296 | | - # Re-importing the module after the fixture removed it from sys.modules |
297 | | - # forces Python to execute the module's top-level code again. |
298 | | - # This includes the pa.register_extension_type call. |
299 | | - |
300 | | - import db_dtypes.json # noqa: F401 |
301 | | - |
302 | | - assert True, "Module re-import completed without error, except block likely worked." |
0 commit comments