mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix #1325 and add test_find_empty_alt
This commit is contained in:
parent
6008f7e2ed
commit
6f9f0def0f
2 changed files with 25 additions and 2 deletions
|
|
@ -584,7 +584,7 @@ def find_empty_alt(content, path):
|
||||||
# src before alt
|
# src before alt
|
||||||
<img
|
<img
|
||||||
[^\>]*
|
[^\>]*
|
||||||
src=(['"])(.*)\1
|
src=(['"])(.*?)\1
|
||||||
[^\>]*
|
[^\>]*
|
||||||
alt=(['"])\3
|
alt=(['"])\3
|
||||||
)|(?:
|
)|(?:
|
||||||
|
|
@ -593,7 +593,7 @@ def find_empty_alt(content, path):
|
||||||
[^\>]*
|
[^\>]*
|
||||||
alt=(['"])\4
|
alt=(['"])\4
|
||||||
[^\>]*
|
[^\>]*
|
||||||
src=(['"])(.*)\5
|
src=(['"])(.*?)\5
|
||||||
)
|
)
|
||||||
""", re.X)
|
""", re.X)
|
||||||
for match in re.findall(imgs, content):
|
for match in re.findall(imgs, content):
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,13 @@ from pelican import readers
|
||||||
from pelican.tests.support import get_settings, unittest
|
from pelican.tests.support import get_settings, unittest
|
||||||
from pelican.utils import SafeDatetime
|
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__)
|
CUR_DIR = os.path.dirname(__file__)
|
||||||
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
||||||
|
|
@ -81,6 +88,22 @@ class DefaultReaderTest(ReaderTest):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
self.read_file(path='article_with_metadata.unknownextension')
|
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):
|
class RstReaderTest(ReaderTest):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue