Skip to content

Commit 54e1743

Browse files
authored
Merge pull request #376 from ma10/yaml2rst-test-20250724
yaml2rst: refactoring and adding tests
2 parents 2dcd09d + 58ff93a commit 54e1743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+16022
-369
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: Set up Python
6666
uses: actions/setup-python@v4
6767
with:
68-
python-version: '3.9.x'
68+
python-version: '3.13.x'
6969
- name: Install the Latest pip
7070
run: python -m pip install --upgrade pip
7171
- name: install ja_JP.UTF-8 locale

requirements-dev.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
# Testing
1+
# Testing framework
22
pytest==8.0.0
33
pytest-cov==4.1.0
44

5+
# Code quality tools
6+
black==24.2.0
7+
isort==5.13.2
8+
flake8>=7.0.0
9+
510
# Type checking
611
mypy==1.9.0
712
types-PyYAML==6.0.12.12
813

9-
# Code formatting
10-
black==24.2.0
11-
isort==5.13.2
12-
13-
# YAML parsing (needed for tests)
14-
PyYAML==6.0.1
14+
# Performance monitoring
15+
psutil>=7.0.0

requirements.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
# Documentation build dependencies
12
wheel
23
sphinx ~= 7.0
34
sphinx_rtd_theme ~= 3.0
45
sphinxcontrib-trimblank
5-
jsonschema < 4.18.0
66
sphinx-lint
7+
8+
# Shared production dependencies
9+
jsonschema < 4.18.0
710
pytz
11+
12+
# Local packages
813
tools/lib/freee_a11y_gl
914
tools/scripts/yaml2rst

tools/lib/freee_a11y_gl/pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ dependencies = [
1616
"pydantic>=2.7.0"
1717
]
1818

19+
[project.optional-dependencies]
20+
dev = [
21+
# Project-specific dev dependencies only
22+
# Common dev tools (pytest, black, mypy, etc.) are managed at root level
23+
# Install with: pip install -r requirements-dev.txt
24+
]
25+
1926
[tool.setuptools]
2027
package-dir = { "" = "src" }
2128
include-package-data = true

tools/scripts/yaml2rst/.coveragerc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[run]
2+
source = yaml2rst
3+
omit =
4+
*/tests/*
5+
*/test_*
6+
*/__pycache__/*
7+
8+
[report]
9+
exclude_lines =
10+
pragma: no cover
11+
def __repr__
12+
raise AssertionError
13+
raise NotImplementedError
14+
if __name__ == .__main__.:
15+
16+
[html]
17+
directory = htmlcov

tools/scripts/yaml2rst/README.md

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
# yaml2rst
2+
3+
A Python tool for converting YAML files into reStructuredText (RST) files for the freee a11y-guidelines project.
4+
5+
## Overview
6+
7+
yaml2rst is a specialized content generation tool that processes YAML data files and converts them into properly formatted RST files for inclusion in the a11y-guidelines documentation. It supports multiple content types including guidelines, FAQs, checks, and reference materials, with full internationalization support.
8+
9+
### Key Features
10+
11+
- **Multi-language support**: Generate content for Japanese and English
12+
- **Template-based generation**: Flexible Jinja2 template system
13+
- **Modular architecture**: Clean mixin-based design for extensibility
14+
- **Comprehensive testing**: 99.56% test coverage with 404+ tests
15+
- **Performance optimized**: Efficient processing of large datasets
16+
- **Type safety**: Full type hints and validation
17+
18+
## Installation
19+
20+
### Prerequisites
21+
22+
- Python 3.8 or higher
23+
- pip package manager
24+
25+
### Dependencies
26+
27+
The tool requires the following Python packages:
28+
29+
```bash
30+
pip install jinja2 freee_a11y_gl>=0.1.0
31+
```
32+
33+
### Development Dependencies
34+
35+
For development and testing:
36+
37+
```bash
38+
pip install pytest pytest-cov pytest-mock psutil flake8
39+
```
40+
41+
### Installation from Source
42+
43+
1. Clone the repository:
44+
```bash
45+
git clone <repository-url>
46+
cd a11y-guidelines/tools/scripts/yaml2rst
47+
```
48+
49+
2. Install in development mode:
50+
```bash
51+
pip install -e .
52+
```
53+
54+
## Basic Usage
55+
56+
### Command Line Interface
57+
58+
The primary way to use yaml2rst is through the command line:
59+
60+
```bash
61+
# Generate all content for Japanese
62+
yaml2rst --lang ja --basedir /path/to/a11y-guidelines
63+
64+
# Generate all content for English
65+
yaml2rst --lang en --basedir /path/to/a11y-guidelines
66+
67+
# Generate specific files only
68+
yaml2rst --lang ja --basedir /path/to/a11y-guidelines category.rst faq_index.rst
69+
70+
# Use custom template directory
71+
yaml2rst --lang ja --basedir /path/to/a11y-guidelines --template-dir /custom/templates
72+
73+
# Export default templates for customization
74+
yaml2rst --export-templates
75+
76+
# Export templates to custom directory
77+
yaml2rst --export-templates --template-dir /custom/templates
78+
```
79+
80+
### Available Options
81+
82+
- `--lang, -l`: Target language (ja/en)
83+
- `--basedir, -b`: Base directory of the a11y-guidelines project
84+
- `--template-dir, -t`: Custom template directory path
85+
- `--export-templates`: Export built-in templates and exit
86+
- `files`: Optional list of specific files to generate (positional arguments)
87+
- `--help`: Show detailed help information
88+
89+
### Template Customization
90+
91+
yaml2rst supports template customization through a priority-based system:
92+
93+
```bash
94+
# Export default templates for customization
95+
yaml2rst --export-templates
96+
97+
# Export to custom directory
98+
yaml2rst --export-templates --template-dir /path/to/custom/templates
99+
100+
# Use custom templates during generation
101+
yaml2rst --lang ja --template-dir /path/to/custom/templates
102+
```
103+
104+
**Template Resolution Priority:**
105+
1. Custom templates (specified via `--template-dir`)
106+
2. User templates (`~/.config/freee_a11y_gl/templates/`)
107+
3. Built-in templates (default)
108+
109+
For detailed template customization guide, see [TEMPLATE_CUSTOMIZATION.md](docs/TEMPLATE_CUSTOMIZATION.md).
110+
111+
### Supported Content Types
112+
113+
yaml2rst can generate the following types of content:
114+
115+
- **Guidelines**: Category pages with accessibility guidelines
116+
- **Checks**: Checklist items and examples
117+
- **FAQ**: Frequently asked questions and tag pages
118+
- **References**: WCAG mappings, priority information, and tool references
119+
- **Build files**: Makefiles for documentation building
120+
121+
## Architecture Overview
122+
123+
yaml2rst follows a modular, mixin-based architecture designed for maintainability and extensibility.
124+
125+
### Core Components
126+
127+
- **ContentGeneratorBase**: Foundation class combining all mixins
128+
- **Mixins**: Reusable functionality (RelationshipMixin, ValidationMixin, UtilityMixin)
129+
- **Content Generators**: Specialized classes for different content types
130+
- **FileGenerator**: Orchestrates the generation process
131+
- **TemplateManager**: Handles Jinja2 template loading and rendering
132+
133+
### Design Patterns
134+
135+
- **Mixin Pattern**: Shared functionality across generators
136+
- **Template Method**: Consistent generation workflow
137+
- **Singleton**: Shared resource management
138+
- **Factory**: Dynamic generator instantiation
139+
140+
For detailed architectural information, see [ARCHITECTURE.md](docs/ARCHITECTURE.md).
141+
142+
## Development
143+
144+
### Running Tests
145+
146+
Use the provided test runner for comprehensive testing:
147+
148+
```bash
149+
# Run all tests
150+
python run_tests.py
151+
152+
# Run with coverage reporting
153+
python run_tests.py --coverage
154+
155+
# Run specific test categories
156+
python run_tests.py --type unit
157+
python run_tests.py --type integration
158+
python run_tests.py --type functional
159+
python run_tests.py --type performance
160+
161+
# Run in fast mode (skip slow tests)
162+
python run_tests.py --fast
163+
164+
# Run with verbose output
165+
python run_tests.py --verbose
166+
```
167+
168+
### Test Structure
169+
170+
The test suite is organized into three main categories:
171+
172+
- **Unit tests** (`tests/unit/`): Individual component testing
173+
- **Integration tests** (`tests/integration/`): Component interaction testing
174+
- **Functional tests** (`tests/functional/`): End-to-end workflow testing
175+
176+
Performance tests are integrated within these categories using pytest markers.
177+
178+
### Code Quality
179+
180+
The project maintains high code quality standards:
181+
182+
- **Test Coverage**: 99.56% (target: >90%)
183+
- **Type Safety**: Full type hints throughout codebase
184+
- **Documentation**: Comprehensive docstrings and comments
185+
- **Code Style**: PEP 8 compliant with automated checking
186+
187+
### Contributing
188+
189+
1. **Fork the repository** and create a feature branch
190+
2. **Write tests** for new functionality (TDD approach recommended)
191+
3. **Ensure all tests pass** with `python run_tests.py`
192+
4. **Maintain or improve** test coverage percentage
193+
5. **Follow coding standards** and add appropriate documentation
194+
6. **Submit a pull request** with clear description of changes
195+
196+
### Development Workflow
197+
198+
1. **Set up development environment**:
199+
```bash
200+
pip install -e .
201+
pip install pytest pytest-cov pytest-mock psutil flake8
202+
```
203+
204+
2. **Run tests during development**:
205+
```bash
206+
python run_tests.py --fast --verbose
207+
```
208+
209+
3. **Check coverage before committing**:
210+
```bash
211+
python run_tests.py --coverage
212+
```
213+
214+
4. **Validate code style**:
215+
```bash
216+
flake8 src/ tests/
217+
```
218+
219+
## Project Structure
220+
221+
```
222+
yaml2rst/
223+
├── src/yaml2rst/ # Main source code
224+
│ ├── generators/ # Content generators
225+
│ │ ├── mixins.py # Shared mixin classes
226+
│ │ ├── content_generator_base.py
227+
│ │ └── content_generators/ # Specific generators
228+
│ ├── config.py # Configuration management
229+
│ ├── initializer.py # Setup and initialization
230+
│ ├── template_manager.py # Template handling
231+
│ └── yaml2rst.py # Main entry point
232+
├── tests/ # Comprehensive test suite
233+
│ ├── unit/ # Unit tests
234+
│ ├── integration/ # Integration tests
235+
│ └── functional/ # Functional tests
236+
├── run_tests.py # Test runner script
237+
├── pyproject.toml # Project configuration
238+
└── README.md # This file
239+
```
240+
241+
## Troubleshooting
242+
243+
### Common Issues
244+
245+
**Import Errors**:
246+
- Ensure all dependencies are installed: `pip install -e .`
247+
- Verify Python path includes the src directory
248+
249+
**Template Not Found**:
250+
- Check that template files exist in the expected location
251+
- Verify basedir parameter points to correct a11y-guidelines directory
252+
253+
**Permission Errors**:
254+
- Ensure write permissions for output directories
255+
- Check file system permissions for template and data directories
256+
257+
**Memory Issues**:
258+
- For large datasets, consider processing in smaller batches
259+
- Monitor memory usage with performance tests
260+
261+
### Debug Mode
262+
263+
For detailed troubleshooting information:
264+
265+
```bash
266+
# Run with maximum verbosity
267+
python run_tests.py --verbose
268+
269+
# Check specific test failures
270+
pytest tests/unit/test_specific_component.py -v
271+
272+
# Profile performance issues
273+
python run_tests.py --type performance --verbose
274+
```
275+
276+
### Getting Help
277+
278+
1. **Check the documentation**: Review [ARCHITECTURE.md](docs/ARCHITECTURE.md) and [API_REFERENCE.md](docs/API_REFERENCE.md)
279+
2. **Run the test suite**: Often reveals configuration or environment issues
280+
3. **Check logs**: Enable verbose logging for detailed execution information
281+
4. **Review examples**: Look at existing generators for implementation patterns
282+
283+
## Performance
284+
285+
yaml2rst is optimized for processing large datasets efficiently:
286+
287+
- **Benchmarks**: <0.1s per item for typical content generation
288+
- **Memory usage**: <100MB increase for 1000 items processing
289+
- **Scalability**: Linear scaling with dataset size
290+
- **Concurrency**: Thread-safe design for parallel processing
291+
292+
## License
293+
294+
This project is part of the freee a11y-guidelines project. See the main project repository for license information.
295+
296+
## Authors
297+
298+
- **Masafumi NAKANE** - *Initial work and maintenance* - [email protected]
299+
300+
## Acknowledgments
301+
302+
- Built on the freee_a11y_gl library
303+
- Uses Jinja2 templating engine
304+
- Inspired by modern Python development practices
305+
- Part of the broader freee accessibility initiative
306+
307+
---
308+
309+
For detailed technical documentation, see:
310+
- [ARCHITECTURE.md](docs/ARCHITECTURE.md) - Detailed architecture and design patterns
311+
- [API_REFERENCE.md](docs/API_REFERENCE.md) - Complete API documentation
312+
- [tests/README.md](tests/README.md) - Testing guide and best practices

0 commit comments

Comments
 (0)