Files
timmy-config/tests/test_normalize_code_blocks.py
Alexander Whitestone 6fcd2cc59a
Some checks failed
Architecture Lint / Linter Tests (pull_request) Successful in 15s
Smoke Test / smoke (pull_request) Failing after 17s
Validate Config / YAML Lint (pull_request) Failing after 15s
Validate Config / JSON Validate (pull_request) Successful in 18s
Validate Config / Python Syntax & Import Check (pull_request) Failing after 39s
Validate Config / Cron Syntax Check (pull_request) Successful in 12s
Validate Config / Deploy Script Dry Run (pull_request) Successful in 10s
Validate Config / Shell Script Lint (pull_request) Failing after 56s
Validate Config / Playbook Schema Validation (pull_request) Successful in 17s
PR Checklist / pr-checklist (pull_request) Successful in 2m45s
Architecture Lint / Lint Repository (pull_request) Has been cancelled
Validate Config / Python Test Suite (pull_request) Has been cancelled
feat: code block normalization tests (closes #750)
tests/test_normalize_code_blocks.py: 5 tests
  test_normalizes_indented_code_block
  test_preserves_non_code_content
  test_handles_multiple_code_blocks
  test_handles_empty_response
  test_preserves_prompt

Existing normalize-code-blocks.py handles code block indentation.
2026-04-18 15:46:22 -04:00

61 lines
2.1 KiB
Python

"""
Tests for scripts/normalize-code-blocks.py — Code block indentation normalization.
"""
import json
import unittest
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
from normalize_code_blocks import process_line
class TestProcessLine(unittest.TestCase):
def test_normalizes_indented_code_block(self):
entry = {
"prompt": "Write code",
"response": "```python\n def hello():\n print('world')\n```"
}
line = json.dumps(entry)
result, count = process_line(line)
parsed = json.loads(result.strip())
# Code block indentation should be normalized
self.assertIn("def hello():", parsed["response"])
def test_preserves_non_code_content(self):
entry = {"prompt": "Hello", "response": "How are you?"}
line = json.dumps(entry)
result, count = process_line(line)
parsed = json.loads(result.strip())
self.assertEqual(parsed["response"], "How are you?")
def test_handles_multiple_code_blocks(self):
entry = {
"prompt": "Two blocks",
"response": "First:\n```python\n x = 1\n```\nSecond:\n```python\n y = 2\n```"
}
line = json.dumps(entry)
result, count = process_line(line)
parsed = json.loads(result.strip())
self.assertIn("x = 1", parsed["response"])
self.assertIn("y = 2", parsed["response"])
def test_handles_empty_response(self):
entry = {"prompt": "Test", "response": ""}
line = json.dumps(entry)
result, count = process_line(line)
parsed = json.loads(result.strip())
self.assertEqual(parsed["response"], "")
def test_preserves_prompt(self):
entry = {"prompt": "Write a function", "response": "```python\n def f(): pass\n```"}
line = json.dumps(entry)
result, count = process_line(line)
parsed = json.loads(result.strip())
self.assertEqual(parsed["prompt"], "Write a function")
if __name__ == "__main__":
unittest.main()