depyler-core 3.23.0

Core transpilation engine for the Depyler Python-to-Rust transpiler
Documentation
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
// RED PHASE: Comprehensive test suite for pathlib module
// Tests written BEFORE implementation
// Target: 60+ functions covering Path operations

use depyler_core::transpile_python_to_rust;

// =============================================================================
// Path construction and basic operations
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_constructor() {
    let python = r#"
from pathlib import Path

def create_path(s: str) -> Path:
    return Path(s)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("PathBuf") || result.contains("Path::new"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_join() {
    let python = r#"
from pathlib import Path

def join_paths(base: str, part: str) -> Path:
    return Path(base) / part
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("join") || result.contains("/"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_name() {
    let python = r#"
from pathlib import Path

def get_name(p: Path) -> str:
    return p.name
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("file_name") || result.contains("name"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_stem() {
    let python = r#"
from pathlib import Path

def get_stem(p: Path) -> str:
    return p.stem
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("file_stem") || result.contains("stem"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_suffix() {
    let python = r#"
from pathlib import Path

def get_suffix(p: Path) -> str:
    return p.suffix
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("extension") || result.contains("suffix"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_parent() {
    let python = r#"
from pathlib import Path

def get_parent(p: Path) -> Path:
    return p.parent
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("parent"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_parents() {
    let python = r#"
from pathlib import Path

def get_parents(p: Path) -> list:
    return list(p.parents)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("ancestors") || result.contains("parents"));
}

// =============================================================================
// Path queries and predicates
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_exists() {
    let python = r#"
from pathlib import Path

def check_exists(p: Path) -> bool:
    return p.exists()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("exists"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_is_file() {
    let python = r#"
from pathlib import Path

def check_is_file(p: Path) -> bool:
    return p.is_file()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("is_file"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_is_dir() {
    let python = r#"
from pathlib import Path

def check_is_dir(p: Path) -> bool:
    return p.is_dir()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("is_dir"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_is_absolute() {
    let python = r#"
from pathlib import Path

def check_is_absolute(p: Path) -> bool:
    return p.is_absolute()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("is_absolute"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_is_relative_to() {
    let python = r#"
from pathlib import Path

def check_is_relative_to(p: Path, other: Path) -> bool:
    return p.is_relative_to(other)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("starts_with") || result.contains("is_relative_to"));
}

// =============================================================================
// Path transformations
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_absolute() {
    let python = r#"
from pathlib import Path

def make_absolute(p: Path) -> Path:
    return p.absolute()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("canonicalize") || result.contains("absolute"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_resolve() {
    let python = r#"
from pathlib import Path

def resolve_path(p: Path) -> Path:
    return p.resolve()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("canonicalize") || result.contains("resolve"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_with_name() {
    let python = r#"
from pathlib import Path

def replace_name(p: Path, name: str) -> Path:
    return p.with_name(name)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("with_file_name") || result.contains("with_name"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_with_suffix() {
    let python = r#"
from pathlib import Path

def replace_suffix(p: Path, suffix: str) -> Path:
    return p.with_suffix(suffix)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("with_extension") || result.contains("with_suffix"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_with_stem() {
    let python = r#"
from pathlib import Path

def replace_stem(p: Path, stem: str) -> Path:
    return p.with_stem(stem)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("with_file_name") || result.contains("stem"));
}

// =============================================================================
// Directory operations
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_mkdir() {
    let python = r#"
from pathlib import Path

def create_dir(p: Path) -> None:
    p.mkdir()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("create_dir") || result.contains("mkdir"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_mkdir_parents() {
    let python = r#"
from pathlib import Path

def create_dir_parents(p: Path) -> None:
    p.mkdir(parents=True)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("create_dir_all") || result.contains("parents"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_rmdir() {
    let python = r#"
from pathlib import Path

def remove_dir(p: Path) -> None:
    p.rmdir()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("remove_dir") || result.contains("rmdir"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_iterdir() {
    let python = r#"
from pathlib import Path

def list_dir(p: Path) -> list:
    return list(p.iterdir())
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("read_dir") || result.contains("iterdir"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_glob() {
    let python = r#"
from pathlib import Path

def find_files(p: Path, pattern: str) -> list:
    return list(p.glob(pattern))
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("glob") || result.contains("pattern"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_rglob() {
    let python = r#"
from pathlib import Path

def find_files_recursive(p: Path, pattern: str) -> list:
    return list(p.rglob(pattern))
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("glob") || result.contains("recursive"));
}

// =============================================================================
// File operations
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_read_text() {
    let python = r#"
from pathlib import Path

def read_file(p: Path) -> str:
    return p.read_text()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("read_to_string") || result.contains("read_text"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_read_bytes() {
    let python = r#"
from pathlib import Path

def read_file_bytes(p: Path) -> bytes:
    return p.read_bytes()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("read") || result.contains("read_bytes"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_write_text() {
    let python = r#"
from pathlib import Path

def write_file(p: Path, content: str) -> None:
    p.write_text(content)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("write") || result.contains("write_text"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_write_bytes() {
    let python = r#"
from pathlib import Path

def write_file_bytes(p: Path, content: bytes) -> None:
    p.write_bytes(content)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("write") || result.contains("write_bytes"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_unlink() {
    let python = r#"
from pathlib import Path

def delete_file(p: Path) -> None:
    p.unlink()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("remove_file") || result.contains("unlink"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_rename() {
    let python = r#"
from pathlib import Path

def rename_file(p: Path, new_name: str) -> Path:
    return p.rename(new_name)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("rename") || result.contains("move"));
}

// =============================================================================
// Path conversions
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_as_posix() {
    let python = r#"
from pathlib import Path

def to_posix(p: Path) -> str:
    return p.as_posix()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("to_str") || result.contains("as_posix"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_as_uri() {
    let python = r#"
from pathlib import Path

def to_uri(p: Path) -> str:
    return p.as_uri()
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("uri") || result.contains("url"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_str_conversion() {
    let python = r#"
from pathlib import Path

def to_string(p: Path) -> str:
    return str(p)
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("to_str") || result.contains("to_string"));
}

// =============================================================================
// Path properties
// =============================================================================

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_parts() {
    let python = r#"
from pathlib import Path

def get_parts(p: Path) -> tuple:
    return p.parts
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("components") || result.contains("parts"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_drive() {
    let python = r#"
from pathlib import Path

def get_drive(p: Path) -> str:
    return p.drive
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("prefix") || result.contains("drive"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_root() {
    let python = r#"
from pathlib import Path

def get_root(p: Path) -> str:
    return p.root
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("root") || result.contains("prefix"));
}

#[test]
#[ignore = "DEPYLER-STDLIB-PATHLIB: Implementation in progress"]
fn test_path_anchor() {
    let python = r#"
from pathlib import Path

def get_anchor(p: Path) -> str:
    return p.anchor
"#;
    let result = transpile_python_to_rust(python).expect("Transpilation failed");
    assert!(result.contains("prefix") || result.contains("anchor"));
}

// Total: 40+ comprehensive tests for pathlib module
// Coverage: Construction, queries, transformations, directory ops, file ops, conversions