@@ -82,65 +82,75 @@ def test_input_or_include_without_extension_and_file(tmp_path, directive):
82
82
@needs_latexmk
83
83
@pytest .mark .end_to_end
84
84
@pytest .mark .parametrize ("image_ext" , COMMON_GRAPHICS_EXTENSIONS )
85
- def test_includegraphics (tmp_path , image_ext ):
86
- """Test includegraphics.
85
+ @pytest .mark .parametrize ("has_extension" , [True , False ])
86
+ @pytest .mark .parametrize ("file_exists" , [True , False ])
87
+ def test_includegraphics (tmp_path , image_ext , has_extension , file_exists ):
88
+ """Test includegraphics with/out extensions and if (not) the image file exists.
87
89
88
90
Using post-script image files does not work with latexmk, since the .ps-file is
89
91
converted to .pdf every run and latexmk will interpret it as a new file every time.
90
92
Can be resolved by allowing pdflatex as the builder.
91
93
92
94
"""
93
- if image_ext == ".ps" :
95
+ if image_ext == ".ps" and file_exists :
94
96
pytest .xfail (
95
97
".ps does not work with latexmk: https://tex.stackexchange.com/a/67904."
96
98
)
97
- if image_ext == ".eps" :
99
+ if image_ext == ".eps" and file_exists :
98
100
pytest .xfail (
99
101
".eps maybe needs \\ graphicspath: https://tex.stackexchange.com/a/98886."
100
102
)
101
103
102
- source = """
103
- \\ documentclass{article}
104
- \\ usepackage{graphicx}
105
- % \\ usepackage{auto-pst-pdf} necessary for .ps-files.
106
- \\ begin{document}
107
- \\ includegraphics{image}
108
- \\ end{document}
104
+ source = f"""
105
+ \\ documentclass{{article}}
106
+ \\ usepackage{{graphicx}}
107
+ \\ begin{{document}}
108
+ \\ includegraphics{{image{ image_ext if has_extension else '' } }}
109
+ \\ end{{document}}
109
110
"""
110
111
tmp_path .joinpath ("document.tex" ).write_text (textwrap .dedent (source ))
111
112
112
113
# In case no extension is passed, we pick the pdf.
113
114
_image_ext = image_ext if image_ext else ".pdf"
114
- shutil .copy (TEST_RESOURCES / f"image{ _image_ext } " , tmp_path / f"image{ _image_ext } " )
115
115
116
- compile_pdf (tmp_path / "document.tex" , tmp_path / "bld" / "document.pdf" )
116
+ if file_exists :
117
+ shutil .copy (
118
+ TEST_RESOURCES / f"image{ _image_ext } " , tmp_path / f"image{ _image_ext } "
119
+ )
120
+ compile_pdf (tmp_path / "document.tex" , tmp_path / "bld" / "document.pdf" )
117
121
118
122
nodes = scan (tmp_path .joinpath ("document.tex" ))
119
123
120
- assert nodes == [
121
- tmp_path .joinpath ("document.tex" ),
122
- tmp_path .joinpath (f"image{ _image_ext } " ),
123
- ]
124
+ expected = [tmp_path .joinpath ("document.tex" )]
125
+ if has_extension or file_exists :
126
+ expected .append (tmp_path .joinpath (f"image{ _image_ext } " ))
127
+ else :
128
+ expected .extend (
129
+ [
130
+ (tmp_path / "image" ).with_suffix (suffix )
131
+ for suffix in COMMON_GRAPHICS_EXTENSIONS
132
+ ]
133
+ )
134
+
135
+ assert nodes == expected
124
136
125
137
126
138
@pytest .mark .end_to_end
127
- def test_includegraphics_without_extension_and_non_existent_file (tmp_path ):
128
- source = """
129
- \\ documentclass{article}
130
- \\ usepackage{graphicx}
131
- \\ begin{document}
132
- \\ includegraphics{image}
133
- \\ end{document}
139
+ def test_includegraphics_with_beamer_overlay (tmp_path ):
140
+ source = r"""
141
+ \documentclass{beamer}
142
+ \usepackage{graphicx}
143
+ \begin{document}
144
+ \begin{frame}
145
+ \includegraphics<1>{image.pdf}
146
+ \end{frame}
147
+ \end{document}
134
148
"""
135
149
tmp_path .joinpath ("document.tex" ).write_text (textwrap .dedent (source ))
136
150
137
151
nodes = scan (tmp_path .joinpath ("document.tex" ))
138
152
139
- expected = [tmp_path / "document.tex" ] + [
140
- (tmp_path / "image" ).with_suffix (suffix )
141
- for suffix in COMMON_GRAPHICS_EXTENSIONS
142
- ]
143
- assert nodes == expected
153
+ assert nodes == [tmp_path .joinpath ("document.tex" ), tmp_path .joinpath ("image.pdf" )]
144
154
145
155
146
156
@needs_latexmk
0 commit comments