Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tools/lib/freee_a11y_gl/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[flake8]
max-line-length = 88
extend-ignore = E203,W503,E501
exclude =
build/,
dist/,
*.egg-info/,
__pycache__/,
.git/,
.tox/,
.venv/,
venv/
per-file-ignores =
# Allow unused imports in __init__.py files
__init__.py:F401
# Allow longer lines in test files for readability
tests/*:E501
60 changes: 30 additions & 30 deletions tools/lib/freee_a11y_gl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def clear_instances():
for model_class in [Faq, FaqTag, Guideline, Category, Check, CheckTool, InfoRef, WcagSc]:
if hasattr(model_class, '_instances'):
model_class._instances.clear()

# Clear RelationshipManager singleton
RelationshipManager._instance = None

yield

# Clear again after test
for model_class in [Faq, FaqTag, Guideline, Category, Check, CheckTool, InfoRef, WcagSc]:
if hasattr(model_class, '_instances'):
model_class._instances.clear()

# Clear RelationshipManager singleton
RelationshipManager._instance = None

Expand All @@ -54,12 +54,12 @@ def setup_categories():
("dynamic_content", {"ja": "動的コンテンツ", "en": "Dynamic Content"}),
("text", {"ja": "テキスト", "en": "Text"})
]

categories = []
for category_id, names in categories_data:
category = Category(category_id, names)
categories.append(category)

return categories


Expand All @@ -71,12 +71,12 @@ def setup_faq_tags():
("keyboard-operation", {"ja": "キーボード操作", "en": "Keyboard Operation"}),
("screen-reader", {"ja": "スクリーンリーダー", "en": "Screen Reader"})
]

tags = []
for tag_id, names in tags_data:
tag = FaqTag(tag_id, names)
tags.append(tag)

return tags


Expand Down Expand Up @@ -113,12 +113,12 @@ def setup_wcag_sc():
}
})
]

wcag_scs = []
for sc_id, data in wcag_data:
wcag_sc = WcagSc(sc_id, data)
wcag_scs.append(wcag_sc)

return wcag_scs


Expand Down Expand Up @@ -147,38 +147,38 @@ def all_check_data():
"conditions": []
}
]

# Mock Config to avoid dependency issues
with patch('freee_a11y_gl.models.check.Config') as mock_config:
mock_config.get_severity_tag.side_effect = lambda severity, lang: {
('normal', 'ja'): '[NORMAL]',
('high', 'ja'): '[HIGH]'
}.get((severity, lang), f'[{severity.upper()}]')

mock_config.get_check_target_name.side_effect = lambda target, lang: {
('code', 'ja'): 'コード',
('design', 'ja'): 'デザイン'
}.get((target, lang), target)

mock_config.get_platform_name.side_effect = lambda platform, lang: {
('web', 'ja'): 'Web',
('mobile', 'ja'): 'モバイル'
}.get((platform, lang), platform)

mock_config.get_list_separator.return_value = '、'

# Mock RelationshipManager
with patch('freee_a11y_gl.models.base.BaseModel._get_relationship_manager') as mock_get_rel:
mock_rel = MagicMock()
mock_get_rel.return_value = mock_rel
mock_rel.get_related_objects.return_value = []
mock_rel.get_sorted_related_objects.return_value = []

checks = []
for data in checks_data:
check = Check(data)
checks.append(check)

return checks


Expand Down Expand Up @@ -277,13 +277,13 @@ def all_guideline_data(setup_categories):
"category": "dynamic_content"
}
]

# Don't mock RelationshipManager for guidelines to allow real relationships
guidelines = []
for data in guidelines_data:
guideline = Guideline(data)
guidelines.append(guideline)

return guidelines


Expand Down Expand Up @@ -344,13 +344,13 @@ def _create_faq(faq_id):
"guidelines": []
}
}

if faq_id not in faq_data:
raise ValueError(f"Unknown FAQ ID: {faq_id}")

# Don't mock RelationshipManager for FAQ creation to allow real relationships
return Faq(faq_data[faq_id])

return _create_faq


Expand Down Expand Up @@ -409,20 +409,20 @@ def _create_guideline(guideline_id):
"platform": ["web"]
}
}

if guideline_id not in guidelines_data:
raise ValueError(f"Unknown Guideline ID: {guideline_id}")

# Mock RelationshipManager for guideline creation
with patch('freee_a11y_gl.models.content.RelationshipManager') as mock_rel_manager:
mock_rel = MagicMock()
mock_rel_manager.return_value = mock_rel

# Create mock category based on guideline data
mock_category = MagicMock()
guideline_data = guidelines_data[guideline_id]
category_id = guideline_data["category"]

if category_id == "markup":
mock_category.names = {"ja": "マークアップと実装", "en": "Markup and Implementation"}
mock_category.id = "markup"
Expand All @@ -435,15 +435,15 @@ def _create_guideline(guideline_id):
mock_category.names = {"ja": "テキスト", "en": "Text"}
mock_category.id = "text"
mock_category.get_name.side_effect = lambda lang: {"ja": "テキスト", "en": "Text"}[lang]

def mock_get_related_objects(obj, relation_type):
if relation_type == "category":
return [mock_category]
return []

mock_rel.get_related_objects.side_effect = mock_get_related_objects
mock_rel.get_sorted_related_objects.return_value = []

return Guideline(guidelines_data[guideline_id])

return _create_guideline
22 changes: 11 additions & 11 deletions tools/lib/freee_a11y_gl/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def run_tests():
"""Run all tests and provide a summary."""

test_suites = [
("Core Config Tests", "tests/core/test_config.py"),
("Core Utils Tests", "tests/core/test_utils.py"),
Expand All @@ -21,53 +21,53 @@ def run_tests():
("YAML Processor Tests", "tests/yaml_processor/test_process_yaml.py"),
("RST Processor Tests", "tests/yaml_processor/test_rst_processor.py"),
]

results = []

for name, test_path in test_suites:
print(f"\n{'='*60}")
print(f"Running {name}")
print('='*60)

try:
result = subprocess.run(
[sys.executable, "-m", "pytest", test_path, "-v"],
capture_output=True,
text=True,
cwd="/home/max/work/a11y-guidelines/tools/lib/freee_a11y_gl"
)

if result.returncode == 0:
print(f"✅ {name}: PASSED")
results.append((name, "PASSED", ""))
else:
print(f"❌ {name}: FAILED")
results.append((name, "FAILED", result.stdout + result.stderr))

except Exception as e:
print(f"💥 {name}: ERROR - {e}")
results.append((name, "ERROR", str(e)))

# Summary
print(f"\n{'='*60}")
print("TEST SUMMARY")
print('='*60)

passed = sum(1 for _, status, _ in results if status == "PASSED")
failed = sum(1 for _, status, _ in results if status == "FAILED")
errors = sum(1 for _, status, _ in results if status == "ERROR")

for name, status, output in results:
icon = "✅" if status == "PASSED" else "❌" if status == "FAILED" else "💥"
print(f"{icon} {name}: {status}")
if status != "PASSED" and output:
print(f" {output[:200]}...")

print(f"\nTotal: {len(results)} test suites")
print(f"Passed: {passed}")
print(f"Failed: {failed}")
print(f"Errors: {errors}")

return failed + errors == 0


Expand Down