Skip to content

Commit cfc602b

Browse files
committed
almost there
1 parent 4ab32b9 commit cfc602b

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

codeflash/code_utils/edit_generated_tests.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ def __init__(
102102
module: cst.Module,
103103
test: GeneratedTests,
104104
tests_root: Path,
105-
rel_tests_root: Path,
106105
original_runtimes: dict[InvocationId, list[int]],
107106
optimized_runtimes: dict[InvocationId, list[int]],
108107
) -> None:
109108
super().__init__()
110109
self.test = test
111110
self.context_stack: list[str] = []
112111
self.tests_root = tests_root
113-
self.rel_tests_root = rel_tests_root
114112
self.module = module
115113
self.cfo_locs: list[int] = []
116114
self.cfo_idx_loc_to_look_at: int = -1
@@ -163,8 +161,8 @@ def leave_SimpleStatementLine(
163161
)
164162
rel_path = (
165163
Path(invocation_id.test_module_path.replace(".", os.sep))
166-
.with_suffix(".py")
167-
.relative_to(self.rel_tests_root)
164+
.with_suffix(".py").resolve()
165+
.relative_to(self.tests_root)
168166
)
169167
if (
170168
qualified_name == ".".join(self.context_stack)
@@ -186,8 +184,8 @@ def leave_SimpleStatementLine(
186184
)
187185
rel_path = (
188186
Path(invocation_id.test_module_path.replace(".", os.sep))
189-
.with_suffix(".py")
190-
.relative_to(self.rel_tests_root)
187+
.with_suffix(".py").resolve()
188+
.relative_to(self.tests_root)
191189
)
192190
if (
193191
qualified_name == ".".join(self.context_stack)
@@ -241,7 +239,6 @@ def add_runtime_comments_to_generated_tests(
241239
"""Add runtime performance comments to function calls in generated tests."""
242240
tests_root = test_cfg.tests_root
243241
module_root = test_cfg.project_root_path
244-
rel_tests_root = tests_root.relative_to(module_root)
245242

246243
# Process each generated test
247244
modified_tests = []
@@ -250,9 +247,9 @@ def add_runtime_comments_to_generated_tests(
250247
# Parse the test source code
251248
tree = cst.parse_module(test.generated_original_test_source)
252249
# Transform the tree to add runtime comments
253-
# qualified_name: str, module: cst.Module, test: GeneratedTests, tests_root: Path, rel_tests_root: Path
250+
# qualified_name: str, module: cst.Module, test: GeneratedTests, tests_root: Path
254251
transformer = RuntimeCommentTransformer(
255-
qualified_name, tree, test, tests_root, rel_tests_root, original_runtimes, optimized_runtimes
252+
qualified_name, tree, test, tests_root, original_runtimes, optimized_runtimes
256253
)
257254
modified_tree = tree.visit(transformer)
258255

codeflash/result/create_pr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def existing_tests_source_for(
4343
headers = ["Test File::Test Function", "Original ⏱️", "Optimized ⏱️", "Speedup"]
4444
tests_root = test_cfg.tests_root
4545
module_root = test_cfg.project_root_path
46-
rel_tests_root = tests_root.relative_to(module_root)
4746
original_tests_to_runtimes: dict[Path, dict[str, int]] = {}
4847
optimized_tests_to_runtimes: dict[Path, dict[str, int]] = {}
4948
non_generated_tests = set()
@@ -53,7 +52,7 @@ def existing_tests_source_for(
5352
all_invocation_ids = original_runtimes_all.keys() | optimized_runtimes_all.keys()
5453
for invocation_id in all_invocation_ids:
5554
rel_path = (
56-
Path(invocation_id.test_module_path.replace(".", os.sep)).with_suffix(".py").relative_to(rel_tests_root)
55+
Path(invocation_id.test_module_path.replace(".", os.sep)).with_suffix(".py").resolve().relative_to(tests_root)
5756
)
5857
if rel_path not in non_generated_tests:
5958
continue

0 commit comments

Comments
 (0)