Skip to content

Commit f7eb828

Browse files
committed
pr review: Apply suggestions
1 parent 457d698 commit f7eb828

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

fluent.runtime/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def assertFileIs(self, filename, expect_contents):
3131
"""
3232
if expect_contents is None:
3333
self.assertFalse(os.path.isfile(filename),
34-
"Expected " + filename + " to not exist.")
34+
f"Expected {filename} to not exist.")
3535
else:
3636
self.assertTrue(os.path.isfile(filename),
37-
"Expected " + filename + " to exist.")
37+
f"Expected {filename} to exist.")
3838
self.assertEqual(codecs.open(filename, "r", "utf-8").read(),
3939
expect_contents)

fluent.runtime/tests/utils.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,12 @@ def dedent_ftl(text):
1818
# Supports only relative paths
1919
# Needed in test_falllback.py because it uses dict + string compare to make a virtual file structure
2020
def _normalize_path(path):
21+
"""Note: Does not support absolute paths or paths that
22+
contain '.' or '..' parts."""
2123
path = PurePath(path)
22-
if path.is_absolute():
23-
raise ValueError("Absolute paths are not supported in file simulation yet. ("
24-
+ str(path) + ")")
25-
if "." not in path.parts and ".." not in path.parts:
26-
return "/".join(PurePath(path).parts)
27-
else:
28-
res_parts = []
29-
length = len(path.parts)
30-
i = 0
31-
while i < length:
32-
if path.parts[i] == ".":
33-
i += 1
34-
elif i < length - 1 and path.parts[i+1] == "..":
35-
i += 2
36-
else:
37-
res_parts.append(path.parts[i])
38-
i += 1
39-
return "/".join(res_parts)
24+
if path.is_absolute() or "." in path.parts or ".." in path.parts:
25+
raise ValueError(f"Unsupported path: {path}")
26+
return "/".join(path.parts)
4027

4128

4229
def patch_files(files: dict):

0 commit comments

Comments
 (0)