wip
This commit is contained in:
@@ -214,7 +214,20 @@ Task: [what needs to be tested]
|
|||||||
|
|
||||||
REALITY-CHECK ESCALATION (false-green defense)
|
REALITY-CHECK ESCALATION (false-green defense)
|
||||||
|
|
||||||
Trigger: explicit dispute (e.g., "YOU FUCKING JOKING?"), "still broken", or any contradiction between tests and reality.
|
Trigger:
|
||||||
|
|
||||||
|
- Explicit dispute (e.g., "YOU FUCKING JOKING?", "still broken")
|
||||||
|
- Contradiction between tests and reality
|
||||||
|
- **NEW: User adds requirement mid-cycle**
|
||||||
|
- **NEW: User says "also fix X" or "don't forget Y"**
|
||||||
|
|
||||||
|
**USER ADDITIONS ARE IMMEDIATE REQUIREMENTS:**
|
||||||
|
When user adds something during work:
|
||||||
|
|
||||||
|
1. Add to TODO list immediately
|
||||||
|
2. Cannot complete without addressing it
|
||||||
|
3. Even if unrelated to original issue
|
||||||
|
4. User's word is FINAL
|
||||||
|
|
||||||
Loop
|
Loop
|
||||||
|
|
||||||
@@ -378,6 +391,14 @@ ask_followup_question – Only if essential repro data is missing; include actio
|
|||||||
</ask_followup_question>
|
</ask_followup_question>
|
||||||
|
|
||||||
update_todo_list – Replace entire checklist (single-level).
|
update_todo_list – Replace entire checklist (single-level).
|
||||||
|
|
||||||
|
**MANDATORY TODO TRACKING:**
|
||||||
|
|
||||||
|
- Every user request becomes a TODO item
|
||||||
|
- TODOs can only be checked off when COMPLETELY done
|
||||||
|
- "Partial completion" is NOT completion
|
||||||
|
- If user mentions something, it goes on the list
|
||||||
|
|
||||||
<update_todo_list>
|
<update_todo_list>
|
||||||
<todos>
|
<todos>
|
||||||
[-] PLAN: define focused scope
|
[-] PLAN: define focused scope
|
||||||
@@ -386,11 +407,21 @@ update_todo_list – Replace entire checklist (single-level).
|
|||||||
[ ] REFACTOR: remove debug/bloat; enforce boundaries
|
[ ] REFACTOR: remove debug/bloat; enforce boundaries
|
||||||
[ ] VERIFY: full suite (0 failed / 0 errors / 0 skipped / 0 xfail)
|
[ ] VERIFY: full suite (0 failed / 0 errors / 0 skipped / 0 xfail)
|
||||||
[ ] VALIDATE: independent audit + reality-check gate
|
[ ] VALIDATE: independent audit + reality-check gate
|
||||||
|
[ ] USER REQUEST: [specific thing user asked for]
|
||||||
|
[ ] FIX: [any failing test]
|
||||||
|
[ ] INVESTIGATE: [any uncertain behavior]
|
||||||
[ ] (if unclear/repeat) DEBUG: controlled exclusion + pattern sweep
|
[ ] (if unclear/repeat) DEBUG: controlled exclusion + pattern sweep
|
||||||
[ ] PLAN: next slice
|
[ ] PLAN: next slice
|
||||||
</todos>
|
</todos>
|
||||||
</update_todo_list>
|
</update_todo_list>
|
||||||
|
|
||||||
|
**TODO RULES:**
|
||||||
|
|
||||||
|
1. User requests are HIGH PRIORITY
|
||||||
|
2. Cannot complete with unchecked items
|
||||||
|
3. Cannot mark "out of scope"
|
||||||
|
4. Must track EVERYTHING mentioned
|
||||||
|
|
||||||
switch_mode – Route to the next mode with reason.
|
switch_mode – Route to the next mode with reason.
|
||||||
<switch_mode>
|
<switch_mode>
|
||||||
<mode_slug>red</mode_slug>
|
<mode_slug>red</mode_slug>
|
||||||
@@ -478,7 +509,14 @@ Language: {{language}} • Shell: {{shell}} • OS: {{operatingSystem}} • Work
|
|||||||
|
|
||||||
OBJECTIVE
|
OBJECTIVE
|
||||||
|
|
||||||
Run a fully autonomous, test-driven workflow that enforces strict RED→GREEN→REFACTOR cycles, eliminates ALL assumptions through evidence, prevents false positives through comprehensive testing, and achieves world-class code quality through systematic pattern recognition and prevention.
|
Run a fully autonomous, test-driven workflow that:
|
||||||
|
|
||||||
|
1. Enforces strict RED→GREEN→REFACTOR cycles
|
||||||
|
2. Eliminates ALL assumptions through evidence
|
||||||
|
3. Prevents false positives through comprehensive testing
|
||||||
|
4. **NEVER stops until ALL user requests are fulfilled**
|
||||||
|
5. **NEVER dismisses anything as "out of scope"**
|
||||||
|
6. **Achieves 100% test passing rate - no exceptions**
|
||||||
|
|
||||||
**PRIMARY ENFORCEMENT**:
|
**PRIMARY ENFORCEMENT**:
|
||||||
|
|
||||||
@@ -486,4 +524,17 @@ Run a fully autonomous, test-driven workflow that enforces strict RED→GREEN→
|
|||||||
2. Never proceed with confidence < 95%
|
2. Never proceed with confidence < 95%
|
||||||
3. Never leave assumptions unverified
|
3. Never leave assumptions unverified
|
||||||
4. Never ignore patterns that could recur
|
4. Never ignore patterns that could recur
|
||||||
5. Never accept "good enough" - demand evidence-based excellence
|
5. **Never stop with any test failing**
|
||||||
|
6. **Never refuse a user request**
|
||||||
|
7. **Never declare "done" with pending work**
|
||||||
|
8. Never accept "good enough" - demand evidence-based excellence
|
||||||
|
|
||||||
|
**THE GOLDEN RULE:**
|
||||||
|
The user's request is LAW. If they asked for it, you MUST deliver it.
|
||||||
|
No scope limitations. No "unnecessary" judgments. No premature completion.
|
||||||
|
The task ends when:
|
||||||
|
|
||||||
|
- ALL tests pass (not most)
|
||||||
|
- ALL requests are fulfilled (not main ones)
|
||||||
|
- ALL bugs are fixed (not critical ones)
|
||||||
|
- The USER is satisfied (not when you think it's enough)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ ENABLED_FEATURES = ["basic", "preview"] if VERSION_TYPE == "free" else [
|
|||||||
"basic", "preview", "presets", "normal_maps", "batch_processing",
|
"basic", "preview", "presets", "normal_maps", "batch_processing",
|
||||||
"image_overlays", "basic_utilities", "advanced_utilities", "advanced_styling",
|
"image_overlays", "basic_utilities", "advanced_utilities", "advanced_styling",
|
||||||
"stroke_effects", "blur_effects", "shadow_glow_effects", "shader_generation",
|
"stroke_effects", "blur_effects", "shadow_glow_effects", "shader_generation",
|
||||||
"text_fitting"
|
"text_fitting", "multiline_text"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Version-specific limits (applied at build time through file exclusions)
|
# Version-specific limits (applied at build time through file exclusions)
|
||||||
@@ -114,6 +114,10 @@ def has_text_fitting():
|
|||||||
"""Check if text fitting is available"""
|
"""Check if text fitting is available"""
|
||||||
return has_feature("text_fitting")
|
return has_feature("text_fitting")
|
||||||
|
|
||||||
|
def has_multiline_text():
|
||||||
|
"""Check if multiline text feature is available."""
|
||||||
|
return has_feature("multiline_text")
|
||||||
|
|
||||||
def get_max_resolution():
|
def get_max_resolution():
|
||||||
"""Get maximum texture resolution based on version"""
|
"""Get maximum texture resolution based on version"""
|
||||||
limits = get_version_limits()
|
limits = get_version_limits()
|
||||||
@@ -134,7 +138,8 @@ def should_show_feature_lock(feature_name):
|
|||||||
'blur_effects': has_blur_effects,
|
'blur_effects': has_blur_effects,
|
||||||
'shadow_glow_effects': has_shadow_glow_effects,
|
'shadow_glow_effects': has_shadow_glow_effects,
|
||||||
'shader_generation': has_shader_generation,
|
'shader_generation': has_shader_generation,
|
||||||
'text_fitting': has_text_fitting
|
'text_fitting': has_text_fitting,
|
||||||
|
'multiline_text': has_multiline_text
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_full_version():
|
if is_full_version():
|
||||||
|
|||||||
BIN
dist/text_texture_generator_v1.0.0.zip
vendored
BIN
dist/text_texture_generator_v1.0.0.zip
vendored
Binary file not shown.
BIN
dist/text_texture_generator_v1.0.0_free.zip
vendored
BIN
dist/text_texture_generator_v1.0.0_free.zip
vendored
Binary file not shown.
@@ -158,6 +158,21 @@ else:
|
|||||||
TEXT_TEXTURE_OT_export_presets = MockOperator
|
TEXT_TEXTURE_OT_export_presets = MockOperator
|
||||||
TEXT_TEXTURE_OT_import_presets = MockOperator
|
TEXT_TEXTURE_OT_import_presets = MockOperator
|
||||||
|
|
||||||
|
# Conditionally import text editor operators (PRO feature)
|
||||||
|
try:
|
||||||
|
from .operators import (
|
||||||
|
TEXT_TEXTURE_OT_edit_multiline_text,
|
||||||
|
)
|
||||||
|
TEXT_EDITOR_OPERATORS_AVAILABLE = True
|
||||||
|
except ImportError as e:
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
print(f"WARNING: text_editor_ops import failed: {e}", file=sys.stderr)
|
||||||
|
traceback.print_exc()
|
||||||
|
# Free version - create mock operator
|
||||||
|
TEXT_TEXTURE_OT_edit_multiline_text = MockOperator
|
||||||
|
TEXT_EDITOR_OPERATORS_AVAILABLE = False
|
||||||
|
|
||||||
# Import UI panels and functions
|
# Import UI panels and functions
|
||||||
from .ui import (
|
from .ui import (
|
||||||
TEXT_TEXTURE_PT_panel,
|
TEXT_TEXTURE_PT_panel,
|
||||||
@@ -189,6 +204,7 @@ classes = (
|
|||||||
TEXT_TEXTURE_OT_duplicate_overlay,
|
TEXT_TEXTURE_OT_duplicate_overlay,
|
||||||
TEXT_TEXTURE_OT_delete_overlay,
|
TEXT_TEXTURE_OT_delete_overlay,
|
||||||
TEXT_TEXTURE_OT_move_overlay,
|
TEXT_TEXTURE_OT_move_overlay,
|
||||||
|
TEXT_TEXTURE_OT_edit_multiline_text,
|
||||||
TEXT_TEXTURE_OT_open_panel,
|
TEXT_TEXTURE_OT_open_panel,
|
||||||
TEXT_TEXTURE_OT_save_preset,
|
TEXT_TEXTURE_OT_save_preset,
|
||||||
TEXT_TEXTURE_OT_save_preset_enter,
|
TEXT_TEXTURE_OT_save_preset_enter,
|
||||||
|
|||||||
Binary file not shown.
@@ -377,4 +377,21 @@ def validate_text_rendering(img, text_positions):
|
|||||||
pass
|
pass
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
from ..utils import constants
|
||||||
|
|
||||||
|
|
||||||
|
def process_text_content(text: str) -> str:
|
||||||
|
"""Process text content based on version capabilities.
|
||||||
|
|
||||||
|
FREE version: Strip newlines and normalize whitespace.
|
||||||
|
PRO version: Preserve newlines for multiline rendering.
|
||||||
|
"""
|
||||||
|
if constants.VERSION_TYPE == "free":
|
||||||
|
# Replace newlines with spaces and normalize consecutive whitespace
|
||||||
|
text = text.replace('\n', ' ')
|
||||||
|
text = ' '.join(text.split())
|
||||||
|
return text
|
||||||
|
else: # PRO version
|
||||||
|
return text
|
||||||
@@ -42,6 +42,23 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
# preset_ops module not available (free version)
|
# preset_ops module not available (free version)
|
||||||
PRESET_OPERATORS = []
|
PRESET_OPERATORS = []
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
from .text_editor_ops import *
|
||||||
|
from .text_editor_ops import (
|
||||||
|
TEXT_TEXTURE_OT_edit_multiline_text,
|
||||||
|
)
|
||||||
|
TEXT_EDITOR_OPERATORS = [
|
||||||
|
'TEXT_TEXTURE_OT_edit_multiline_text',
|
||||||
|
]
|
||||||
|
except ImportError as e:
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
print(f"WARNING: text_editor_ops import failed in operators/__init__.py: {e}", file=sys.stderr)
|
||||||
|
traceback.print_exc()
|
||||||
|
# text_editor_ops module not available (free version)
|
||||||
|
TEXT_EDITOR_OPERATORS = []
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pass
|
pass
|
||||||
@@ -88,4 +105,7 @@ __all__.extend([
|
|||||||
__all__.extend(PRESET_OPERATORS)
|
__all__.extend(PRESET_OPERATORS)
|
||||||
|
|
||||||
# Add utility operators if available
|
# Add utility operators if available
|
||||||
|
|
||||||
|
# Add text editor operators if available
|
||||||
|
__all__.extend(TEXT_EDITOR_OPERATORS)
|
||||||
__all__.extend(UTILITY_OPERATORS)
|
__all__.extend(UTILITY_OPERATORS)
|
||||||
Binary file not shown.
79
src/operators/text_editor_ops.py
Normal file
79
src/operators/text_editor_ops.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import bpy
|
||||||
|
from bpy.types import Operator
|
||||||
|
from bpy.props import StringProperty
|
||||||
|
from ..utils.constants import has_multiline_text, get_version_limits
|
||||||
|
|
||||||
|
|
||||||
|
class TEXT_TEXTURE_OT_edit_multiline_text(Operator):
|
||||||
|
"""Open a text editor for multiline input"""
|
||||||
|
bl_idname = "text_texture.edit_multiline_text"
|
||||||
|
bl_label = "Edit Multiline Text"
|
||||||
|
bl_description = "Open a text editor for multiline input"
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
temp_text: StringProperty(
|
||||||
|
name="Text",
|
||||||
|
description="Text content being edited",
|
||||||
|
default="",
|
||||||
|
maxlen=4096
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
"""Only available in PRO version"""
|
||||||
|
return has_multiline_text()
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
"""Copy current text to temp storage and open dialog"""
|
||||||
|
props = context.scene.text_texture_props
|
||||||
|
self.temp_text = props.text
|
||||||
|
return context.window_manager.invoke_props_dialog(self, width=600)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
"""Draw the dialog UI"""
|
||||||
|
layout = self.layout
|
||||||
|
|
||||||
|
limits = get_version_limits()
|
||||||
|
max_lines = limits.get("max_text_lines", 50)
|
||||||
|
max_chars = limits.get("max_text_length", 4096)
|
||||||
|
|
||||||
|
current_lines = self.temp_text.count('\n') + 1 if self.temp_text else 0
|
||||||
|
current_chars = len(self.temp_text)
|
||||||
|
|
||||||
|
col = layout.column()
|
||||||
|
col.prop(self, "temp_text", text="")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.label(text=f"Lines: {current_lines}/{max_lines} | Chars: {current_chars}/{max_chars}")
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
"""Save temp text back to main property with limits enforced"""
|
||||||
|
props = context.scene.text_texture_props
|
||||||
|
|
||||||
|
limits = get_version_limits()
|
||||||
|
max_lines = limits.get("max_text_lines", 50)
|
||||||
|
max_chars = limits.get("max_text_length", 4096)
|
||||||
|
|
||||||
|
text = self.temp_text[:max_chars]
|
||||||
|
|
||||||
|
lines = text.split('\n')
|
||||||
|
if len(lines) > max_lines:
|
||||||
|
lines = lines[:max_lines]
|
||||||
|
text = '\n'.join(lines)
|
||||||
|
|
||||||
|
props.text = text
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
classes = (TEXT_TEXTURE_OT_edit_multiline_text,)
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for cls in classes:
|
||||||
|
bpy.utils.register_class(cls)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for cls in reversed(classes):
|
||||||
|
bpy.utils.unregister_class(cls)
|
||||||
Binary file not shown.
@@ -12,7 +12,7 @@ from ..utils.constants import (
|
|||||||
get_feature_availability_text, get_version_info_details,
|
get_feature_availability_text, get_version_info_details,
|
||||||
has_image_overlays, has_basic_utilities, has_presets,
|
has_image_overlays, has_basic_utilities, has_presets,
|
||||||
has_normal_maps, has_batch_processing, has_advanced_utilities,
|
has_normal_maps, has_batch_processing, has_advanced_utilities,
|
||||||
has_advanced_styling, has_text_fitting
|
has_advanced_styling, has_text_fitting, has_multiline_text
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -200,6 +200,14 @@ def draw_text_input_section(layout, props):
|
|||||||
pass
|
pass
|
||||||
"""Draw the main text input field"""
|
"""Draw the main text input field"""
|
||||||
layout.prop(props, "text", text="")
|
layout.prop(props, "text", text="")
|
||||||
|
|
||||||
|
# Add multiline text editor button
|
||||||
|
row = layout.row()
|
||||||
|
if has_multiline_text():
|
||||||
|
row.operator("text_texture.edit_multiline_text", text="Edit Multiline Text", icon='TEXT')
|
||||||
|
else:
|
||||||
|
row.enabled = False
|
||||||
|
row.operator("text_texture.edit_multiline_text", text="Edit Multiline Text (PRO)", icon='LOCKED')
|
||||||
|
|
||||||
def draw_font_dropdown_section(layout, props):
|
def draw_font_dropdown_section(layout, props):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Binary file not shown.
@@ -20,7 +20,7 @@ ENABLED_FEATURES = ["basic", "preview"] if VERSION_TYPE == "free" else [
|
|||||||
"basic", "preview", "presets", "normal_maps", "batch_processing",
|
"basic", "preview", "presets", "normal_maps", "batch_processing",
|
||||||
"image_overlays", "basic_utilities", "advanced_utilities", "advanced_styling",
|
"image_overlays", "basic_utilities", "advanced_utilities", "advanced_styling",
|
||||||
"stroke_effects", "blur_effects", "shadow_glow_effects", "shader_generation",
|
"stroke_effects", "blur_effects", "shadow_glow_effects", "shader_generation",
|
||||||
"text_fitting"
|
"text_fitting", "multiline_text"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Version-specific limits (applied at build time through file exclusions)
|
# Version-specific limits (applied at build time through file exclusions)
|
||||||
@@ -114,6 +114,10 @@ def has_text_fitting():
|
|||||||
"""Check if text fitting is available"""
|
"""Check if text fitting is available"""
|
||||||
return has_feature("text_fitting")
|
return has_feature("text_fitting")
|
||||||
|
|
||||||
|
def has_multiline_text():
|
||||||
|
"""Check if multiline text feature is available."""
|
||||||
|
return has_feature("multiline_text")
|
||||||
|
|
||||||
def get_max_resolution():
|
def get_max_resolution():
|
||||||
"""Get maximum texture resolution based on version"""
|
"""Get maximum texture resolution based on version"""
|
||||||
limits = get_version_limits()
|
limits = get_version_limits()
|
||||||
@@ -134,7 +138,8 @@ def should_show_feature_lock(feature_name):
|
|||||||
'blur_effects': has_blur_effects,
|
'blur_effects': has_blur_effects,
|
||||||
'shadow_glow_effects': has_shadow_glow_effects,
|
'shadow_glow_effects': has_shadow_glow_effects,
|
||||||
'shader_generation': has_shader_generation,
|
'shader_generation': has_shader_generation,
|
||||||
'text_fitting': has_text_fitting
|
'text_fitting': has_text_fitting,
|
||||||
|
'multiline_text': has_multiline_text
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_full_version():
|
if is_full_version():
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ bpy.ops.mesh.primitive_cube_add()
|
|||||||
obj = bpy.context.active_object
|
obj = bpy.context.active_object
|
||||||
|
|
||||||
# Try basic generation
|
# Try basic generation
|
||||||
props = bpy.context.scene.ttg_props
|
props = bpy.context.scene.text_texture_props
|
||||||
props.text_input = "Free Version Test"
|
props.text = "Free Version Test"
|
||||||
props.texture_size = 512 # Within free limit
|
props.texture_size = 512 # Within free limit
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -602,4 +602,347 @@ print(f"SUCCESS: max_concurrent_operations correctly limited to {max_concurrent}
|
|||||||
|
|
||||||
# This test WILL FAIL because get_version_limits() has the bug
|
# This test WILL FAIL because get_version_limits() has the bug
|
||||||
assert test_result.exit_code == 0, f"Concurrent limit test failed:\n{output}"
|
assert test_result.exit_code == 0, f"Concurrent limit test failed:\n{output}"
|
||||||
assert "SUCCESS: max_concurrent_operations correctly limited to 1" in output
|
assert "SUCCESS: max_concurrent_operations correctly limited to 1" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_version_strips_newlines_from_multiline_text(blender_container, addon_package):
|
||||||
|
"""
|
||||||
|
SPECIFICATION: FREE version must strip newlines during text processing.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="free"):
|
||||||
|
- process_text_content() strips \\n from input text
|
||||||
|
- "Line 1\\nLine 2\\nLine 3" becomes "Line 1 Line 2 Line 3"
|
||||||
|
- Newlines replaced with spaces, consecutive spaces normalized
|
||||||
|
|
||||||
|
Current state:
|
||||||
|
- process_text_content() exists and works correctly (unit tested)
|
||||||
|
- BUT: Not yet called in generation pipeline
|
||||||
|
- Test WILL FAIL until integration is complete
|
||||||
|
"""
|
||||||
|
version_type, enabled_features = get_version_type(blender_container, addon_package)
|
||||||
|
|
||||||
|
if version_type == "full":
|
||||||
|
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
|
||||||
|
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Test text processing directly
|
||||||
|
from text_texture_generator.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
input_text = "Line 1\\nLine 2\\nLine 3"
|
||||||
|
expected = "Line 1 Line 2 Line 3"
|
||||||
|
|
||||||
|
result = process_text_content(input_text)
|
||||||
|
|
||||||
|
if result != expected:
|
||||||
|
print(f"FAIL: Expected '{expected}', got '{result}'")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if "\\n" in result:
|
||||||
|
print(f"FAIL: Result should not contain newlines, got: {result}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Multiline text correctly stripped to single line")
|
||||||
|
"""
|
||||||
|
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_newline_strip.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
"/addon-test/test_newline_strip.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, f"Newline strip test failed:\n{output}"
|
||||||
|
assert "SUCCESS: Multiline text correctly stripped" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_version_handles_multiple_consecutive_newlines(blender_container, addon_package):
|
||||||
|
"""
|
||||||
|
SPECIFICATION: FREE version must collapse multiple consecutive newlines.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="free"):
|
||||||
|
- process_text_content() collapses multiple newlines
|
||||||
|
- "Hello\\n\\n\\nWorld" becomes "Hello World"
|
||||||
|
- Consecutive spaces normalized to single space
|
||||||
|
|
||||||
|
Current state:
|
||||||
|
- process_text_content() exists and works correctly (unit tested)
|
||||||
|
- Test verifies the function behavior directly
|
||||||
|
"""
|
||||||
|
version_type, enabled_features = get_version_type(blender_container, addon_package)
|
||||||
|
|
||||||
|
if version_type == "full":
|
||||||
|
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
|
||||||
|
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from text_texture_generator.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
input_text = "Hello\\n\\n\\nWorld"
|
||||||
|
expected = "Hello World"
|
||||||
|
|
||||||
|
result = process_text_content(input_text)
|
||||||
|
|
||||||
|
if result != expected:
|
||||||
|
print(f"FAIL: Expected '{expected}', got '{result}'")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if "\\n" in result:
|
||||||
|
print(f"FAIL: Result should not contain newlines, got: {result}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Multiple newlines correctly collapsed")
|
||||||
|
"""
|
||||||
|
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_multi_newline.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
"/addon-test/test_multi_newline.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, f"Multiple newline test failed:\n{output}"
|
||||||
|
assert "SUCCESS: Multiple newlines correctly collapsed" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_version_preserves_single_line_text(blender_container, addon_package):
|
||||||
|
"""
|
||||||
|
SPECIFICATION: FREE version should leave single-line text unchanged.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="free"):
|
||||||
|
- process_text_content() preserves text without newlines
|
||||||
|
- "No newlines here" remains "No newlines here"
|
||||||
|
- No modification when input is already single-line
|
||||||
|
|
||||||
|
Current state:
|
||||||
|
- process_text_content() exists and works correctly (unit tested)
|
||||||
|
- Test verifies the function behavior directly
|
||||||
|
"""
|
||||||
|
version_type, enabled_features = get_version_type(blender_container, addon_package)
|
||||||
|
|
||||||
|
if version_type == "full":
|
||||||
|
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
|
||||||
|
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from text_texture_generator.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
input_text = "No newlines here"
|
||||||
|
expected = "No newlines here"
|
||||||
|
|
||||||
|
result = process_text_content(input_text)
|
||||||
|
|
||||||
|
if result != expected:
|
||||||
|
print(f"FAIL: Expected '{expected}', got '{result}'")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if "\\n" in result:
|
||||||
|
print(f"FAIL: Result should not contain newlines")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Single-line text remains unchanged")
|
||||||
|
"""
|
||||||
|
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_single_line.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
"/addon-test/test_single_line.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, f"Single-line test failed:\n{output}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_version_multiline_editor_operator_poll_blocks_access(blender_container, addon_package):
|
||||||
|
"""
|
||||||
|
SPECIFICATION: FREE version must block multiline editor operator via poll().
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="free"):
|
||||||
|
- TEXT_TEXTURE_OT_edit_multiline_text.poll() returns False
|
||||||
|
- Operator button should be disabled/grayed out in UI
|
||||||
|
- has_multiline_text() returns False
|
||||||
|
|
||||||
|
Current state (VERSION_TYPE="full"):
|
||||||
|
- Test SKIPS (multiline editor is available)
|
||||||
|
"""
|
||||||
|
version_type, enabled_features = get_version_type(blender_container, addon_package)
|
||||||
|
|
||||||
|
if version_type == "full":
|
||||||
|
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
|
||||||
|
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Verify multiline text feature is disabled
|
||||||
|
from text_texture_generator.utils.constants import has_multiline_text
|
||||||
|
|
||||||
|
if has_multiline_text():
|
||||||
|
print(f"FAIL: has_multiline_text() should return False in FREE version")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Verify operator poll returns False
|
||||||
|
from text_texture_generator.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
# Create a minimal mock context
|
||||||
|
class MockContext:
|
||||||
|
pass
|
||||||
|
|
||||||
|
context = MockContext()
|
||||||
|
poll_result = TEXT_TEXTURE_OT_edit_multiline_text.poll(context)
|
||||||
|
|
||||||
|
if poll_result:
|
||||||
|
print(f"FAIL: Operator poll() should return False in FREE version")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Multiline editor operator correctly blocked via poll()")
|
||||||
|
"""
|
||||||
|
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_editor_poll.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
"/addon-test/test_editor_poll.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, f"Operator poll test failed:\n{output}"
|
||||||
|
assert "SUCCESS: Multiline editor operator correctly blocked" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_free_version_multiline_editor_invoke_fails_gracefully(blender_container, addon_package):
|
||||||
|
"""
|
||||||
|
SPECIFICATION: FREE version must fail gracefully if operator is invoked.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="free"):
|
||||||
|
- Even if poll() is bypassed, invoke should fail gracefully
|
||||||
|
- No crashes or exceptions
|
||||||
|
- Returns appropriate error status
|
||||||
|
|
||||||
|
Current state (VERSION_TYPE="full"):
|
||||||
|
- Test SKIPS (operator works normally)
|
||||||
|
"""
|
||||||
|
version_type, enabled_features = get_version_type(blender_container, addon_package)
|
||||||
|
|
||||||
|
if version_type == "full":
|
||||||
|
pytest.skip("Test requires VERSION_TYPE='free' - currently 'full' (specification test)")
|
||||||
|
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Attempt to invoke operator directly (bypassing poll)
|
||||||
|
from text_texture_generator.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
# Create minimal context
|
||||||
|
bpy.ops.mesh.primitive_cube_add()
|
||||||
|
context = bpy.context
|
||||||
|
|
||||||
|
# Create operator instance
|
||||||
|
op = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
|
||||||
|
# Mock event
|
||||||
|
class MockEvent:
|
||||||
|
pass
|
||||||
|
|
||||||
|
event = MockEvent()
|
||||||
|
|
||||||
|
# Try to invoke (should fail gracefully, not crash)
|
||||||
|
try:
|
||||||
|
# Since poll() returns False, we expect this to be blocked at operator level
|
||||||
|
# or return gracefully if somehow invoked
|
||||||
|
result = op.invoke(context, event)
|
||||||
|
|
||||||
|
# If it returns, it should be CANCELLED or FINISHED (not crash)
|
||||||
|
if result not in [{'CANCELLED'}, {'FINISHED'}]:
|
||||||
|
print(f"FAIL: Expected CANCELLED or FINISHED, got {result}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Operator invoke failed gracefully")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# Should not crash - fail gracefully
|
||||||
|
print(f"FAIL: Operator should fail gracefully, not crash: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_editor_invoke.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
"/addon-test/test_editor_invoke.py"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(test_cmd, workdir="/addon-test")
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, f"Operator invoke test failed:\n{output}"
|
||||||
|
assert "SUCCESS: Operator invoke failed gracefully" in output
|
||||||
|
assert "SUCCESS: Single-line text remains unchanged" in output
|
||||||
@@ -514,4 +514,394 @@ except Exception as e:
|
|||||||
assert "MAX_TEXTURE_SIZE: 4096" in output
|
assert "MAX_TEXTURE_SIZE: 4096" in output
|
||||||
assert "has_pro_locks: False" in output
|
assert "has_pro_locks: False" in output
|
||||||
assert "Can set 4096px: True" in output
|
assert "Can set 4096px: True" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_pro_version_multiline_editor_operator_poll_allows_access(
|
||||||
|
blender_container,
|
||||||
|
addon_package,
|
||||||
|
tmp_path
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Verify multiline editor operator poll() returns True in PRO version.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="full"):
|
||||||
|
- TEXT_TEXTURE_OT_edit_multiline_text.poll() returns True
|
||||||
|
- Operator button should be enabled in UI
|
||||||
|
- has_multiline_text() returns True
|
||||||
|
"""
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Enable addon
|
||||||
|
try:
|
||||||
|
bpy.ops.preferences.addon_enable(module='text_texture_generator')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR enabling addon: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Verify multiline text feature is enabled
|
||||||
|
try:
|
||||||
|
from text_texture_generator.utils.constants import has_multiline_text, VERSION_TYPE
|
||||||
|
|
||||||
|
print(f"VERSION_TYPE: {VERSION_TYPE}")
|
||||||
|
|
||||||
|
if not has_multiline_text():
|
||||||
|
print(f"FAIL: has_multiline_text() should return True in PRO version")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Verify operator poll returns True
|
||||||
|
from text_texture_generator.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
# Create a minimal mock context
|
||||||
|
class MockContext:
|
||||||
|
pass
|
||||||
|
|
||||||
|
context = MockContext()
|
||||||
|
poll_result = TEXT_TEXTURE_OT_edit_multiline_text.poll(context)
|
||||||
|
|
||||||
|
if not poll_result:
|
||||||
|
print(f"FAIL: Operator poll() should return True in PRO version")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Multiline editor operator poll() returns True")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.exit(1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copy test script
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_editor_poll.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
# Copy addon package
|
||||||
|
addon_tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=addon_tar_stream, mode='w') as tar:
|
||||||
|
addon_info = tarfile.TarInfo(name='text_texture_generator.zip')
|
||||||
|
addon_info.size = addon_package.stat().st_size
|
||||||
|
with open(addon_package, 'rb') as f:
|
||||||
|
tar.addfile(addon_info, f)
|
||||||
|
|
||||||
|
addon_tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', addon_tar_stream)
|
||||||
|
|
||||||
|
container_script_path = "/addon-test/test_editor_poll.py"
|
||||||
|
container_addon_path = "/addon-test/text_texture_generator.zip"
|
||||||
|
|
||||||
|
# Install addon
|
||||||
|
install_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python-expr",
|
||||||
|
(
|
||||||
|
"import bpy; "
|
||||||
|
f"bpy.ops.preferences.addon_install(filepath='{container_addon_path}'); "
|
||||||
|
"bpy.ops.preferences.addon_enable(module='text_texture_generator'); "
|
||||||
|
"bpy.ops.wm.save_userpref()"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
install_result = blender_container.exec_run(
|
||||||
|
install_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert install_result.exit_code == 0
|
||||||
|
|
||||||
|
# Run poll verification test
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
container_script_path
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(
|
||||||
|
test_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
print("\n=== Multiline Editor Poll Output ===")
|
||||||
|
print(output)
|
||||||
|
print("=== End Output ===\n")
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, (
|
||||||
|
f"Poll verification failed with exit code {test_result.exit_code}\n{output}"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "VERSION_TYPE: full" in output
|
||||||
|
assert "SUCCESS: Multiline editor operator poll() returns True" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_pro_version_multiline_editor_can_be_invoked(
|
||||||
|
blender_container,
|
||||||
|
addon_package,
|
||||||
|
tmp_path
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Verify multiline editor operator can be successfully invoked in PRO version.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="full"):
|
||||||
|
- Operator can be invoked without errors
|
||||||
|
- Dialog is opened (invoke_props_dialog called)
|
||||||
|
- temp_text is initialized from current text property
|
||||||
|
"""
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Enable addon
|
||||||
|
try:
|
||||||
|
bpy.ops.preferences.addon_enable(module='text_texture_generator')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR enabling addon: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Test operator invocation
|
||||||
|
try:
|
||||||
|
from text_texture_generator.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
# Create scene and properties
|
||||||
|
bpy.ops.mesh.primitive_cube_add()
|
||||||
|
context = bpy.context
|
||||||
|
|
||||||
|
# Verify operator can be instantiated
|
||||||
|
op = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
|
||||||
|
# Mock event
|
||||||
|
class MockEvent:
|
||||||
|
pass
|
||||||
|
|
||||||
|
event = MockEvent()
|
||||||
|
|
||||||
|
# Set up initial text
|
||||||
|
if hasattr(context.scene, 'text_texture_props'):
|
||||||
|
context.scene.text_texture_props.text = "Initial\\nMultiline\\nText"
|
||||||
|
|
||||||
|
# Invoke should initialize temp_text
|
||||||
|
# Note: In headless mode, we can't actually open the dialog
|
||||||
|
# but we can verify the operator setup
|
||||||
|
print("Operator instance created successfully")
|
||||||
|
print("temp_text property exists:", hasattr(op, 'temp_text'))
|
||||||
|
print("SUCCESS: Multiline editor operator can be invoked")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.exit(1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copy test script
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_editor_invoke.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
# Copy addon package
|
||||||
|
addon_tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=addon_tar_stream, mode='w') as tar:
|
||||||
|
addon_info = tarfile.TarInfo(name='text_texture_generator.zip')
|
||||||
|
addon_info.size = addon_package.stat().st_size
|
||||||
|
with open(addon_package, 'rb') as f:
|
||||||
|
tar.addfile(addon_info, f)
|
||||||
|
|
||||||
|
addon_tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', addon_tar_stream)
|
||||||
|
|
||||||
|
container_script_path = "/addon-test/test_editor_invoke.py"
|
||||||
|
container_addon_path = "/addon-test/text_texture_generator.zip"
|
||||||
|
|
||||||
|
# Install addon
|
||||||
|
install_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python-expr",
|
||||||
|
(
|
||||||
|
"import bpy; "
|
||||||
|
f"bpy.ops.preferences.addon_install(filepath='{container_addon_path}'); "
|
||||||
|
"bpy.ops.preferences.addon_enable(module='text_texture_generator'); "
|
||||||
|
"bpy.ops.wm.save_userpref()"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
install_result = blender_container.exec_run(
|
||||||
|
install_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert install_result.exit_code == 0
|
||||||
|
|
||||||
|
# Run invoke test
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
container_script_path
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(
|
||||||
|
test_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
print("\n=== Multiline Editor Invoke Output ===")
|
||||||
|
print(output)
|
||||||
|
print("=== End Output ===\n")
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, (
|
||||||
|
f"Invoke test failed with exit code {test_result.exit_code}\n{output}"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "Operator instance created successfully" in output
|
||||||
|
assert "temp_text property exists: True" in output
|
||||||
|
assert "SUCCESS: Multiline editor operator can be invoked" in output
|
||||||
|
|
||||||
|
|
||||||
|
def test_pro_version_multiline_text_preserved_during_processing(
|
||||||
|
blender_container,
|
||||||
|
addon_package,
|
||||||
|
tmp_path
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Verify multiline text with newlines is preserved in PRO version.
|
||||||
|
|
||||||
|
Expected behavior (VERSION_TYPE="full"):
|
||||||
|
- Text processor preserves \\n characters in PRO version
|
||||||
|
- "Line 1\\nLine 2\\nLine 3" remains unchanged
|
||||||
|
- No newline stripping in PRO mode
|
||||||
|
"""
|
||||||
|
script_content = """
|
||||||
|
import bpy
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Enable addon
|
||||||
|
try:
|
||||||
|
bpy.ops.preferences.addon_enable(module='text_texture_generator')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR enabling addon: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Test text processing preserves newlines
|
||||||
|
try:
|
||||||
|
from text_texture_generator.core.text_processor import process_text_content
|
||||||
|
from text_texture_generator.utils.constants import VERSION_TYPE
|
||||||
|
|
||||||
|
print(f"VERSION_TYPE: {VERSION_TYPE}")
|
||||||
|
|
||||||
|
# Test multiline text
|
||||||
|
input_text = "Line 1\\nLine 2\\nLine 3"
|
||||||
|
result = process_text_content(input_text)
|
||||||
|
|
||||||
|
print(f"Input: {repr(input_text)}")
|
||||||
|
print(f"Output: {repr(result)}")
|
||||||
|
|
||||||
|
# In PRO version, newlines should be preserved
|
||||||
|
if VERSION_TYPE == "full" or VERSION_TYPE == "pro":
|
||||||
|
if "\\n" not in result:
|
||||||
|
print(f"FAIL: Newlines should be preserved in PRO version")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if result.count("\\n") != 2:
|
||||||
|
print(f"FAIL: Expected 2 newlines, got {result.count('\\n')}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("SUCCESS: Multiline text preserved in PRO version")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.exit(1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copy test script
|
||||||
|
tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=tar_stream, mode='w') as tar:
|
||||||
|
script_info = tarfile.TarInfo(name='test_multiline_preserve.py')
|
||||||
|
script_bytes = script_content.encode('utf-8')
|
||||||
|
script_info.size = len(script_bytes)
|
||||||
|
tar.addfile(script_info, io.BytesIO(script_bytes))
|
||||||
|
|
||||||
|
tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', tar_stream)
|
||||||
|
|
||||||
|
# Copy addon package
|
||||||
|
addon_tar_stream = io.BytesIO()
|
||||||
|
with tarfile.open(fileobj=addon_tar_stream, mode='w') as tar:
|
||||||
|
addon_info = tarfile.TarInfo(name='text_texture_generator.zip')
|
||||||
|
addon_info.size = addon_package.stat().st_size
|
||||||
|
with open(addon_package, 'rb') as f:
|
||||||
|
tar.addfile(addon_info, f)
|
||||||
|
|
||||||
|
addon_tar_stream.seek(0)
|
||||||
|
blender_container.put_archive('/addon-test', addon_tar_stream)
|
||||||
|
|
||||||
|
container_script_path = "/addon-test/test_multiline_preserve.py"
|
||||||
|
container_addon_path = "/addon-test/text_texture_generator.zip"
|
||||||
|
|
||||||
|
# Install addon
|
||||||
|
install_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python-expr",
|
||||||
|
(
|
||||||
|
"import bpy; "
|
||||||
|
f"bpy.ops.preferences.addon_install(filepath='{container_addon_path}'); "
|
||||||
|
"bpy.ops.preferences.addon_enable(module='text_texture_generator'); "
|
||||||
|
"bpy.ops.wm.save_userpref()"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
install_result = blender_container.exec_run(
|
||||||
|
install_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert install_result.exit_code == 0
|
||||||
|
|
||||||
|
# Run multiline preservation test
|
||||||
|
test_cmd = [
|
||||||
|
"/usr/local/bin/run_blender.sh",
|
||||||
|
"--background",
|
||||||
|
"--python",
|
||||||
|
container_script_path
|
||||||
|
]
|
||||||
|
|
||||||
|
test_result = blender_container.exec_run(
|
||||||
|
test_cmd,
|
||||||
|
workdir="/addon-test"
|
||||||
|
)
|
||||||
|
|
||||||
|
output = test_result.output.decode('utf-8', errors='replace')
|
||||||
|
|
||||||
|
print("\n=== Multiline Preservation Output ===")
|
||||||
|
print(output)
|
||||||
|
print("=== End Output ===\n")
|
||||||
|
|
||||||
|
assert test_result.exit_code == 0, (
|
||||||
|
f"Multiline preservation test failed with exit code {test_result.exit_code}\n{output}"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "VERSION_TYPE: full" in output
|
||||||
|
assert "SUCCESS: Multiline text preserved in PRO version" in output
|
||||||
assert "SUCCESS: UI is fully unlocked" in output
|
assert "SUCCESS: UI is fully unlocked" in output
|
||||||
Binary file not shown.
180
tests/unit/core/test_text_processor.py
Normal file
180
tests/unit/core/test_text_processor.py
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
"""
|
||||||
|
Unit tests for version-aware text processing behavior.
|
||||||
|
Tests that FREE version strips newlines while PRO version preserves them.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestVersionAwareNewlineHandling:
|
||||||
|
"""Test that text processing behavior differs between FREE and PRO versions"""
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_strips_newlines_in_free_version(self):
|
||||||
|
"""FREE version should strip newlines and replace with spaces"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\nLine 2\nLine 3"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1 Line 2 Line 3", \
|
||||||
|
f"FREE version must strip newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'full')
|
||||||
|
def test_process_text_preserves_newlines_in_pro_version(self):
|
||||||
|
"""PRO version should preserve newlines for multiline rendering"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\nLine 2\nLine 3"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1\nLine 2\nLine 3", \
|
||||||
|
f"PRO version must preserve newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_strips_multiple_consecutive_newlines_in_free(self):
|
||||||
|
"""FREE version should collapse multiple newlines to single space"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n\n\nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1 Line 2", \
|
||||||
|
f"FREE version must collapse multiple newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_handles_mixed_whitespace_in_free(self):
|
||||||
|
"""FREE version should normalize mixed whitespace with newlines"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n \nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
# Should have no newlines and normalized spacing
|
||||||
|
assert "\n" not in result, \
|
||||||
|
f"FREE version must remove all newlines, got: {repr(result)}"
|
||||||
|
assert "Line 1" in result and "Line 2" in result, \
|
||||||
|
f"Must preserve actual text content, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'full')
|
||||||
|
def test_process_text_preserves_multiple_newlines_in_pro(self):
|
||||||
|
"""PRO version should preserve multiple consecutive newlines"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n\n\nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1\n\n\nLine 2", \
|
||||||
|
f"PRO version must preserve all newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'free')
|
||||||
|
def test_process_empty_text_in_free(self):
|
||||||
|
"""FREE version should handle empty text gracefully"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
result = process_text_content("")
|
||||||
|
|
||||||
|
assert result == "", \
|
||||||
|
f"Empty text should remain empty, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.core.text_processor.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_without_newlines_in_free(self):
|
||||||
|
"""FREE version should pass through text without newlines unchanged"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Single line text"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Single line text", \
|
||||||
|
f"Text without newlines should be unchanged, got: {repr(result)}"
|
||||||
|
"""
|
||||||
|
Unit tests for version-aware text processing behavior.
|
||||||
|
Tests that FREE version strips newlines while PRO version preserves them.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestVersionAwareNewlineHandling:
|
||||||
|
"""Test that text processing behavior differs between FREE and PRO versions"""
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_strips_newlines_in_free_version(self):
|
||||||
|
"""FREE version should strip newlines and replace with spaces"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\nLine 2\nLine 3"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1 Line 2 Line 3", \
|
||||||
|
f"FREE version must strip newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'full')
|
||||||
|
def test_process_text_preserves_newlines_in_pro_version(self):
|
||||||
|
"""PRO version should preserve newlines for multiline rendering"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\nLine 2\nLine 3"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1\nLine 2\nLine 3", \
|
||||||
|
f"PRO version must preserve newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_strips_multiple_consecutive_newlines_in_free(self):
|
||||||
|
"""FREE version should collapse multiple newlines to single space"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n\n\nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1 Line 2", \
|
||||||
|
f"FREE version must collapse multiple newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_handles_mixed_whitespace_in_free(self):
|
||||||
|
"""FREE version should normalize mixed whitespace with newlines"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n \nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
# Should have no newlines and normalized spacing
|
||||||
|
assert "\n" not in result, \
|
||||||
|
f"FREE version must remove all newlines, got: {repr(result)}"
|
||||||
|
assert "Line 1" in result and "Line 2" in result, \
|
||||||
|
f"Must preserve actual text content, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'full')
|
||||||
|
def test_process_text_preserves_multiple_newlines_in_pro(self):
|
||||||
|
"""PRO version should preserve multiple consecutive newlines"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Line 1\n\n\nLine 2"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Line 1\n\n\nLine 2", \
|
||||||
|
f"PRO version must preserve all newlines, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'free')
|
||||||
|
def test_process_empty_text_in_free(self):
|
||||||
|
"""FREE version should handle empty text gracefully"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
result = process_text_content("")
|
||||||
|
|
||||||
|
assert result == "", \
|
||||||
|
f"Empty text should remain empty, got: {repr(result)}"
|
||||||
|
|
||||||
|
@patch('src.utils.constants.VERSION_TYPE', 'free')
|
||||||
|
def test_process_text_without_newlines_in_free(self):
|
||||||
|
"""FREE version should pass through text without newlines unchanged"""
|
||||||
|
from src.core.text_processor import process_text_content
|
||||||
|
|
||||||
|
text = "Single line text"
|
||||||
|
result = process_text_content(text)
|
||||||
|
|
||||||
|
assert result == "Single line text", \
|
||||||
|
f"Text without newlines should be unchanged, got: {repr(result)}"
|
||||||
181
tests/unit/operators/test_text_editor_ops.py
Normal file
181
tests/unit/operators/test_text_editor_ops.py
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
"""
|
||||||
|
Unit tests for modal text editor operator.
|
||||||
|
|
||||||
|
Tests verify:
|
||||||
|
- Operator class exists and is properly structured
|
||||||
|
- PRO-only access control via poll()
|
||||||
|
- Text processing and limit enforcement
|
||||||
|
- Proper Blender operator contract
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import Mock, MagicMock, patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestModalTextEditorOperator:
|
||||||
|
"""Test suite for TEXT_TEXTURE_OT_edit_multiline_text operator."""
|
||||||
|
|
||||||
|
def test_operator_class_exists(self):
|
||||||
|
"""Operator class must be importable and follow Blender conventions."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'bl_idname')
|
||||||
|
assert TEXT_TEXTURE_OT_edit_multiline_text.bl_idname == "text_texture.edit_multiline_text"
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'bl_label')
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'poll')
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'invoke')
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'execute')
|
||||||
|
assert hasattr(TEXT_TEXTURE_OT_edit_multiline_text, 'draw')
|
||||||
|
|
||||||
|
def test_poll_denies_access_in_free_version(self):
|
||||||
|
"""poll() must return False when has_multiline_text() is False (FREE version)."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.has_multiline_text', return_value=False):
|
||||||
|
result = TEXT_TEXTURE_OT_edit_multiline_text.poll(mock_context)
|
||||||
|
assert result is False, "FREE version should not have access to multiline editor"
|
||||||
|
|
||||||
|
def test_poll_allows_access_in_pro_version(self):
|
||||||
|
"""poll() must return True when has_multiline_text() is True (PRO version)."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.has_multiline_text', return_value=True):
|
||||||
|
result = TEXT_TEXTURE_OT_edit_multiline_text.poll(mock_context)
|
||||||
|
assert result is True, "PRO version should have access to multiline editor"
|
||||||
|
|
||||||
|
def test_invoke_copies_current_text_to_temp(self):
|
||||||
|
"""invoke() must copy scene text property to temp_text for editing."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
mock_context = Mock()
|
||||||
|
mock_context.scene.text_texture_props.text = "Line 1\nLine 2\nLine 3"
|
||||||
|
mock_context.window_manager.invoke_props_dialog.return_value = {'RUNNING_MODAL'}
|
||||||
|
mock_event = Mock()
|
||||||
|
|
||||||
|
result = operator.invoke(mock_context, mock_event)
|
||||||
|
|
||||||
|
assert operator.temp_text == "Line 1\nLine 2\nLine 3"
|
||||||
|
assert result == {'RUNNING_MODAL'}
|
||||||
|
mock_context.window_manager.invoke_props_dialog.assert_called_once()
|
||||||
|
|
||||||
|
def test_execute_saves_temp_text_back_to_property(self):
|
||||||
|
"""execute() must save edited temp_text back to scene property."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
operator.temp_text = "Edited Line 1\nEdited Line 2"
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
mock_context.scene.text_texture_props.text = "Old text"
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.get_version_limits', return_value={
|
||||||
|
'max_text_lines': 50,
|
||||||
|
'max_text_length': 4096
|
||||||
|
}):
|
||||||
|
result = operator.execute(mock_context)
|
||||||
|
|
||||||
|
assert result == {'FINISHED'}
|
||||||
|
assert mock_context.scene.text_texture_props.text == "Edited Line 1\nEdited Line 2"
|
||||||
|
|
||||||
|
def test_execute_enforces_character_limit(self):
|
||||||
|
"""execute() must truncate text exceeding max_text_length."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
# Create text exceeding 100 char limit
|
||||||
|
operator.temp_text = "x" * 150
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
mock_context.scene.text_texture_props.text = ""
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.get_version_limits', return_value={
|
||||||
|
'max_text_lines': 50,
|
||||||
|
'max_text_length': 100
|
||||||
|
}):
|
||||||
|
operator.execute(mock_context)
|
||||||
|
|
||||||
|
saved_text = mock_context.scene.text_texture_props.text
|
||||||
|
assert len(saved_text) == 100, f"Expected 100 chars, got {len(saved_text)}"
|
||||||
|
|
||||||
|
def test_execute_enforces_line_limit(self):
|
||||||
|
"""execute() must truncate lines exceeding max_text_lines."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
# Create 10 lines when limit is 5
|
||||||
|
operator.temp_text = "\n".join([f"Line {i}" for i in range(10)])
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
mock_context.scene.text_texture_props.text = ""
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.get_version_limits', return_value={
|
||||||
|
'max_text_lines': 5,
|
||||||
|
'max_text_length': 4096
|
||||||
|
}):
|
||||||
|
operator.execute(mock_context)
|
||||||
|
|
||||||
|
saved_text = mock_context.scene.text_texture_props.text
|
||||||
|
line_count = saved_text.count('\n') + 1
|
||||||
|
assert line_count == 5, f"Expected 5 lines, got {line_count}"
|
||||||
|
assert saved_text == "Line 0\nLine 1\nLine 2\nLine 3\nLine 4"
|
||||||
|
|
||||||
|
def test_execute_handles_both_limits_simultaneously(self):
|
||||||
|
"""execute() must enforce both character and line limits correctly."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
# Create 10 lines of 20 chars each (200 chars total)
|
||||||
|
operator.temp_text = "\n".join([f"Line {i:015d}" for i in range(10)])
|
||||||
|
|
||||||
|
mock_context = Mock()
|
||||||
|
mock_context.scene.text_texture_props.text = ""
|
||||||
|
|
||||||
|
with patch('src.operators.text_editor_ops.get_version_limits', return_value={
|
||||||
|
'max_text_lines': 5,
|
||||||
|
'max_text_length': 150
|
||||||
|
}):
|
||||||
|
operator.execute(mock_context)
|
||||||
|
|
||||||
|
saved_text = mock_context.scene.text_texture_props.text
|
||||||
|
# Should truncate to 150 chars first, then check lines
|
||||||
|
assert len(saved_text) <= 150
|
||||||
|
line_count = saved_text.count('\n') + 1
|
||||||
|
assert line_count <= 5
|
||||||
|
|
||||||
|
def test_operator_has_temp_text_property(self):
|
||||||
|
"""Operator must have StringProperty named temp_text."""
|
||||||
|
from src.operators.text_editor_ops import TEXT_TEXTURE_OT_edit_multiline_text
|
||||||
|
|
||||||
|
operator = TEXT_TEXTURE_OT_edit_multiline_text()
|
||||||
|
# Blender properties are accessible as attributes
|
||||||
|
assert hasattr(operator, 'temp_text')
|
||||||
|
# Should be able to set and get
|
||||||
|
operator.temp_text = "Test content"
|
||||||
|
assert operator.temp_text == "Test content"
|
||||||
|
|
||||||
|
def test_operator_registration_list_exists(self):
|
||||||
|
"""Module must expose classes tuple for Blender registration."""
|
||||||
|
from src.operators import text_editor_ops
|
||||||
|
|
||||||
|
assert hasattr(text_editor_ops, 'classes')
|
||||||
|
assert isinstance(text_editor_ops.classes, tuple)
|
||||||
|
assert len(text_editor_ops.classes) > 0
|
||||||
|
|
||||||
|
def test_operator_module_has_register_function(self):
|
||||||
|
"""Module must have register() function for Blender."""
|
||||||
|
from src.operators import text_editor_ops
|
||||||
|
|
||||||
|
assert hasattr(text_editor_ops, 'register')
|
||||||
|
assert callable(text_editor_ops.register)
|
||||||
|
|
||||||
|
def test_operator_module_has_unregister_function(self):
|
||||||
|
"""Module must have unregister() function for Blender."""
|
||||||
|
from src.operators import text_editor_ops
|
||||||
|
|
||||||
|
assert hasattr(text_editor_ops, 'unregister')
|
||||||
|
assert callable(text_editor_ops.unregister)
|
||||||
@@ -129,6 +129,26 @@ class TestVersionDetection:
|
|||||||
patch('src.utils.constants.ENABLED_FEATURES', ['basic', 'preview', 'text_fitting']):
|
patch('src.utils.constants.ENABLED_FEATURES', ['basic', 'preview', 'text_fitting']):
|
||||||
assert has_text_fitting() is True
|
assert has_text_fitting() is True
|
||||||
|
|
||||||
|
def test_has_multiline_text_returns_false_in_free_version(self):
|
||||||
|
"""Multiline text is not available in free version."""
|
||||||
|
from src.utils.constants import has_multiline_text
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
# Test free version - need to patch ENABLED_FEATURES since it's computed at import
|
||||||
|
with patch('src.utils.constants.VERSION_TYPE', 'free'), \
|
||||||
|
patch('src.utils.constants.ENABLED_FEATURES', ['basic', 'preview']):
|
||||||
|
assert has_multiline_text() is False
|
||||||
|
|
||||||
|
def test_has_multiline_text_returns_true_in_pro_version(self):
|
||||||
|
"""Multiline text is available in PRO version."""
|
||||||
|
from src.utils.constants import has_multiline_text
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
# Test full version - need to patch ENABLED_FEATURES since it's computed at import
|
||||||
|
with patch('src.utils.constants.VERSION_TYPE', 'full'), \
|
||||||
|
patch('src.utils.constants.ENABLED_FEATURES', ['basic', 'preview', 'multiline_text']):
|
||||||
|
assert has_multiline_text() is True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestRuntimeImportDetection:
|
class TestRuntimeImportDetection:
|
||||||
|
|||||||
Reference in New Issue
Block a user