-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
5 changed files
with
160 additions
and
74 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
preflight_parser/tests/fixture/include_1/NOBEL_PRIZE_WINNER.TEX
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,19 @@ | ||
%! Author = ntai | ||
%! Date = 2/14/24 | ||
|
||
% Preamble | ||
\documentclass[11pt]{article} | ||
|
||
% Packages | ||
\usepackage{amsmath} | ||
\usepackage{graphicx} | ||
|
||
% Document | ||
\begin{document} | ||
|
||
Hello World | ||
\includegraphics{ImageOfNobelPrize.jpg} | ||
|
||
|
||
|
||
\end{document} |
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
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,83 @@ | ||
import os | ||
import unittest | ||
|
||
from preflight_parser import PreflightResponse, generate_preflight_response | ||
|
||
|
||
class TestPreflight(unittest.TestCase): | ||
def setUp(self): | ||
self.fixture_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixture")) | ||
|
||
def test_preflight_0(self): | ||
"""Test for empty/missing directory response.""" | ||
dir_path = "/no/such/directory/should/exist" | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "error") | ||
self.assertEqual(pf.status.info, "No TeX files found") | ||
self.assertEqual(len(pf.detected_toplevel_files), 0) | ||
self.assertEqual(len(pf.tex_files), 0) | ||
|
||
def test_preflight_1(self): | ||
dir_path = os.path.join(self.fixture_dir, "include_1") | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "success") | ||
self.assertEqual(len(pf.detected_toplevel_files), 1) | ||
self.assertEqual(pf.tex_files[0].used_other_files, ["ImageOfNobelPrize.jpg"]) | ||
# check for correct detection of output==pdf when a jpg is included | ||
self.assertEqual( | ||
pf.detected_toplevel_files[0].process.compiler.model_dump_json(exclude_none=True, exclude_defaults=True), | ||
"""{"engine":"tex","lang":"latex","output":"pdf","postp":"none"}""", | ||
) | ||
|
||
def test_preflight_single_tex_1(self): | ||
dir_path = os.path.join(self.fixture_dir, "single_tex_1") | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "success") | ||
self.assertEqual(len(pf.detected_toplevel_files), 1) | ||
self.assertEqual( | ||
pf.detected_toplevel_files[0].process.compiler.model_dump_json(exclude_none=True, exclude_defaults=True), | ||
"""{"engine":"tex","lang":"latex","output":"pdf","postp":"none"}""", | ||
) | ||
|
||
def test_preflight_single_tex_2(self): | ||
dir_path = os.path.join(self.fixture_dir, "single_tex_2") | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "success") | ||
# we do NOT check for 00README entries, so nothing is ignored | ||
self.assertEqual(len(pf.detected_toplevel_files), 3) | ||
self.assertEqual( | ||
pf.detected_toplevel_files[0].process.compiler.model_dump_json(exclude_none=True, exclude_defaults=True), | ||
"""{"engine":"tex","lang":"latex","output":"pdf","postp":"none"}""", | ||
) | ||
|
||
def test_preflight_single_tex_3(self): | ||
"""Test recursive inclusion.""" | ||
dir_path = os.path.join(self.fixture_dir, "single_tex_3") | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "success") | ||
self.assertEqual(len(pf.detected_toplevel_files), 1) | ||
self.assertEqual( | ||
pf.detected_toplevel_files[0].process.compiler.model_dump_json(exclude_none=True, exclude_defaults=True), | ||
"""{"engine":"tex","lang":"latex","output":"pdf","postp":"none"}""", | ||
) | ||
for tf in pf.tex_files: | ||
if tf.filename == "fake-file-1.tex": | ||
self.assertEqual(tf.used_tex_files, ["fake-file-2.TEX", "fake-file-3.tex"]) | ||
self.assertEqual(tf.language.value, "latex") | ||
|
||
def test_preflight_single_tex_4(self): | ||
"""Test recursive inclusion.""" | ||
dir_path = os.path.join(self.fixture_dir, "single_tex_4") | ||
pf: PreflightResponse = generate_preflight_response(dir_path) | ||
self.assertEqual(pf.status.key.value, "success") | ||
self.assertEqual(len(pf.detected_toplevel_files), 2) | ||
self.assertEqual( | ||
pf.detected_toplevel_files[0].process.compiler.model_dump_json(exclude_none=True, exclude_defaults=True), | ||
"""{"engine":"tex","lang":"latex","output":"pdf","postp":"none"}""", | ||
) | ||
for tf in pf.tex_files: | ||
if tf.filename == "fake-file-1.tex": | ||
self.assertEqual(tf.used_tex_files, ["fake-file-2.TEX", "fake-file-3.tex"]) | ||
self.assertEqual(tf.issues[0].info, "fake-package.sty") | ||
self.assertEqual(tf.issues[0].key.value, "file_not_found") | ||
self.assertEqual(tf.language.value, "latex") |