@@ -38,13 +38,17 @@ def test_e2e(self):
3838 sleep (2 )
3939 assert loader .get_load_error () == str (None )
4040 assert loader .get_core_version () == "0.0.1"
41+ # Verify load time was measured
42+ assert loader .get_load_time () is not None
43+ assert loader .get_load_time () >= 0
4144
4245 def test_core_loader_initialization (self ):
4346 """Test that _CoreLoader initializes with None values."""
4447 loader = _CoreLoader ()
4548 assert loader ._version is None
4649 assert loader ._error is None
4750 assert loader ._path is None
51+ assert loader ._load_time is None
4852
4953 @pytest .mark .parametrize (
5054 "system,expected" ,
@@ -194,7 +198,7 @@ def test_register_functions(self):
194198 assert mock_core .sf_core_full_version .restype == ctypes .c_char_p
195199
196200 def test_load_minicore (self ):
197- """Test that _load_minicore loads the library."""
201+ """Test that _load_minicore loads the library correctly ."""
198202 mock_path = mock .MagicMock ()
199203 mock_lib_path = "/path/to/libsf_mini_core.so"
200204
@@ -255,7 +259,7 @@ def test_load_skips_loading_when_core_disabled(self):
255259 def test_load_success (self ):
256260 """Test successful load of the core library."""
257261 loader = _CoreLoader ()
258- mock_path = mock . MagicMock ()
262+ mock_path = "/path/to/libsf_mini_core.so"
259263 mock_core = mock .MagicMock ()
260264 mock_version = b"1.2.3"
261265 mock_core .sf_core_full_version = mock .MagicMock (return_value = mock_version )
@@ -270,15 +274,18 @@ def test_load_success(self):
270274 with mock .patch .object (
271275 loader , "_register_functions"
272276 ) as mock_register :
273- loader .load ()
274- sleep (2 )
275-
276- mock_get_path .assert_called_once ()
277- mock_load .assert_called_once_with (mock_path )
278- mock_register .assert_called_once_with (mock_core )
279- assert loader ._version == mock_version
280- assert loader ._error is None
281- assert loader ._path == str (mock_path )
277+ with mock .patch ("time.perf_counter" , side_effect = [0.0 , 0.0155 ]):
278+ loader .load ()
279+ sleep (2 )
280+
281+ mock_get_path .assert_called_once ()
282+ mock_load .assert_called_once_with (mock_path )
283+ mock_register .assert_called_once_with (mock_core )
284+ assert loader ._version == mock_version
285+ assert loader ._error is None
286+ assert loader ._path == mock_path
287+ # (0.0155 - 0.0) * 1000 = 15.5 ms
288+ assert loader ._load_time == 15.5
282289
283290 def test_load_failure (self ):
284291 """Test that load captures exceptions."""
@@ -349,6 +356,102 @@ def test_get_file_name_no_path(self):
349356
350357 assert result is None
351358
359+ def test_get_load_time_with_time (self ):
360+ """Test get_load_time returns the load time when it has been set."""
361+ loader = _CoreLoader ()
362+ loader ._load_time = 42.5
363+
364+ result = loader .get_load_time ()
365+
366+ assert result == 42.5
367+
368+ def test_get_load_time_no_time (self ):
369+ """Test get_load_time returns None when no load time exists."""
370+ loader = _CoreLoader ()
371+
372+ result = loader .get_load_time ()
373+
374+ assert result is None
375+
376+ def test_get_present_binaries_contains_expected_paths (self ):
377+ """Test get_present_binaries returns binaries for expected paths."""
378+ loader = _CoreLoader ()
379+
380+ result = loader .get_present_binaries ()
381+
382+ assert isinstance (result , str )
383+ assert result != ""
384+
385+ def test_get_present_binaries_with_mocked_structure (self , tmp_path ):
386+ """Test get_present_binaries with mocked directory structure."""
387+ loader = _CoreLoader ()
388+
389+ # Create a temporary directory structure mimicking minicore layout
390+ # Create platform directories with binary files
391+ linux_dir = tmp_path / "linux_x86_64_glibc"
392+ linux_dir .mkdir ()
393+ (linux_dir / "libsf_mini_core.so" ).write_text ("fake binary content" )
394+
395+ macos_dir = tmp_path / "macos_aarch64"
396+ macos_dir .mkdir ()
397+ (macos_dir / "libsf_mini_core.dylib" ).write_text ("fake binary content" )
398+
399+ windows_dir = tmp_path / "windows_x86_64"
400+ windows_dir .mkdir ()
401+ (windows_dir / "sf_mini_core.dll" ).write_text ("fake binary content" )
402+
403+ # Create a __pycache__ directory that should be ignored
404+ pycache_dir = tmp_path / "__pycache__"
405+ pycache_dir .mkdir ()
406+ (pycache_dir / "some_file.pyc" ).write_text ("cached file" )
407+
408+ # Mock importlib.resources.files to return our temp directory
409+ with mock .patch ("importlib.resources.files" ) as mock_files :
410+ mock_files .return_value = tmp_path
411+
412+ result = loader .get_present_binaries ()
413+
414+ # Verify the function was called with correct module name
415+ mock_files .assert_called_once_with ("snowflake.connector.minicore" )
416+
417+ # Parse the result
418+ binaries = result .split ("," )
419+ assert len (binaries ) == 3
420+
421+ # Verify all expected binaries are present
422+ assert "linux_x86_64_glibc/libsf_mini_core.so" in binaries
423+ assert "macos_aarch64/libsf_mini_core.dylib" in binaries
424+ assert "windows_x86_64/sf_mini_core.dll" in binaries
425+
426+ # Verify __pycache__ files are not included
427+ assert not any ("__pycache__" in binary for binary in binaries )
428+
429+ def test_get_present_binaries_with_empty_directory (self , tmp_path ):
430+ """Test get_present_binaries returns empty string for empty directory."""
431+ loader = _CoreLoader ()
432+
433+ # Create an empty temp directory
434+ # Mock importlib.resources.files to return our temp directory
435+ with mock .patch ("importlib.resources.files" ) as mock_files :
436+ mock_files .return_value = tmp_path
437+
438+ result = loader .get_present_binaries ()
439+
440+ assert result == ""
441+
442+ def test_get_present_binaries_handles_exceptions (self ):
443+ """Test get_present_binaries handles exceptions gracefully."""
444+ loader = _CoreLoader ()
445+
446+ # Mock importlib.resources.files to raise an exception
447+ with mock .patch ("importlib.resources.files" ) as mock_files :
448+ mock_files .side_effect = Exception ("Failed to access resources" )
449+
450+ # Should not raise, but return empty string
451+ result = loader .get_present_binaries ()
452+
453+ assert result == ""
454+
352455
353456def test_importing_snowflake_connector_triggers_core_loader_load ():
354457 """Test that importing snowflake.connector triggers core_loader.load()."""
0 commit comments