62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test XML formatting
|
|
"""
|
|
|
|
import tempfile
|
|
import os
|
|
from lxml import etree
|
|
from xml_processor import XMLProcessor
|
|
from config import Config
|
|
|
|
def test_xml_formatting():
|
|
"""Test that XML is properly formatted"""
|
|
|
|
# Create a mock config
|
|
class MockConfig:
|
|
def __init__(self):
|
|
self.output_config = {'create_backups': False}
|
|
|
|
config = MockConfig()
|
|
processor = XMLProcessor(config)
|
|
|
|
# Create initial XML
|
|
initial_xml = '''<?xml version="1.0" encoding="utf-8"?>
|
|
<resources>
|
|
<string name="existing_key">Existing value</string>
|
|
</resources>'''
|
|
|
|
# Write to temp file
|
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.xml', delete=False) as f:
|
|
f.write(initial_xml)
|
|
temp_path = f.name
|
|
|
|
try:
|
|
# Load the XML
|
|
root = processor.load_xml_file(temp_path)
|
|
|
|
# Add new strings
|
|
new_strings = [
|
|
('new_key1', 'New value 1'),
|
|
('new_key2', 'New value 2')
|
|
]
|
|
|
|
processor.add_missing_strings(root, new_strings)
|
|
|
|
# Save the file
|
|
processor.save_xml_file(root, temp_path)
|
|
|
|
# Read and display the result
|
|
with open(temp_path, 'r', encoding='utf-8') as f:
|
|
result = f.read()
|
|
|
|
print("=== FORMATTED XML ===")
|
|
print(result)
|
|
print("=== END XML ===")
|
|
|
|
finally:
|
|
os.unlink(temp_path)
|
|
|
|
if __name__ == "__main__":
|
|
test_xml_formatting()
|