Фикс создания файла
This commit is contained in:
Mikan
2025-12-08 19:28:50 +03:00
parent d709f1dee2
commit 9553c03c12
6 changed files with 241 additions and 47 deletions

View File

@@ -28,7 +28,7 @@ def test_handle_image():
doc = Document()
style_reg = StyleRegistry(Path("resources/style_config.yaml"))
style_reg.ensure_styles_in_doc(doc)
node = {"type": "image", "src": "images/logo.png", "alt": "Логотип"} # ✅ src = images/logo.png
node = {"type": "image", "src": "images/logo.png", "alt": "Логотип"}
# Создаем реальное изображение
img_path = Path("tests/fixtures/images/logo.png")
@@ -36,7 +36,8 @@ def test_handle_image():
img = Image.new("RGB", (100, 100), color="red")
img.save(img_path)
handle_image(node, doc, Path("tests/fixtures"), style_reg) # images_dir = tests/fixtures
# images_dir должен указывать на папку images/
handle_image(node, doc, Path("tests/fixtures/images"), style_reg)
# После вызова должно быть 2 параграфа: картинка и подпись
assert len(doc.paragraphs) == 2
@@ -93,18 +94,23 @@ def test_handle_table():
node = {
"type": "table",
"children": [
{ # header
"type": "table_row",
{ # table_head
"type": "table_head",
"children": [
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 1"}]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 2"}]},
]
},
{ # row 1
"type": "table_row",
{ # table_body
"type": "table_body",
"children": [
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 1"}]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 2"}]},
{ # table_row
"type": "table_row",
"children": [
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 1"}]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 2"}]},
]
}
]
}
]
@@ -124,22 +130,32 @@ def test_handle_table_with_br():
node = {
"type": "table",
"children": [
{ # header
"type": "table_row",
{ # table_head
"type": "table_head",
"children": [
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 1"}]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 2"}]},
{ # table_row
"type": "table_row",
"children": [
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 1"}]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Заголовок 2"}]},
]
}
]
},
{ # row 1
"type": "table_row",
{ # table_body
"type": "table_body",
"children": [
{"type": "table_cell", "children": [
{"type": "text", "raw": "Первая строка"},
{"type": "softbreak"}, # или linebreak/html
{"type": "text", "raw": "Вторая строка"}
]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 2"}]},
{ # row 1
"type": "table_row",
"children": [
{"type": "table_cell", "children": [
{"type": "text", "raw": "Первая строка"},
{"type": "softbreak"}, # или linebreak/html
{"type": "text", "raw": "Вторая строка"}
]},
{"type": "table_cell", "children": [{"type": "text", "raw": "Ячейка 2"}]},
]
}
]
}
]