From e2e328bcf01fddf2227205677fde091d69a506f2 Mon Sep 17 00:00:00 2001 From: Julfried <51880314+Julfried@users.noreply.github.com> Date: Sat, 1 Feb 2025 10:54:53 +0100 Subject: [PATCH] Fix formatting style --- src/sagemaker/_studio.py | 6 ++++-- tests/unit/sagemaker/test_studio.py | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/sagemaker/_studio.py b/src/sagemaker/_studio.py index 6ea5c4c875..ce73de3179 100644 --- a/src/sagemaker/_studio.py +++ b/src/sagemaker/_studio.py @@ -65,8 +65,10 @@ def _find_config(working_dir=None): wd = Path(working_dir) if working_dir else Path.cwd() path = None - - root = Path(wd.anchor) # Properly get the root of the current working directory for both Windows and Unix-like systems + + root = Path( + wd.anchor + ) # Properly get the root of the current working directory for both Windows and Unix-like systems while path is None and wd != root: candidate = wd / STUDIO_PROJECT_CONFIG if Path.exists(candidate): diff --git a/tests/unit/sagemaker/test_studio.py b/tests/unit/sagemaker/test_studio.py index bc57e4917f..6a09e590a3 100644 --- a/tests/unit/sagemaker/test_studio.py +++ b/tests/unit/sagemaker/test_studio.py @@ -21,40 +21,44 @@ _parse_tags, ) + def test_find_config_cross_platform(tmpdir): """Test _find_config works correctly across different platforms.""" # Create a completely separate directory for isolated tests import tempfile + with tempfile.TemporaryDirectory() as isolated_root: # Setup test directory structure for positive tests config = tmpdir.join(".sagemaker-code-config") config.write('{"sagemakerProjectId": "proj-1234"}') - + # Test 1: Direct parent directory working_dir = tmpdir.mkdir("sub") found_path = _find_config(working_dir) assert found_path == config - + # Test 2: Deeply nested directories nested_dir = tmpdir.mkdir("deep").mkdir("nested").mkdir("path") found_path = _find_config(nested_dir) assert found_path == config - + # Test 3: Start from root directory import os + root_dir = os.path.abspath(os.sep) found_path = _find_config(root_dir) assert found_path is None - + # Test 4: No config file in path - using truly isolated directory isolated_path = Path(isolated_root) / "nested" / "path" isolated_path.mkdir(parents=True) found_path = _find_config(isolated_path) assert found_path is None + def test_find_config_path_separators(tmpdir): """Test _find_config handles different path separator styles. - + Tests: 1. Forward slashes 2. Backslashes @@ -64,20 +68,21 @@ def test_find_config_path_separators(tmpdir): config = tmpdir.join(".sagemaker-code-config") config.write('{"sagemakerProjectId": "proj-1234"}') base_path = str(tmpdir) - + # Test different path separator styles paths = [ os.path.join(base_path, "dir1", "dir2"), # OS native - "/".join([base_path, "dir1", "dir2"]), # Forward slashes - "\\".join([base_path, "dir1", "dir2"]), # Backslashes - base_path + "/dir1\\dir2" # Mixed + "/".join([base_path, "dir1", "dir2"]), # Forward slashes + "\\".join([base_path, "dir1", "dir2"]), # Backslashes + base_path + "/dir1\\dir2", # Mixed ] - + for path in paths: os.makedirs(path, exist_ok=True) found_path = _find_config(path) assert found_path == config + def test_find_config(tmpdir): path = tmpdir.join(".sagemaker-code-config") path.write('{"sagemakerProjectId": "proj-1234"}')