-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
178 lines (139 loc) · 4.45 KB
/
conftest.py
File metadata and controls
178 lines (139 loc) · 4.45 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
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
"""
Pytest configuration and shared fixtures for Hug SCM Python helpers.
This module provides common test fixtures and configuration following
Google's Python testing best practices.
"""
import sys
from pathlib import Path
import pytest
# Import command mock framework from installed library
# These must be imported before pytest due to E402 rules
from command_mock.player import CommandMockPlayer
from command_mock.recorder import CommandMockRecorder
# Add parent directory to Python path for module imports
PYTHON_LIB_DIR = Path(__file__).parent.parent
sys.path.insert(0, str(PYTHON_LIB_DIR))
def pytest_addoption(parser):
"""Add custom command line options."""
parser.addoption(
"--regenerate-mocks",
action="store_true",
default=False,
help="Regenerate mock data from real command calls",
)
parser.addoption(
"--command-type",
default="git",
help="Command type for mocks (default: git). Examples: git, docker, npm",
)
@pytest.fixture(scope="session")
def command_type(request):
"""Get command type from CLI or test parameter."""
try:
return request.config.getoption("--command-type")
except ValueError:
# Default to git when option not provided
return "git"
@pytest.fixture(scope="session")
def regenerate_mocks(request):
"""Session-scoped fixture indicating if mocks should be regenerated."""
try:
return request.config.getoption("--regenerate-mocks")
except ValueError:
return False
@pytest.fixture
def command_mock(command_type, regenerate_mocks):
"""
Fixture providing command mock player or recorder.
Returns CommandMockRecorder if --regenerate-mocks is set,
otherwise CommandMockPlayer.
Points to LOCAL fixtures directory in this project, allowing hug-scm
to maintain its own test data while using the framework library.
"""
# CRITICAL: Point to LOCAL fixtures directory with hug-scm-specific mocks
local_fixtures_root = Path(__file__).parent / "fixtures"
if regenerate_mocks:
return CommandMockRecorder(command_type, fixtures_root=local_fixtures_root)
else:
return CommandMockPlayer(command_type, fixtures_root=local_fixtures_root)
@pytest.fixture
def sample_git_log_co_changes():
"""
Sample git log output for co-changes analysis.
Format: commit hash followed by file names.
"""
return """abc1234567890123456789012345678901234567
file_a.py
file_b.py
def4567890123456789012345678901234567890
file_a.py
file_c.py
1234567890abcdef1234567890abcdef12345678
file_a.py
file_b.py
file_c.py
fedcba0987654321fedcba0987654321fedcba09
file_b.py
file_c.py
00112233445566778899aabbccddeeff00112233
file_a.py
file_b.py
"""
@pytest.fixture
def sample_git_log_activity():
"""
Sample git log output for activity analysis.
Format: timestamp|author
"""
return """2024-11-17 09:30:15 -0500|Alice Smith
2024-11-17 10:45:22 -0500|Bob Johnson
2024-11-17 14:15:33 -0500|Alice Smith
2024-11-16 09:20:11 -0500|Charlie Brown
2024-11-16 15:30:45 -0500|Bob Johnson
2024-11-15 22:15:30 -0500|Alice Smith
2024-11-15 02:30:15 -0500|Bob Johnson
2024-11-13 10:00:00 -0500|Alice Smith
"""
@pytest.fixture
def sample_git_log_ownership_file():
"""
Sample git log output for file ownership analysis.
Format: hash|author|date
"""
return """abc1234|Alice Smith|2024-11-17 09:30:15 -0500
def5678|Bob Johnson|2024-11-10 14:20:30 -0500
ghi9012|Alice Smith|2024-11-09 11:15:45 -0500
jkl3456|Alice Smith|2024-11-01 16:30:22 -0500
mno7890|Charlie Brown|2024-10-15 09:45:10 -0500
pqr1234|Bob Johnson|2024-09-20 13:20:15 -0500
stu5678|Alice Smith|2024-08-10 10:30:45 -0500
"""
@pytest.fixture
def sample_git_log_ownership_author():
"""
Sample git log output for author expertise analysis.
Format: hash followed by file names, for specific author.
"""
return """abc1234567890123456789012345678901234567
src/auth/login.py
src/auth/session.py
def4567890123456789012345678901234567890
src/auth/login.py
tests/auth/test_login.py
ghi7890123456789012345678901234567890123
src/api/users.py
src/models/user.py
jkl0123456789012345678901234567890123456
src/auth/session.py
src/auth/middleware.py
"""
@pytest.fixture
def mock_git_log_minimal():
"""Minimal git log output for edge case testing."""
return """abc1234567890123456789012345678901234567
single_file.py
"""
@pytest.fixture
def empty_git_log():
"""Empty git log output for error case testing."""
return ""