199 """Create a minimal Option C project inside a real git repo.
201 Directory structure::
205 ├── debug_config.json
207 │ └── ARCHITECTURE.md
213 The repo has one initial commit so HEAD exists, and
214 ``user.name``/``user.email`` are configured.
217 pytest.skip(
"git binary not available on PATH")
219 root = tmp_path /
"project"
223 _git(root,
"init",
"--quiet",
"-b",
"main")
224 _git(root,
"config",
"user.email",
"test@example.com")
225 _git(root,
"config",
"user.name",
"Test")
226 _git(root,
"config",
"commit.gpgsign",
"false")
229 (root /
"src").mkdir()
230 (root /
"tests").mkdir()
231 (root /
"docs").mkdir()
232 (root /
"logs").mkdir()
233 (root /
"oc_diagnostics").mkdir()
237 "linter": {
"profile":
"compact"},
238 "git": {
"protected_branches": [
"main",
"master"]},
240 (root /
".octrc.json").write_text(
241 json.dumps(octrc, indent=2), encoding=
"utf-8",
247 "GIT": {
"level": 1,
"color":
"cyan"},
248 "TEST": {
"level": 1,
"color":
"white"},
251 (root /
"debug_config.json").write_text(
252 json.dumps(debug_cfg, indent=2), encoding=
"utf-8",
256 (root /
"docs" /
"ARCHITECTURE.md").write_text(
257 "# Architecture\n\nStub for testing.\n", encoding=
"utf-8",
261 (root /
"pyproject.toml").write_text(
262 '[project]\nname = "test_project"\n', encoding=
"utf-8",
266 _git(root,
"add",
"-A")
267 _git(root,
"commit",
"-m",
"initial: project structure",
"--quiet")
269 return root.resolve()
274 """Factory: write a compliant Python file and return its Path.
278 path = make_compliant_py("src/good.py")
280 def _factory(rel_path: str) -> Path:
281 content = _COMPLIANT_TEMPLATE.format(
284 full = temp_git_project / rel_path
285 full.parent.mkdir(parents=
True, exist_ok=
True)
286 full.write_text(content, encoding=
"utf-8")
290 module_name = full.stem
291 test_file = temp_git_project /
"tests" / f
"test_{module_name}.py"
292 if not test_file.exists():
293 test_file.write_text(
294 f
'"""Stub test for {module_name}."""\n\n'
295 f
'def test_{module_name}():\n pass\n',
305 """Factory: write a noncompliant Python file with a chosen violation.
309 path = make_noncompliant_py("src/bad.py", "missing_header")
311 Supported violations:
312 - ``"missing_header"``
313 - ``"missing_docstring"``
314 - ``"hardcoded_secret"``
318 "missing_header": _NONCOMPLIANT_MISSING_HEADER,
319 "missing_docstring": _NONCOMPLIANT_MISSING_DOCSTRING,
320 "hardcoded_secret": _NONCOMPLIANT_HARDCODED_SECRET,
321 "format_error": _NONCOMPLIANT_FORMAT_ERROR,
324 def _factory(rel_path: str, violation: str) -> Path:
325 if violation
not in templates:
327 f
"Unknown violation {violation!r}; "
328 f
"choose from: {', '.join(templates)}"
330 content = templates[violation]
331 full = temp_git_project / rel_path
332 full.parent.mkdir(parents=
True, exist_ok=
True)
333 full.write_text(content, encoding=
"utf-8")