parent
764ef3cbbe
commit
c61dc5bbe0
|
@ -5,6 +5,7 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from base64 import b64encode, b64decode
|
||||
from os.path import isfile
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
|
@ -159,8 +160,14 @@ class HTMLReport(object):
|
|||
href = None
|
||||
if extra.get('format') == extras.FORMAT_IMAGE:
|
||||
content = extra.get('content')
|
||||
if content.startswith(('file', 'http')) or \
|
||||
os.path.isfile(content):
|
||||
try:
|
||||
is_uri_or_path = (content.startswith(('file', 'http')) or
|
||||
isfile(content))
|
||||
except ValueError:
|
||||
# On Windows, os.path.isfile throws this exception when
|
||||
# passed a b64 encoded image.
|
||||
is_uri_or_path = False
|
||||
if is_uri_or_path:
|
||||
if self.self_contained:
|
||||
warnings.warn('Self-contained HTML report '
|
||||
'includes link to external '
|
||||
|
|
|
@ -326,6 +326,12 @@ class TestHTML:
|
|||
src = 'data:{0};base64,{1}'.format(mime_type, content)
|
||||
assert '<img src="{0}"/>'.format(src) in html
|
||||
|
||||
def test_extra_image_windows(self, mocker, testdir):
|
||||
mock_isfile = mocker.patch('pytest_html.plugin.isfile')
|
||||
mock_isfile.side_effect = ValueError('stat: path too long for Windows')
|
||||
self.test_extra_image(testdir, 'image/png', 'png')
|
||||
assert mock_isfile.call_count == 1
|
||||
|
||||
@pytest.mark.parametrize('content', [
|
||||
("u'\u0081'"),
|
||||
("'foo'"),
|
||||
|
|
Loading…
Reference in New Issue