Skip to content

Commit 2dcd09d

Browse files
authored
Merge pull request #375 from ma10/lib-tests-20250703
Refine code and add tests for freee_a11y_gl, tests need closer reviews
2 parents 3e26ec1 + 63a199e commit 2dcd09d

Some content is hidden

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

44 files changed

+8803
-259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ incfiles.mk
88
__pycache__/
99
*:Zone.Identifier
1010
*.egg-info/
11+
.coverage

requirements-dev.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Testing
2+
pytest==8.0.0
3+
pytest-cov==4.1.0
4+
5+
# Type checking
6+
mypy==1.9.0
7+
types-PyYAML==6.0.12.12
8+
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

tools/lib/freee_a11y_gl/conftest.py

Lines changed: 449 additions & 0 deletions
Large diffs are not rendered by default.

tools/lib/freee_a11y_gl/pyproject.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "freee_a11y_gl"
7-
version = "0.2.0"
7+
version = "0.2.2"
88
description = "A module to process a11y guidelines data"
99
authors = [
1010
{name = "Masafumi NAKANE", email = "[email protected]"}
1111
]
12-
requires-python = ">=3.8"
12+
requires-python = ">=3.9"
1313
dependencies = [
1414
"pyyaml>=6.0",
1515
"gitpython>=3.1.43",
16-
"pydantic>=2.7.0",
17-
"importlib_resources>=1.3.0; python_version<'3.9'"
16+
"pydantic>=2.7.0"
1817
]
1918

2019
[tool.setuptools]
@@ -23,3 +22,19 @@ include-package-data = true
2322

2423
[tool.setuptools.package-data]
2524
freee_a11y_gl = ["data/*.yaml"]
25+
26+
[tool.pytest.ini_options]
27+
testpaths = ["tests"]
28+
python_files = ["test_*.py"]
29+
python_classes = ["Test*"]
30+
python_functions = ["test_*"]
31+
addopts = [
32+
"-v",
33+
"--tb=short",
34+
"--strict-markers",
35+
"--disable-warnings",
36+
]
37+
markers = [
38+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
39+
"integration: marks tests as integration tests",
40+
]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
"""Test runner script for freee_a11y_gl tests."""
3+
4+
import subprocess
5+
import sys
6+
7+
8+
def run_tests():
9+
"""Run all tests and provide a summary."""
10+
11+
test_suites = [
12+
("Core Config Tests", "tests/core/test_config.py"),
13+
("Core Utils Tests", "tests/core/test_utils.py"),
14+
("Base Model Tests", "tests/models/test_base.py"),
15+
("Check Model Tests", "tests/models/test_check.py"),
16+
("FAQ Article Tests", "tests/models/test_faq_article.py"),
17+
("Guideline Tests", "tests/models/test_guideline.py"),
18+
("Info Reference Tests", "tests/models/test_info_ref.py"),
19+
("FAQ Tag Tests", "tests/models/faq/test_tag.py"),
20+
("RelationshipManager Tests", "tests/managers/test_relationship_manager.py"),
21+
("YAML Processor Tests", "tests/yaml_processor/test_process_yaml.py"),
22+
("RST Processor Tests", "tests/yaml_processor/test_rst_processor.py"),
23+
]
24+
25+
results = []
26+
27+
for name, test_path in test_suites:
28+
print(f"\n{'='*60}")
29+
print(f"Running {name}")
30+
print('='*60)
31+
32+
try:
33+
result = subprocess.run(
34+
[sys.executable, "-m", "pytest", test_path, "-v"],
35+
capture_output=True,
36+
text=True,
37+
cwd="/home/max/work/a11y-guidelines/tools/lib/freee_a11y_gl"
38+
)
39+
40+
if result.returncode == 0:
41+
print(f"✅ {name}: PASSED")
42+
results.append((name, "PASSED", ""))
43+
else:
44+
print(f"❌ {name}: FAILED")
45+
results.append((name, "FAILED", result.stdout + result.stderr))
46+
47+
except Exception as e:
48+
print(f"💥 {name}: ERROR - {e}")
49+
results.append((name, "ERROR", str(e)))
50+
51+
# Summary
52+
print(f"\n{'='*60}")
53+
print("TEST SUMMARY")
54+
print('='*60)
55+
56+
passed = sum(1 for _, status, _ in results if status == "PASSED")
57+
failed = sum(1 for _, status, _ in results if status == "FAILED")
58+
errors = sum(1 for _, status, _ in results if status == "ERROR")
59+
60+
for name, status, output in results:
61+
icon = "✅" if status == "PASSED" else "❌" if status == "FAILED" else "💥"
62+
print(f"{icon} {name}: {status}")
63+
if status != "PASSED" and output:
64+
print(f" {output[:200]}...")
65+
66+
print(f"\nTotal: {len(results)} test suites")
67+
print(f"Passed: {passed}")
68+
print(f"Failed: {failed}")
69+
print(f"Errors: {errors}")
70+
71+
return failed + errors == 0
72+
73+
74+
if __name__ == "__main__":
75+
success = run_tests()
76+
sys.exit(0 if success else 1)

tools/lib/freee_a11y_gl/src/freee_a11y_gl/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from .relationship_manager import RelationshipManager
99

1010
# Constants and utilities
11-
from .constants import *
1211
from .source import get_src_path
1312
from .initializer import setup_instances
1413
from .info_utils import get_info_links
@@ -24,9 +23,6 @@
2423
'WcagSc', 'InfoRef', 'AxeRule', 'CheckTool',
2524
# Managers
2625
'RelationshipManager',
27-
# Constants
28-
'PLATFORM_NAMES', 'SEVERITY_TAGS', 'CHECK_TARGETS',
29-
'IMPLEMENTATION_TARGETS',
3026
# Utils
3127
'get_src_path', 'setup_instances', 'get_info_links',
3228
'get_version_info',

tools/lib/freee_a11y_gl/src/freee_a11y_gl/config.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ def get_platform_name(cls, platform: str, lang: Optional[LanguageCode] = None) -
211211
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
212212
return settings.message_catalog.get_platform_name(platform, effective_lang)
213213

214+
@classmethod
215+
def get_implementation_target_name(cls, target: str, lang: Optional[LanguageCode] = None) -> str:
216+
"""Get localized implementation target name."""
217+
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
218+
return settings.message_catalog.get_implementation_target(target, effective_lang)
219+
214220
@classmethod
215221
def get_faq_path(cls) -> str:
216222
"""Get FAQ path
@@ -262,3 +268,37 @@ def get_default_language(cls) -> str:
262268
Default language code
263269
"""
264270
return settings.get("languages.default", "ja")
271+
272+
@classmethod
273+
def get_yaml_validation_mode(cls) -> str:
274+
"""Get YAML validation mode.
275+
276+
Returns:
277+
YAML validation mode ("strict", "warning", or "disabled")
278+
"""
279+
return settings.get("validation.yaml_validation", "strict")
280+
281+
@classmethod
282+
def set_yaml_validation_mode(cls, mode: str) -> None:
283+
"""Set YAML validation mode.
284+
285+
Args:
286+
mode: Validation mode ("strict", "warning", or "disabled")
287+
288+
Raises:
289+
ValueError: If mode is not valid
290+
"""
291+
valid_modes = ["strict", "warning", "disabled"]
292+
if mode not in valid_modes:
293+
raise ValueError(f"Invalid validation mode: {mode}. Must be one of {valid_modes}")
294+
295+
settings.set("validation.yaml_validation", mode)
296+
297+
@classmethod
298+
def get_axe_core_config(cls) -> Dict[str, str]:
299+
"""Get axe-core configuration.
300+
301+
Returns:
302+
Dictionary containing axe-core configuration settings
303+
"""
304+
return settings.get("axe_core", {})
Lines changed: 2 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,2 @@
1-
# List of check tools and their names
2-
CHECK_TOOLS = {
3-
'nvda': {
4-
'ja': 'NVDA',
5-
'en': 'NVDA'
6-
},
7-
'macos-vo': {
8-
'ja': 'macOS VoiceOver',
9-
'en': 'macOS VoiceOver'
10-
},
11-
'axe': {
12-
'ja': 'axe DevTools',
13-
'en': 'axe DevTools'
14-
},
15-
'ios-vo': {
16-
'ja': 'iOS VoiceOver',
17-
'en': 'iOS VoiceOver'
18-
},
19-
'android-tb': {
20-
'ja': 'Android TalkBack',
21-
'en': 'Android TalkBack'
22-
},
23-
'keyboard': {
24-
'ja': 'キーボード操作',
25-
'en': 'Keyboard'
26-
},
27-
'misc': {
28-
'ja': 'その他の手段',
29-
'en': 'Miscellaneous Methods'
30-
}
31-
}
32-
33-
# Check targets
34-
CHECK_TARGETS = {
35-
'design': {
36-
'ja': 'デザイン',
37-
'en': 'Design'
38-
},
39-
'code': {
40-
'ja': 'コード',
41-
'en': 'Code'
42-
},
43-
'product': {
44-
'ja': 'プロダクト',
45-
'en': 'Product'
46-
}
47-
}
48-
49-
# Names for checks/guidelines/procedures target platforms
50-
PLATFORM_NAMES = {
51-
'web': {
52-
'ja': 'Web',
53-
'en': 'Web'
54-
},
55-
'mobile': {
56-
'ja': 'モバイル',
57-
'en': 'Mobile'
58-
},
59-
'general': {
60-
'ja': 'Web、モバイル',
61-
'en': 'Web, Mobile'
62-
},
63-
'ios': {
64-
'ja': 'iOS',
65-
'en': 'iOS'
66-
},
67-
'android': {
68-
'ja': 'Android',
69-
'en': 'Android'
70-
}
71-
}
72-
73-
# Severity tags and its display names
74-
SEVERITY_TAGS = {
75-
'critical': {
76-
'ja': '[CRITICAL]',
77-
'en': '[CRITICAL]'
78-
},
79-
'major': {
80-
'ja': '[MAJOR]',
81-
'en': '[MAJOR]'
82-
},
83-
'normal': {
84-
'ja': '[NORMAL]',
85-
'en': '[NORMAL]'
86-
},
87-
'minor': {
88-
'ja': '[MINOR]',
89-
'en': '[MINOR]'
90-
}
91-
}
92-
93-
# Possible targets for implementation examples
94-
IMPLEMENTATION_TARGETS = {
95-
'web': {
96-
'ja': 'Web',
97-
'en': 'Web'
98-
},
99-
'android': {
100-
'ja': 'Android',
101-
'en': 'Android'
102-
},
103-
'ios': {
104-
'ja': 'iOS',
105-
'en': 'iOS'
106-
}
107-
}
108-
109-
# for axe rules
110-
AXE_CORE = {
111-
'submodule_name': 'vendor/axe-core',
112-
'base_dir': 'vendor/axe-core', # 追加: yaml2rstでも使用
113-
'deque_url': 'https://dequeuniversity.com/rules/axe/',
114-
'msg_ja_file': 'locales/ja.json',
115-
'pkg_file': 'package.json',
116-
'rules_dir': 'lib/rules',
117-
'locale_dir': 'locales', # 追加: yaml2rstでも使用
118-
'locale_ja_file': 'ja.json' # 追加: yaml2rstでも使用
119-
}
1+
# This file previously contained constants that have been moved to the configuration system.
2+
# All constants are now managed through the Config class and YAML configuration files.

tools/lib/freee_a11y_gl/src/freee_a11y_gl/data/config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ paths:
1212
guidelines: "/categories/"
1313
faq: "/faq/articles/"
1414

15+
validation:
16+
yaml_validation: "strict" # strict | warning | disabled
17+
18+
# axe-core configuration
19+
axe_core:
20+
submodule_name: "vendor/axe-core"
21+
base_dir: "vendor/axe-core"
22+
deque_url: "https://dequeuniversity.com/rules/axe/"
23+
pkg_file: "package.json"
24+
rules_dir: "lib/rules"
25+
locale_dir: "locales"
26+
locale_ja_file: "ja.json"
27+
1528
# Profile-specific configurations
1629
profiles:
1730
yaml2rst:

0 commit comments

Comments
 (0)