-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
134 lines (109 loc) · 2.92 KB
/
Copy pathconftest.py
File metadata and controls
134 lines (109 loc) · 2.92 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
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
"""
pytest配置文件
定义全局的测试配置和fixture。
"""
import pytest
from hypothesis import settings
# 配置Hypothesis
settings.register_profile("default", max_examples=100, deadline=None)
settings.load_profile("default")
@pytest.fixture
def sample_code_element():
"""示例代码元素fixture"""
from src.codenexus.models.core import CodeElement, ElementType
return CodeElement(
name="TestClass",
type=ElementType.CLASS,
file_path="test.py",
line_number=1,
end_line_number=10,
complexity=5,
visibility="public",
docstring="A test class for demonstration"
)
@pytest.fixture
def sample_relationship():
"""示例关系fixture"""
from src.codenexus.models.core import Relationship, RelationType
return Relationship(
source_id="class1",
target_id="class2",
type=RelationType.INHERITS,
strength=1.0,
line_number=5,
context="class inheritance"
)
@pytest.fixture
def sample_code_graph():
"""示例代码图fixture"""
from src.codenexus.models.core import (
CodeGraph, GraphNode, GraphEdge, GraphMetadata,
CodeElement, Relationship, ElementType, RelationType
)
# 创建节点
element1 = CodeElement(
id="elem1",
name="ClassA",
type=ElementType.CLASS,
file_path="a.py",
line_number=1
)
element2 = CodeElement(
id="elem2",
name="ClassB",
type=ElementType.CLASS,
file_path="b.py",
line_number=1
)
node1 = GraphNode(id="node1", element=element1)
node2 = GraphNode(id="node2", element=element2)
# 创建边
relationship = Relationship(
id="rel1",
source_id="elem1",
target_id="elem2",
type=RelationType.INHERITS
)
edge = GraphEdge(
id="edge1",
relationship=relationship,
source_node_id="node1",
target_node_id="node2"
)
# 创建图
graph = CodeGraph()
graph.add_node(node1)
graph.add_node(node2)
graph.add_edge(edge)
graph.metadata = GraphMetadata(
project_name="test_project",
project_path="/test",
language="python"
)
return graph
@pytest.fixture
def temp_project_dir(tmp_path):
"""临时项目目录fixture"""
# 创建示例Python文件
(tmp_path / "main.py").write_text("""
class Calculator:
def add(self, a, b):
return a + b
def multiply(self, a, b):
return a * b
def main():
calc = Calculator()
result = calc.add(1, 2)
print(result)
""")
(tmp_path / "utils.py").write_text("""
from main import Calculator
class AdvancedCalculator(Calculator):
def power(self, base, exp):
return base ** exp
def factorial(self, n):
if n <= 1:
return 1
return n * self.factorial(n - 1)
""")
return tmp_path