-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f0b86d
commit adf9d15
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import tempfile | ||
import os | ||
from latex_clean_fig.clean import extract_included_images | ||
|
||
def test_extract_included_images(): | ||
latex_content = """ | ||
\\documentclass{article} | ||
\\usepackage{graphicx} | ||
\\begin{document} | ||
\\includegraphics{figure1} | ||
\\includegraphics[width=0.5\\textwidth]{figure2} | ||
\\end{document} | ||
""" | ||
|
||
# Create a temporary LaTeX file | ||
with tempfile.NamedTemporaryFile(delete=False, suffix=".tex") as temp_file: | ||
temp_file.write(latex_content.encode("utf-8")) | ||
temp_file_path = temp_file.name | ||
|
||
try: | ||
# Extract included images | ||
images = extract_included_images(temp_file_path) | ||
assert images == {"figure1", "figure2"}, f"Expected {{'figure1', 'figure2'}}, got {images}" | ||
finally: | ||
os.remove(temp_file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import tempfile | ||
import os | ||
from latex_clean_fig.clean import remove_unused_images | ||
|
||
def test_remove_unused_images(): | ||
# Simulate LaTeX file | ||
latex_content = """ | ||
\\includegraphics{figure1} | ||
\\includegraphics{figure2} | ||
""" | ||
|
||
# Create a temporary LaTeX file | ||
with tempfile.NamedTemporaryFile(delete=False, suffix=".tex") as temp_tex_file: | ||
temp_tex_file.write(latex_content.encode("utf-8")) | ||
tex_file_path = temp_tex_file.name | ||
|
||
# Create a temporary directory with images | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
# Create image files | ||
included_images = ["figure1.png", "figure2.jpg"] | ||
unused_images = ["unused1.png", "unused2.jpg"] | ||
for image in included_images + unused_images: | ||
open(os.path.join(temp_dir, image), "w").close() | ||
|
||
# Call remove_unused_images | ||
included, removed, total_files = remove_unused_images(temp_dir, tex_file_path) | ||
assert included == {"figure1", "figure2"}, f"Expected {{'figure1', 'figure2'}}, got {included}" | ||
assert sorted(removed) == sorted(unused_images), f"Expected {unused_images}, got {removed}" | ||
assert total_files == len(included_images + unused_images), f"Expected {len(included_images + unused_images)}, got {total_files}" | ||
|
||
os.remove(tex_file_path) |