1
0
Fork 0
forked from github/pelican

Merge pull request #1354 from storeyio/1325

Add test_find_empty_alt. Fixes #1325
This commit is contained in:
Justin Mayer 2016-11-18 09:22:56 -07:00 committed by GitHub
commit ca10933082
2 changed files with 25 additions and 2 deletions

View file

@ -584,7 +584,7 @@ def find_empty_alt(content, path):
# src before alt
<img
[^\>]*
src=(['"])(.*)\1
src=(['"])(.*?)\1
[^\>]*
alt=(['"])\3
)|(?:
@ -593,7 +593,7 @@ def find_empty_alt(content, path):
[^\>]*
alt=(['"])\4
[^\>]*
src=(['"])(.*)\5
src=(['"])(.*?)\5
)
""", re.X)
for match in re.findall(imgs, content):

View file

@ -9,6 +9,13 @@ from pelican import readers
from pelican.tests.support import get_settings, unittest
from pelican.utils import SafeDatetime
try:
from unittest.mock import patch
except ImportError:
try:
from mock import patch
except ImportError:
patch = False
CUR_DIR = os.path.dirname(__file__)
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
@ -81,6 +88,22 @@ class DefaultReaderTest(ReaderTest):
with self.assertRaises(TypeError):
self.read_file(path='article_with_metadata.unknownextension')
@unittest.skipUnless(patch, 'Needs Mock module')
def test_find_empty_alt(self):
with patch('pelican.readers.logger') as log_mock:
content = ['<img alt="" src="test-image.png" width="300px" />',
'<img src="test-image.png" width="300px" alt="" />']
for tag in content:
readers.find_empty_alt(tag, '/test/path')
log_mock.warning.assert_called_with(
u'Empty alt attribute for image %s in %s',
u'test-image.png',
u'/test/path',
extra={'limit_msg':
'Other images have empty alt attributes'}
)
class RstReaderTest(ReaderTest):