feat: implement --emoji flag and MARKITECT_EMOJI environment variable - Issue #37
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>
This commit is contained in:
175
tests/test_issue_37_emoji_flag_basic.py
Normal file
175
tests/test_issue_37_emoji_flag_basic.py
Normal file
@@ -0,0 +1,175 @@
|
||||
"""
|
||||
Test basic emoji flag functionality - Issue #37
|
||||
|
||||
Tests the implementation of --emoji flag and MARKITECT_EMOJI environment variable
|
||||
to complement the existing --ascii flag functionality.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, mock_open
|
||||
|
||||
|
||||
class TestEmojiFlag:
|
||||
"""Test emoji flag functionality in CLI tools."""
|
||||
|
||||
def test_emoji_flag_exists_in_visualize_schema(self):
|
||||
"""Test that --emoji flag is available in visualize_schema.py - Issue #37."""
|
||||
# Test that the --emoji flag is recognized by the argument parser
|
||||
result = subprocess.run([
|
||||
sys.executable, 'tools/visualize_schema.py', '--help'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0
|
||||
assert "--emoji" in result.stdout
|
||||
assert "Use emoji output" in result.stdout or "Enable emoji output" in result.stdout
|
||||
|
||||
def test_emoji_flag_exists_in_schema_summary(self):
|
||||
"""Test that --emoji flag is available in schema_summary.py - Issue #37."""
|
||||
result = subprocess.run([
|
||||
sys.executable, 'tools/schema_summary.py', '--help'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
assert result.returncode == 0
|
||||
assert "--emoji" in result.stdout
|
||||
assert "Use emoji output" in result.stdout or "Enable emoji output" in result.stdout
|
||||
|
||||
def test_emoji_flag_mutually_exclusive_with_ascii_visualize_schema(self):
|
||||
"""Test that --emoji and --ascii flags are mutually exclusive in visualize_schema - Issue #37."""
|
||||
# Create a temporary test file
|
||||
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', '--emoji'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
# Should fail with argument parsing error due to mutual exclusivity
|
||||
assert result.returncode == 2, "Using both --ascii and --emoji should result in argument parsing error"
|
||||
assert "not allowed with argument" in result.stderr, "Error message should indicate mutual exclusivity"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
|
||||
def test_emoji_flag_mutually_exclusive_with_ascii_schema_summary(self):
|
||||
"""Test that --emoji and --ascii flags are mutually exclusive 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', '--emoji'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
# Should fail with argument parsing error due to mutual exclusivity
|
||||
assert result.returncode == 2, "Using both --ascii and --emoji should result in argument parsing error"
|
||||
assert "not allowed with argument" in result.stderr, "Error message should indicate mutual exclusivity"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
|
||||
def test_emoji_output_is_default_in_visualize_schema(self):
|
||||
"""Test that emoji output is the default behavior in visualize_schema - Issue #37."""
|
||||
test_file = Path("temp_test_schema.json")
|
||||
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
||||
|
||||
try:
|
||||
# Test default output (should have emojis)
|
||||
result_default = subprocess.run([
|
||||
sys.executable, 'tools/visualize_schema.py', str(test_file)
|
||||
], capture_output=True, text=True)
|
||||
|
||||
# Test explicit emoji flag
|
||||
result_emoji = subprocess.run([
|
||||
sys.executable, 'tools/visualize_schema.py', str(test_file), '--emoji'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
assert result_default.returncode == 0
|
||||
assert result_emoji.returncode == 0
|
||||
|
||||
# Both should contain emoji characters (basic check)
|
||||
default_has_emojis = any(ord(char) > 127 for char in result_default.stdout)
|
||||
emoji_has_emojis = any(ord(char) > 127 for char in result_emoji.stdout)
|
||||
|
||||
assert default_has_emojis, "Default output should contain emoji characters"
|
||||
assert emoji_has_emojis, "Explicit --emoji flag should produce emoji output"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
|
||||
def test_emoji_output_is_default_in_schema_summary(self):
|
||||
"""Test that emoji output is the default behavior in schema_summary - Issue #37."""
|
||||
test_file = Path("temp_test_schema.json")
|
||||
test_file.write_text('{"type": "object", "properties": {"name": {"type": "string"}}}')
|
||||
|
||||
try:
|
||||
# Test default output (should have emojis)
|
||||
result_default = subprocess.run([
|
||||
sys.executable, 'tools/schema_summary.py', str(test_file)
|
||||
], capture_output=True, text=True)
|
||||
|
||||
# Test explicit emoji flag
|
||||
result_emoji = subprocess.run([
|
||||
sys.executable, 'tools/schema_summary.py', str(test_file), '--emoji'
|
||||
], capture_output=True, text=True)
|
||||
|
||||
assert result_default.returncode == 0
|
||||
assert result_emoji.returncode == 0
|
||||
|
||||
# Both should contain emoji characters (basic check)
|
||||
default_has_emojis = any(ord(char) > 127 for char in result_default.stdout)
|
||||
emoji_has_emojis = any(ord(char) > 127 for char in result_emoji.stdout)
|
||||
|
||||
assert default_has_emojis, "Default output should contain emoji characters"
|
||||
assert emoji_has_emojis, "Explicit --emoji flag should produce emoji output"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
|
||||
def test_ascii_flag_overrides_emoji_default_visualize_schema(self):
|
||||
"""Test that --ascii flag overrides emoji default 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)
|
||||
|
||||
assert result.returncode == 0
|
||||
|
||||
# Should NOT contain emoji characters
|
||||
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
||||
assert not has_emojis, "ASCII mode should not contain emoji characters"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
|
||||
def test_ascii_flag_overrides_emoji_default_schema_summary(self):
|
||||
"""Test that --ascii flag overrides emoji default 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)
|
||||
|
||||
assert result.returncode == 0
|
||||
|
||||
# Should NOT contain emoji characters
|
||||
has_emojis = any(ord(char) > 127 for char in result.stdout)
|
||||
assert not has_emojis, "ASCII mode should not contain emoji characters"
|
||||
|
||||
finally:
|
||||
if test_file.exists():
|
||||
test_file.unlink()
|
||||
Reference in New Issue
Block a user