Skip to content

Commit e6d6db7

Browse files
committed
test: Add tests for the new root path exploration
1 parent e64d2c9 commit e6d6db7

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

tests/unit/sagemaker/test_studio.py

+58-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,71 @@
1212
# language governing permissions and limitations under the License.
1313
# language governing permissions and limitations under the License.
1414
from __future__ import absolute_import
15-
15+
import os
16+
from pathlib import Path
1617
from sagemaker._studio import (
1718
_append_project_tags,
1819
_find_config,
1920
_load_config,
2021
_parse_tags,
2122
)
2223

24+
def test_find_config_cross_platform(tmpdir):
25+
"""Test _find_config works correctly across different platforms."""
26+
# Create a completely separate directory for isolated tests
27+
import tempfile
28+
with tempfile.TemporaryDirectory() as isolated_root:
29+
# Setup test directory structure for positive tests
30+
config = tmpdir.join(".sagemaker-code-config")
31+
config.write('{"sagemakerProjectId": "proj-1234"}')
32+
33+
# Test 1: Direct parent directory
34+
working_dir = tmpdir.mkdir("sub")
35+
found_path = _find_config(working_dir)
36+
assert found_path == config
37+
38+
# Test 2: Deeply nested directories
39+
nested_dir = tmpdir.mkdir("deep").mkdir("nested").mkdir("path")
40+
found_path = _find_config(nested_dir)
41+
assert found_path == config
42+
43+
# Test 3: Start from root directory
44+
import os
45+
root_dir = os.path.abspath(os.sep)
46+
found_path = _find_config(root_dir)
47+
assert found_path is None
48+
49+
# Test 4: No config file in path - using truly isolated directory
50+
isolated_path = Path(isolated_root) / "nested" / "path"
51+
isolated_path.mkdir(parents=True)
52+
found_path = _find_config(isolated_path)
53+
assert found_path is None
54+
55+
def test_find_config_path_separators(tmpdir):
56+
"""Test _find_config handles different path separator styles.
57+
58+
Tests:
59+
1. Forward slashes
60+
2. Backslashes
61+
3. Mixed separators
62+
"""
63+
# Setup
64+
config = tmpdir.join(".sagemaker-code-config")
65+
config.write('{"sagemakerProjectId": "proj-1234"}')
66+
base_path = str(tmpdir)
67+
68+
# Test different path separator styles
69+
paths = [
70+
os.path.join(base_path, "dir1", "dir2"), # OS native
71+
"/".join([base_path, "dir1", "dir2"]), # Forward slashes
72+
"\\".join([base_path, "dir1", "dir2"]), # Backslashes
73+
base_path + "/dir1\\dir2" # Mixed
74+
]
75+
76+
for path in paths:
77+
os.makedirs(path, exist_ok=True)
78+
found_path = _find_config(path)
79+
assert found_path == config
2380

2481
def test_find_config(tmpdir):
2582
path = tmpdir.join(".sagemaker-code-config")

0 commit comments

Comments
 (0)