MCPcopy Create free account
hub / github.com/TtTRz/graphify-rs / extract_sample_python_file

Function extract_sample_python_file

tests/integration/test_python_compat.rs:5–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4#[test]
5fn extract_sample_python_file() {
6 let source = br#"
7import os
8from pathlib import Path
9
10class FileManager:
11 def __init__(self, root):
12 self.root = root
13
14 def list_files(self):
15 return os.listdir(self.root)
16
17def process(path):
18 fm = FileManager(path)
19 return fm.list_files()
20"#;
21
22 let dir = tempfile::tempdir().unwrap();
23 let py_file = dir.path().join("sample.py");
24 std::fs::write(&py_file, source).unwrap();
25
26 let result = graphify_extract::extract(&[py_file]);
27
28 assert!(
29 result.nodes.len() >= 4,
30 "should have file + class + 2 functions, got {} nodes: {:?}",
31 result.nodes.len(),
32 result.nodes.iter().map(|n| &n.label).collect::<Vec<_>>()
33 );
34
35 assert!(
36 result.nodes.iter().any(|n| n.label == "FileManager"),
37 "should extract FileManager class, got: {:?}",
38 result.nodes.iter().map(|n| &n.label).collect::<Vec<_>>()
39 );
40
41 assert!(
42 result.nodes.iter().any(|n| n.label.contains("list_files")),
43 "should extract list_files method, got: {:?}",
44 result.nodes.iter().map(|n| &n.label).collect::<Vec<_>>()
45 );
46
47 assert!(
48 result
49 .edges
50 .iter()
51 .any(|e| e.relation == "imports" || e.relation == "imports_from"),
52 "should extract imports, got relations: {:?}",
53 result.edges.iter().map(|e| &e.relation).collect::<Vec<_>>()
54 );
55
56 assert!(
57 result
58 .edges
59 .iter()
60 .any(|e| e.relation == "contains" || e.relation == "defines"),
61 "should have structural edges (contains/defines), got relations: {:?}",
62 result.edges.iter().map(|e| &e.relation).collect::<Vec<_>>()

Callers

nothing calls this directly

Calls 1

extractFunction · 0.85

Tested by

no test coverage detected