pyladoc/tests/test_template_functions.py

87 lines
2.1 KiB
Python
Raw Normal View History

import pyladoc
2025-05-30 15:08:38 +00:00
2025-05-31 09:32:05 +00:00
def test_inject_to_template_html():
template = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><!--TITLE--></title>
</head>
<!-- some comment -->
<body>
<!--CONTENT-->
</body>
</html>
"""
2025-05-30 15:08:38 +00:00
content = "Hello, World!"
title = "Test Title"
2025-05-30 15:08:38 +00:00
result = pyladoc.inject_to_template({'CONTENT': content, 'TITLE': title}, template_string=template)
print(result)
2025-05-30 15:08:38 +00:00
assert "Hello, World!" in result
2025-05-31 09:32:05 +00:00
assert "<!-- some comment -->" in result # Keep unrelated HTML comments
2025-05-30 15:08:38 +00:00
assert "<title>Test Title</title>" in result
2025-05-31 09:32:05 +00:00
2025-05-31 09:32:05 +00:00
def test_inject_to_template_latex():
template = """
\\documentclass[a4paper,12pt]{article}
% Packages
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{lmodern} % Load Latin Modern font
\\usepackage{graphicx} % For including images
\\usepackage{amsmath} % For mathematical symbols
\\usepackage{amssymb} % For additional symbols
\\usepackage{hyperref} % For hyperlinks
\\usepackage{caption} % For customizing captions
\\usepackage{geometry} % To set margins
\\usepackage{natbib} % For citations
\\usepackage{float} % For fixing figure positions
\\usepackage{siunitx} % For scientific units
\\usepackage{booktabs} % For professional-looking tables
\\usepackage{pgf} % For using pgf grafics
\\usepackage{textcomp, gensymb} % provides \\degree symbol
\\sisetup{
table-align-text-post = false
}
% Geometry Settings
\\geometry{margin=1in} % 1-inch margins
% Title and Author Information
\\title{<!--PROJECT-->}
<!--AUTHOR-->
\\date{\\today}
\begin{document}
% Title Page
\\maketitle
% <!--CONTENT-->
\\end{document}
"""
content = "Hello, World!"
project_name = "Test Project"
author_name = "Otto"
result = pyladoc.inject_to_template(
{'CONTENT': content, 'PROJECT': project_name, 'AUTHOR': author_name},
template_string=template)
print(result)
assert "\nOtto\n" in result
assert "\\title{Test Project}\n" in result
assert "Hello, World!" in result