forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_code.py
More file actions
38 lines (34 loc) · 1.09 KB
/
replace_code.py
File metadata and controls
38 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
with open("src/utils.test.ts", "r") as f:
content = f.read()
search = """ const spy = vi
.spyOn(fs, "readFileSync")
// biome-ignore lint/suspicious/noExplicitAny: forwarding to native signature
.mockImplementation((path: any, encoding?: any) => {
if (path === mappingPath) {
return `"5551234"`;
}
return original(path, encoding);
});"""
replace = """ const spy = vi
.spyOn(fs, "readFileSync")
.mockImplementation(
(
path: PathOrFileDescriptor,
encoding?: ObjectEncodingOptions | BufferEncoding | null,
) => {
if (path === mappingPath) {
return `"5551234"`;
}
return original(path, encoding as any);
},
);"""
if search in content:
new_content = content.replace(search, replace)
with open("src/utils.test.ts", "w") as f:
f.write(new_content)
print("Replaced successfully")
else:
print("Search string not found")
# print("Content around line 80:")
# print(content[2500:3000]) # approximate location