Option C Tools
Loading...
Searching...
No Matches
conftest.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_formatter/conftest.py
4
5"""
6Shared fixtures for formatter tests.
7
8Purpose
9-------
10Provide reusable test fixtures for formatter unit and integration tests.
11
12Responsibilities
13----------------
14- Create temporary Option C projects with required directory structure.
15- Provide FormatterContext for testing.
16- Copy test fixture files into temporary project.
17- Clean up after tests.
18
19Diagnostics
20-----------
21Domain: TESTS.FORMATTER
22Levels:
23 L2 — test lifecycle and setup
24 L3 — fixture creation and teardown
25 L4 — file operations and structure verification
26
27Contracts
28---------
29- temp_project_root fixture provides a clean, isolated test project.
30- All fixture files are available in the temporary project.
31- FormatterContext is properly configured for the temporary project.
32"""
33
34import pytest
35from pathlib import Path
36from dataclasses import dataclass
37
38from oct.formatter.oct_format import FormatterContext
39
40
41@pytest.fixture
42def temp_project_root(tmp_path: Path) -> Path:
43 """
44 Create a temporary Option C project root with required directory structure.
45
46 Returns the project root path. All required directories are created.
47 """
48 root = tmp_path / "test-project"
49 root.mkdir()
50
51 # Create required directories
52 (root / "docs").mkdir()
53 (root / "tests").mkdir()
54 (root / "oc_diagnostics").mkdir()
55 (root / "logs").mkdir()
56
57 return root
58
59
60@pytest.fixture
61def formatter_ctx(temp_project_root: Path) -> FormatterContext:
62 """
63 Return a FormatterContext configured for the temporary test project.
64
65 Context is in dry-run mode (not fix mode) by default.
66 """
67 return FormatterContext(
68 project_root=temp_project_root,
69 project_name=temp_project_root.name,
70 diagnostics_dir=temp_project_root / "oc_diagnostics",
71 tests_dir=temp_project_root / "tests",
72 docs_dir=temp_project_root / "docs",
73 fix_mode=False,
74 dry_run_mode=True,
75 json_mode=False,
76 verbose=False,
77 )
78
79
80@pytest.fixture
81def formatter_ctx_fix(temp_project_root: Path) -> FormatterContext:
82 """
83 Return a FormatterContext in fix mode for actual file modifications.
84 """
85 return FormatterContext(
86 project_root=temp_project_root,
87 project_name=temp_project_root.name,
88 diagnostics_dir=temp_project_root / "oc_diagnostics",
89 tests_dir=temp_project_root / "tests",
90 docs_dir=temp_project_root / "docs",
91 fix_mode=True,
92 dry_run_mode=False,
93 json_mode=False,
94 verbose=False,
95 )
FormatterContext formatter_ctx(Path temp_project_root)
Definition conftest.py:61
FormatterContext formatter_ctx_fix(Path temp_project_root)
Definition conftest.py:81
Path temp_project_root(Path tmp_path)
Definition conftest.py:42