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