@@ -432,30 +432,38 @@ def test_set_tracking_uri(mlflow_mock):
432
432
@mock .patch ("lightning.pytorch.loggers.mlflow._get_resolve_tags" , Mock ())
433
433
def test_mlflow_logger_save_dir_file_uri_handling (mlflow_mock ):
434
434
"""Test that save_dir correctly handles file URIs, especially on Windows."""
435
- # Test Unix-style absolute file URI
436
- logger = MLFlowLogger (tracking_uri = "file:///home/user/mlruns" )
437
- expected_unix = "/home/user/mlruns"
438
- assert logger .save_dir == expected_unix
439
-
440
- # Test Windows-style absolute file URI
441
- logger_win = MLFlowLogger (tracking_uri = "file:///C:/Dev/example/mlruns" )
442
- # On Windows, url2pathname converts file:///C:/path to C:\path
443
- # On Unix, it converts to /C:/path, but we test the actual behavior
444
435
import platform
445
436
437
+ # Test proper Windows-style absolute file URI (the main fix)
438
+ logger_win = MLFlowLogger (tracking_uri = "file:///C:/Dev/example/mlruns" )
439
+ result_win = logger_win .save_dir
446
440
expected_win = "C:\\ Dev\\ example\\ mlruns" if platform .system () == "Windows" else "/C:/Dev/example/mlruns"
447
- assert logger_win . save_dir == expected_win
441
+ assert result_win == expected_win
448
442
449
- # Test relative file URI
443
+ # Test proper Unix-style absolute file URI
444
+ logger_unix = MLFlowLogger (tracking_uri = "file:///home/user/mlruns" )
445
+ result_unix = logger_unix .save_dir
446
+ expected_unix = "\\ home\\ user\\ mlruns" if platform .system () == "Windows" else "/home/user/mlruns"
447
+ assert result_unix == expected_unix
448
+
449
+ # Test proper file URI with special characters and spaces
450
+ logger_special = MLFlowLogger (tracking_uri = "file:///path/with%20spaces/mlruns" )
451
+ result_special = logger_special .save_dir
452
+ expected_special = "\\ path\\ with spaces\\ mlruns" if platform .system () == "Windows" else "/path/with spaces/mlruns"
453
+ assert result_special == expected_special
454
+
455
+ # Test legacy format used by constructor (file:/path - should return as-is)
456
+ logger_legacy = MLFlowLogger (tracking_uri = "file:/tmp/mlruns" )
457
+ result_legacy = logger_legacy .save_dir
458
+ expected_legacy = "/tmp/mlruns"
459
+ assert result_legacy == expected_legacy
460
+
461
+ # Test legacy relative format
450
462
logger_rel = MLFlowLogger (tracking_uri = "file:./mlruns" )
463
+ result_rel = logger_rel .save_dir
451
464
expected_rel = "./mlruns"
452
- assert logger_rel . save_dir == expected_rel
465
+ assert result_rel == expected_rel
453
466
454
467
# Test non-file URI (should return None)
455
468
logger_http = MLFlowLogger (tracking_uri = "http://localhost:8080" )
456
469
assert logger_http .save_dir is None
457
-
458
- # Test file URI with special characters and spaces
459
- logger_special = MLFlowLogger (tracking_uri = "file:///path/with%20spaces/mlruns" )
460
- expected_special = "/path/with spaces/mlruns"
461
- assert logger_special .save_dir == expected_special
0 commit comments