summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 13:20:49 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 13:20:49 +0000
commit6150a8dfd9f99865e48098ee3ef7953a5d02ed7b (patch)
treea0cbcaae7295d322f1479a29f020f169b9dcd98b
parente1998a914a538b41956951572b80c098c0293d22 (diff)
downloaddocutils-6150a8dfd9f99865e48098ee3ef7953a5d02ed7b.tar.gz
Fix [ 3606028 ] ``assert`` is skipped with ``python -O``.
Also, raise ValueError with list of valid units if length_or_percentage_or_unitless() fails. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7621 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--HISTORY.txt4
-rw-r--r--docutils/parsers/rst/directives/__init__.py9
-rwxr-xr-xtest/test_parsers/test_rst/test_directives/test_images.py16
3 files changed, 26 insertions, 3 deletions
diff --git a/HISTORY.txt b/HISTORY.txt
index 544a23268..eb9bb8f60 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -25,6 +25,10 @@ Changes Since 0.10
- Fix [ 3601607 ] node.__repr__() must return `str` instance.
+* docutils/parsers/rst/directives/__init__.py
+
+ - Fix [ 3606028 ] ``assert`` is skipped with ``python -O``.
+
* docutils/parsers/rst/directives/images.py
- Apply [ 3599485 ] node source/line information for sphinx translation.
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
index fdc70d70f..ee919dd6f 100644
--- a/docutils/parsers/rst/directives/__init__.py
+++ b/docutils/parsers/rst/directives/__init__.py
@@ -232,9 +232,8 @@ def get_measure(argument, units):
"""
match = re.match(r'^([0-9.]+) *(%s)$' % '|'.join(units), argument)
try:
- assert match is not None
float(match.group(1))
- except (AssertionError, ValueError):
+ except (AttributeError, ValueError):
raise ValueError(
'not a positive measure of one of the following units:\n%s'
% ' '.join(['"%s"' % i for i in units]))
@@ -262,7 +261,11 @@ def length_or_percentage_or_unitless(argument, default=''):
try:
return get_measure(argument, length_units + ['%'])
except ValueError:
- return get_measure(argument, ['']) + default
+ try:
+ return get_measure(argument, ['']) + default
+ except ValueError:
+ # raise ValueError with list of valid units:
+ return get_measure(argument, length_units + ['%'])
def class_option(argument):
"""
diff --git a/test/test_parsers/test_rst/test_directives/test_images.py b/test/test_parsers/test_rst/test_directives/test_images.py
index 67d898eb4..ea3adfa8f 100755
--- a/test/test_parsers/test_rst/test_directives/test_images.py
+++ b/test/test_parsers/test_rst/test_directives/test_images.py
@@ -164,6 +164,22 @@ totest['images'] = [
"""],
["""\
.. image:: picture.png
+ :width: 20mc
+""",
+"""\
+<document source="test data">
+ <system_message level="3" line="1" source="test data" type="ERROR">
+ <paragraph>
+ Error in "image" directive:
+ invalid option value: (option: "width"; value: \'20mc\')
+ not a positive measure of one of the following units:
+ "em" "ex" "px" "in" "cm" "mm" "pt" "pc" "%".
+ <literal_block xml:space="preserve">
+ .. image:: picture.png
+ :width: 20mc
+"""],
+["""\
+.. image:: picture.png
:height: 100
:width: 200
:scale: 50