Fix #2012 exception occurred if `numfig_format` is invalid

This commit is contained in:
Takeshi KOMIYA
2015-11-30 11:38:37 +09:00
parent afcea49dc9
commit 47e7b022c2
4 changed files with 24 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ Release 1.3.3 (in development)
Bugs fixed
----------
* #2012: Fix exception occurred if ``numfig_format`` is invalid
Release 1.3.2 (released Nov 29, 2015)

View File

@@ -646,7 +646,12 @@ class StandardDomain(Domain):
if target == fully_normalize_name(title):
title = env.config.numfig_format.get(figtype, '')
newtitle = title % '.'.join(map(str, fignumber))
try:
newtitle = title % '.'.join(map(str, fignumber))
except TypeError:
env.warn(fromdocname, 'invalid numfig_format: %s' % title)
return None
return self.build_reference_node(fromdocname, builder,
docname, labelid, newtitle,
nodeclass=addnodes.number_reference,

View File

@@ -48,3 +48,5 @@ test-tocdepth
* Table.2.2 is :numref:`Table:%s <table22>`
* List.1 is :numref:`CODE_1`
* List.2.2 is :numref:`Code-%s <CODE22>`
* Invalid numfig_format 01: :numref:`invalid <fig1>`
* Invalid numfig_format 02: :numref:`Fig %s %s <fig1>`

View File

@@ -488,6 +488,9 @@ def test_tocdepth_singlehtml(app, status, warning):
def test_numfig_disabled(app, status, warning):
app.builder.build_all()
assert 'WARNING: invalid numfig_format: invalid' not in warning.getvalue()
assert 'WARNING: invalid numfig_format: Fig %s %s' not in warning.getvalue()
expects = {
'index.html': [
(".//div[@class='figure']/p[@class='caption']/"
@@ -547,6 +550,9 @@ def test_numfig_without_numbered_toctree(app, status, warning):
(app.srcdir / 'index.rst').write_text(index, encoding='utf-8')
app.builder.build_all()
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
expects = {
'index.html': [
(".//div[@class='figure']/p[@class='caption']/"
@@ -642,6 +648,9 @@ def test_numfig_without_numbered_toctree(app, status, warning):
def test_numfig_with_numbered_toctree(app, status, warning):
app.builder.build_all()
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
expects = {
'index.html': [
(".//div[@class='figure']/p[@class='caption']/"
@@ -740,6 +749,9 @@ def test_numfig_with_numbered_toctree(app, status, warning):
def test_numfig_with_prefix(app, status, warning):
app.builder.build_all()
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
expects = {
'index.html': [
(".//div[@class='figure']/p[@class='caption']/"
@@ -835,6 +847,9 @@ def test_numfig_with_prefix(app, status, warning):
def test_numfig_with_secnum_depth(app, status, warning):
app.builder.build_all()
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
expects = {
'index.html': [
(".//div[@class='figure']/p[@class='caption']/"