mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-08-26 05:07:35 -05:00
* for PR#264: update CHANGES, add tests, small refactoring.
This commit is contained in:
@@ -163,6 +163,8 @@ Bugs fixed
|
|||||||
sub section number that is larger depth than `:tocdepth:` is shrinked.
|
sub section number that is larger depth than `:tocdepth:` is shrinked.
|
||||||
* PR#260: Encode underscore in citation labels for latex export. Thanks to
|
* PR#260: Encode underscore in citation labels for latex export. Thanks to
|
||||||
Lennart Fricke.
|
Lennart Fricke.
|
||||||
|
* PR#264: Fix could not resolve xref for figure node with :name: option.
|
||||||
|
Thanks to Takeshi Komiya.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|||||||
+9
-12
@@ -543,24 +543,21 @@ class StandardDomain(Domain):
|
|||||||
if node.tagname == 'section':
|
if node.tagname == 'section':
|
||||||
sectname = clean_astext(node[0]) # node[0] == title node
|
sectname = clean_astext(node[0]) # node[0] == title node
|
||||||
elif node.tagname == 'figure':
|
elif node.tagname == 'figure':
|
||||||
for n in node:
|
for n in node.traverse(nodes.caption):
|
||||||
if n.tagname == 'caption':
|
sectname = clean_astext(n)
|
||||||
sectname = clean_astext(n)
|
break
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
elif node.tagname == 'image' and node.parent.tagname == 'figure':
|
elif node.tagname == 'image' and node.parent.tagname == 'figure':
|
||||||
for n in node.parent:
|
for n in node.parent.traverse(nodes.caption):
|
||||||
if n.tagname == 'caption':
|
sectname = clean_astext(n)
|
||||||
sectname = clean_astext(n)
|
break
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
elif node.tagname == 'table':
|
elif node.tagname == 'table':
|
||||||
for n in node:
|
for n in node.traverse(nodes.title):
|
||||||
if n.tagname == 'title':
|
sectname = clean_astext(n)
|
||||||
sectname = clean_astext(n)
|
break
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
test_std_domain
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Tests the std domain
|
||||||
|
|
||||||
|
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
|
||||||
|
:license: BSD, see LICENSE for details.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from docutils import nodes
|
||||||
|
|
||||||
|
from sphinx.domains.std import StandardDomain
|
||||||
|
from util import mock
|
||||||
|
|
||||||
|
|
||||||
|
def test_process_doc_handle_figure_caption():
|
||||||
|
env = mock.Mock(domaindata={})
|
||||||
|
figure_node = nodes.figure(
|
||||||
|
'',
|
||||||
|
nodes.caption('caption text', 'caption text'),
|
||||||
|
)
|
||||||
|
document = mock.Mock(
|
||||||
|
nametypes={'testname': True},
|
||||||
|
nameids={'testname': 'testid'},
|
||||||
|
ids={'testid': figure_node},
|
||||||
|
)
|
||||||
|
|
||||||
|
domain = StandardDomain(env)
|
||||||
|
if 'testname' in domain.data['labels']:
|
||||||
|
del domain.data['labels']['testname']
|
||||||
|
domain.process_doc(env, 'testdoc', document)
|
||||||
|
assert 'testname' in domain.data['labels']
|
||||||
|
assert domain.data['labels']['testname'] == (
|
||||||
|
'testdoc', 'testid', 'caption text')
|
||||||
|
|
||||||
|
|
||||||
|
def test_process_doc_handle_image_parent_figure_caption():
|
||||||
|
env = mock.Mock(domaindata={})
|
||||||
|
img_node = nodes.image('', alt='image alt')
|
||||||
|
figure_node = nodes.figure(
|
||||||
|
'',
|
||||||
|
nodes.caption('caption text', 'caption text'),
|
||||||
|
img_node,
|
||||||
|
)
|
||||||
|
document = mock.Mock(
|
||||||
|
nametypes={'testname': True},
|
||||||
|
nameids={'testname': 'testid'},
|
||||||
|
ids={'testid': img_node},
|
||||||
|
)
|
||||||
|
|
||||||
|
domain = StandardDomain(env)
|
||||||
|
if 'testname' in domain.data['labels']:
|
||||||
|
del domain.data['labels']['testname']
|
||||||
|
domain.process_doc(env, 'testdoc', document)
|
||||||
|
assert 'testname' in domain.data['labels']
|
||||||
|
assert domain.data['labels']['testname'] == (
|
||||||
|
'testdoc', 'testid', 'caption text')
|
||||||
|
|
||||||
|
|
||||||
|
def test_process_doc_handle_table_title():
|
||||||
|
env = mock.Mock(domaindata={})
|
||||||
|
table_node = nodes.table(
|
||||||
|
'',
|
||||||
|
nodes.title('title text', 'title text'),
|
||||||
|
)
|
||||||
|
document = mock.Mock(
|
||||||
|
nametypes={'testname': True},
|
||||||
|
nameids={'testname': 'testid'},
|
||||||
|
ids={'testid': table_node},
|
||||||
|
)
|
||||||
|
|
||||||
|
domain = StandardDomain(env)
|
||||||
|
if 'testname' in domain.data['labels']:
|
||||||
|
del domain.data['labels']['testname']
|
||||||
|
domain.process_doc(env, 'testdoc', document)
|
||||||
|
assert 'testname' in domain.data['labels']
|
||||||
|
assert domain.data['labels']['testname'] == (
|
||||||
|
'testdoc', 'testid', 'title text')
|
||||||
@@ -23,6 +23,12 @@ from path import path
|
|||||||
|
|
||||||
from nose import tools, SkipTest
|
from nose import tools, SkipTest
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Python >=3.3
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'test_root', 'test_roots', 'raises', 'raises_msg',
|
'test_root', 'test_roots', 'raises', 'raises_msg',
|
||||||
@@ -30,6 +36,7 @@ __all__ = [
|
|||||||
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
'ListOutput', 'TestApp', 'with_app', 'gen_with_app',
|
||||||
'path', 'with_tempdir',
|
'path', 'with_tempdir',
|
||||||
'sprint', 'remove_unicode_literals',
|
'sprint', 'remove_unicode_literals',
|
||||||
|
'mock',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user