@@ -181,33 +181,7 @@ def create_asset(
181
181
def append_extra_html (self , extra , extra_index , test_index ):
182
182
href = None
183
183
if extra .get ("format" ) == extras .FORMAT_IMAGE :
184
- content = extra .get ("content" )
185
- try :
186
- is_uri_or_path = content .startswith (("file" , "http" )) or isfile (
187
- content
188
- )
189
- except ValueError :
190
- # On Windows, os.path.isfile throws this exception when
191
- # passed a b64 encoded image.
192
- is_uri_or_path = False
193
- if is_uri_or_path :
194
- if self .self_contained :
195
- warnings .warn (
196
- "Self-contained HTML report "
197
- "includes link to external "
198
- "resource: {}" .format (content )
199
- )
200
- html_div = html .a (html .img (src = content ), href = content )
201
- elif self .self_contained :
202
- src = "data:{};base64,{}" .format (extra .get ("mime_type" ), content )
203
- html_div = html .img (src = src )
204
- else :
205
- content = b64decode (content .encode ("utf-8" ))
206
- href = src = self .create_asset (
207
- content , extra_index , test_index , extra .get ("extension" ), "wb"
208
- )
209
- html_div = html .a (html .img (src = src ), href = href )
210
- self .additional_html .append (html .div (html_div , class_ = "image" ))
184
+ self ._append_image (extra , extra_index , test_index )
211
185
212
186
elif extra .get ("format" ) == extras .FORMAT_HTML :
213
187
self .additional_html .append (html .div (raw (extra .get ("content" ))))
@@ -279,8 +253,9 @@ def append_log_html(self, report, additional_html):
279
253
log .append ("No log output captured." )
280
254
additional_html .append (log )
281
255
282
- def _append_video (self , extra , extra_index , test_index ):
283
- video_base = '<video controls><source src="{}" type="video/mp4"></video>'
256
+ def _make_media_html_div (
257
+ self , extra , extra_index , test_index , base_extra_string , base_extra_class
258
+ ):
284
259
content = extra .get ("content" )
285
260
try :
286
261
is_uri_or_path = content .startswith (("file" , "http" )) or isfile (content )
@@ -293,20 +268,35 @@ def _append_video(self, extra, extra_index, test_index):
293
268
warnings .warn (
294
269
"Self-contained HTML report "
295
270
"includes link to external "
296
- "resource: {}" . format ( content )
271
+ f "resource: { content } "
297
272
)
298
273
299
- html_div = html .div (raw (video_base .format (extra .get ("content" ))))
274
+ html_div = html .a (
275
+ raw (base_extra_string .format (extra .get ("content" ))), href = content
276
+ )
300
277
elif self .self_contained :
301
- src = "data:{};base64,{}" . format ( extra .get (" mime_type" ), content )
302
- html_div = html . div ( raw (video_base .format (src ) ))
278
+ src = f "data:{ extra .get (' mime_type' ) } ;base64, { content } "
279
+ html_div = raw (base_extra_string .format (src ))
303
280
else :
304
281
content = b64decode (content .encode ("utf-8" ))
305
282
href = src = self .create_asset (
306
283
content , extra_index , test_index , extra .get ("extension" ), "wb"
307
284
)
285
+ html_div = html .a (class_ = base_extra_class , target = "_blank" , href = href )
286
+ return html_div
287
+
288
+ def _append_image (self , extra , extra_index , test_index ):
289
+ image_base = '<img src="{}"/>'
290
+ html_div = self ._make_media_html_div (
291
+ extra , extra_index , test_index , image_base , "image"
292
+ )
293
+ self .additional_html .append (html .div (html_div , class_ = "image" ))
308
294
309
- html_div = html .a (video_base .format (src ), href = href )
295
+ def _append_video (self , extra , extra_index , test_index ):
296
+ video_base = '<video controls><source src="{}" type="video/mp4"></video>'
297
+ html_div = self ._make_media_html_div (
298
+ extra , extra_index , test_index , video_base , "video"
299
+ )
310
300
self .additional_html .append (html .div (html_div , class_ = "video" ))
311
301
312
302
def _appendrow (self , outcome , report ):
0 commit comments