Add comprehensive emoji preference support to complement existing --ascii flag: 🎯 Core Features: • Add --emoji flag to visualization tools (visualize_schema.py, schema_summary.py) • Implement MARKITECT_EMOJI environment variable support • Maintain backward compatibility with existing --ascii flag behavior • Establish proper priority: CLI flags > environment variables > defaults 🏗️ Architecture: • Create shared emoji_utils.py module for centralized logic • Implement determine_output_mode() for standardized preference resolution • Add add_emoji_arguments() for consistent argument parser setup • Follow DRY principle - eliminate duplicate code between tools 🧪 Testing: • 18 comprehensive tests covering all functionality • Basic flag tests: existence, mutual exclusivity, defaults, precedence • Environment variable tests: recognition, case handling, CLI overrides • Configuration integration tests: system compatibility, error handling • All 1337 project tests pass (no regressions) 💡 User Experience: • Consistent behavior across all MarkiTect visualization tools • Multiple preference setting methods (CLI flags, environment variables) • Robust error handling with sensible defaults (emoji by default) • Clear help documentation and discoverable usage patterns 🔧 Implementation Details: • Mutually exclusive argument groups prevent conflicting flags • Case-insensitive environment variable processing • Valid false values: 'false', 'f', '0' - all others default to emoji • Comprehensive documentation with usage examples The implementation follows TDD principles and MarkiTect architectural patterns, ensuring high quality and maintainability while delivering enhanced usability features. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
232 lines
9.5 KiB
Python
232 lines
9.5 KiB
Python
"""
|
|
Test MARKITECT_EMOJI environment variable functionality - Issue #37
|
|
|
|
Tests the implementation of MARKITECT_EMOJI environment variable
|
|
to set user preferences for emoji output.
|
|
"""
|
|
|
|
import pytest
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestEmojiEnvironmentVariable:
|
|
"""Test MARKITECT_EMOJI environment variable functionality."""
|
|
|
|
def test_markitect_emoji_env_var_enables_emoji_visualize_schema(self):
|
|
"""Test that MARKITECT_EMOJI=true enables emoji output in visualize_schema - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'true'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should contain emoji characters
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert has_emojis, "MARKITECT_EMOJI=true should produce emoji output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_markitect_emoji_env_var_enables_emoji_schema_summary(self):
|
|
"""Test that MARKITECT_EMOJI=true enables emoji output in schema_summary - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/schema_summary.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'true'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should contain emoji characters
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert has_emojis, "MARKITECT_EMOJI=true should produce emoji output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_markitect_emoji_env_var_disables_emoji_visualize_schema(self):
|
|
"""Test that MARKITECT_EMOJI=false disables emoji output in visualize_schema - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'false'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should NOT contain emoji characters
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert not has_emojis, "MARKITECT_EMOJI=false should produce ASCII-only output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_markitect_emoji_env_var_disables_emoji_schema_summary(self):
|
|
"""Test that MARKITECT_EMOJI=false disables emoji output in schema_summary - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/schema_summary.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'false'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should NOT contain emoji characters
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert not has_emojis, "MARKITECT_EMOJI=false should produce ASCII-only output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_cli_flag_overrides_env_var_ascii_visualize_schema(self):
|
|
"""Test that --ascii CLI flag overrides MARKITECT_EMOJI=true in visualize_schema - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file), '--ascii'
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'true'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should NOT contain emoji characters (CLI flag wins)
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert not has_emojis, "--ascii flag should override MARKITECT_EMOJI=true"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_cli_flag_overrides_env_var_ascii_schema_summary(self):
|
|
"""Test that --ascii CLI flag overrides MARKITECT_EMOJI=true in schema_summary - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/schema_summary.py', str(test_file), '--ascii'
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'true'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should NOT contain emoji characters (CLI flag wins)
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert not has_emojis, "--ascii flag should override MARKITECT_EMOJI=true"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_cli_flag_overrides_env_var_emoji_visualize_schema(self):
|
|
"""Test that --emoji CLI flag overrides MARKITECT_EMOJI=false in visualize_schema - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file), '--emoji'
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'false'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should contain emoji characters (CLI flag wins)
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert has_emojis, "--emoji flag should override MARKITECT_EMOJI=false"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_cli_flag_overrides_env_var_emoji_schema_summary(self):
|
|
"""Test that --emoji CLI flag overrides MARKITECT_EMOJI=false in schema_summary - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/schema_summary.py', str(test_file), '--emoji'
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': 'false'})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should contain emoji characters (CLI flag wins)
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert has_emojis, "--emoji flag should override MARKITECT_EMOJI=false"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_invalid_env_var_values_default_to_emoji(self):
|
|
"""Test that invalid MARKITECT_EMOJI values default to emoji output - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
invalid_values = ['invalid', '1', 'yes', 'no']
|
|
|
|
try:
|
|
for invalid_value in invalid_values:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': invalid_value})
|
|
|
|
assert result.returncode == 0
|
|
|
|
# Should default to emoji output for invalid values
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
assert has_emojis, f"MARKITECT_EMOJI='{invalid_value}' should default to emoji output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink()
|
|
|
|
def test_case_insensitive_env_var_handling(self):
|
|
"""Test that MARKITECT_EMOJI handles case variations properly - Issue #37."""
|
|
test_file = Path("temp_test_schema.json")
|
|
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
|
|
|
case_variations = [
|
|
('True', True),
|
|
('TRUE', True),
|
|
('true', True),
|
|
('False', False),
|
|
('FALSE', False),
|
|
('false', False)
|
|
]
|
|
|
|
try:
|
|
for env_value, should_have_emojis in case_variations:
|
|
result = subprocess.run([
|
|
sys.executable, 'tools/visualize_schema.py', str(test_file)
|
|
], capture_output=True, text=True, env={'MARKITECT_EMOJI': env_value})
|
|
|
|
assert result.returncode == 0
|
|
|
|
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
|
if should_have_emojis:
|
|
assert has_emojis, f"MARKITECT_EMOJI='{env_value}' should enable emoji output"
|
|
else:
|
|
assert not has_emojis, f"MARKITECT_EMOJI='{env_value}' should disable emoji output"
|
|
|
|
finally:
|
|
if test_file.exists():
|
|
test_file.unlink() |