Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
test.test_transforms.test_hyperlinks.py Maven / Gradle / Ivy
#! /usr/bin/env python
# $Id: test_hyperlinks.py 4564 2006-05-21 20:44:42Z wiemann $
# Author: David Goodger
# Copyright: This module has been placed in the public domain.
"""
Tests for docutils.transforms.references.Hyperlinks.
"""
from __init__ import DocutilsTestSupport
from docutils.transforms.references import PropagateTargets, \
AnonymousHyperlinks, IndirectHyperlinks, ExternalTargets, \
InternalTargets, DanglingReferences
from docutils.parsers.rst import Parser
def suite():
parser = Parser()
s = DocutilsTestSupport.TransformTestSuite(parser)
s.generateTests(totest)
return s
totest = {}
# Exhaustive listing of hyperlink variations: every combination of
# target/reference, direct/indirect, internal/external, and named/anonymous,
# plus embedded URIs.
totest['exhaustive_hyperlinks'] = ((PropagateTargets, AnonymousHyperlinks,
IndirectHyperlinks,
ExternalTargets, InternalTargets,
DanglingReferences), [
["""\
direct_ external
.. _direct: http://direct
""",
"""\
direct
external
"""],
["""\
indirect_ external
.. _indirect: xtarget_
.. _xtarget: http://indirect
""",
"""\
indirect
external
"""],
["""\
.. _direct:
direct_ internal
""",
"""\
direct
internal
"""],
["""\
.. _ztarget:
indirect_ internal
.. _indirect2: ztarget_
.. _indirect: indirect2_
""",
"""\
indirect
internal
"""],
["""\
Implicit
--------
indirect_ internal
.. _indirect: implicit_
""",
"""\
Implicit
indirect
internal
"""],
["""\
Implicit
--------
`multiply-indirect`_ internal
.. _multiply-indirect: indirect_
.. _indirect: implicit_
""",
"""\
Implicit
multiply-indirect
internal
"""],
["""\
circular_ indirect reference
.. _circular: indirect_
.. _indirect: circular_
""",
"""\
circular_
indirect reference
.. _indirect: circular_
Indirect hyperlink target "circular" (id="circular") refers to target "indirect", forming a circular reference.
"""],
["""\
Implicit
--------
Duplicate implicit targets.
Implicit
--------
indirect_ internal
.. _indirect: implicit_
Direct internal reference: Implicit_
""",
"""\
Implicit
Duplicate implicit targets.
Implicit
Duplicate implicit target name: "implicit".
indirect_
internal
Direct internal reference:
Implicit_
Indirect hyperlink target "indirect" (id="indirect") refers to target "implicit", which is a duplicate, and cannot be used as a unique reference.
Duplicate target name, cannot be used as a unique reference: "implicit".
"""],
["""\
`direct external`__
__ http://direct
""",
"""\
direct external
"""],
["""\
`indirect external`__
__ xtarget_
.. _xtarget: http://indirect
""",
"""\
indirect external
"""],
["""\
__
`direct internal`__
""",
"""\
direct internal
"""],
["""\
.. _ztarget:
`indirect internal`__
__ ztarget_
""",
"""\
indirect internal
"""],
["""\
.. _ztarget:
First
.. _ztarget:
Second
`indirect internal`__
__ ztarget_
""",
"""\
First
Duplicate explicit target name: "ztarget".
Second
`indirect internal`__
Indirect hyperlink target (id="id2") refers to target "ztarget", which is a duplicate, and cannot be used as a unique reference.
"""],
["""\
The next anonymous hyperlink reference is parsed (and discarded) at
some point, but nonetheless anonymous hyperlink references and targets
match in this snippet.
.. |invalid| replace:: anonymous__
hyperlink__
__ URL
""",
"""\
The next anonymous hyperlink reference is parsed (and discarded) at
some point, but nonetheless anonymous hyperlink references and targets
match in this snippet.
Substitution definition contains illegal element:
anonymous
.. |invalid| replace:: anonymous__
hyperlink
"""],
["""\
An `embedded uri `_.
Another reference to the same `embedded URI`_.
""",
"""\
An \n\
embedded uri
.
Another reference to the same \n\
embedded URI
.
"""],
["""\
An `anonymous embedded uri `__.
""",
"""\
An \n\
anonymous embedded uri
.
"""],
["""\
.. _target:
.. [1] Footnote; target_
""",
"""\
1
Footnote; \n\
target
"""],
["""\
.. _target:
.. [cit] Citation; target_
""",
"""\
cit
Citation; \n\
target
"""],
])
totest['hyperlinks'] = ((PropagateTargets, AnonymousHyperlinks,
IndirectHyperlinks, ExternalTargets,
InternalTargets, DanglingReferences), [
["""\
.. _internal hyperlink:
This paragraph referenced.
By this `internal hyperlink`_ reference.
""",
"""\
This paragraph referenced.
By this \n\
internal hyperlink
reference.
"""],
["""\
.. _chained:
.. _internal hyperlink:
This paragraph referenced.
By this `internal hyperlink`_ reference
as well as by this chained_ reference.
The results of the transform are not visible at the XML level.
""",
"""\
This paragraph referenced.
By this \n\
internal hyperlink
reference
as well as by this \n\
chained
reference.
The results of the transform are not visible at the XML level.
"""],
["""\
.. _chained:
__ http://anonymous
Anonymous__ and chained_ both refer to the same URI.
""",
"""\
Anonymous
and \n\
chained
both refer to the same URI.
"""],
["""\
.. _a:
.. _b:
x
""",
"""\
x
Hyperlink target "a" is not referenced.
Hyperlink target "b" is not referenced.
"""],
["""\
.. _a:
.. _b:
a_
""",
"""\
a
Hyperlink target "b" is not referenced.
"""],
["""\
.. _a:
.. _b:
b_
""",
"""\
b
Hyperlink target "a" is not referenced.
"""],
["""\
.. _a:
.. _b:
a_\ b_
""",
"""\
a
b
"""],
["""\
.. _external hyperlink: http://uri
`External hyperlink`_ reference.
""",
"""\
External hyperlink
reference.
"""],
["""\
.. _external hyperlink: http://uri
.. _indirect target: `external hyperlink`_
""",
"""\
Hyperlink target "indirect target" is not referenced.
"""],
["""\
.. _chained:
.. _external hyperlink: http://uri
`External hyperlink`_ reference
and a chained_ reference too.
""",
"""\
External hyperlink
reference
and a \n\
chained
reference too.
"""],
["""\
.. _external hyperlink: http://uri
.. _indirect hyperlink: `external hyperlink`_
`Indirect hyperlink`_ reference.
""",
"""\
Indirect hyperlink
reference.
"""],
["""\
.. _external hyperlink: http://uri
.. _chained:
.. _indirect hyperlink: `external hyperlink`_
Chained_ `indirect hyperlink`_ reference.
""",
"""\
Chained
\n\
indirect hyperlink
reference.
"""],
["""\
.. __: http://full
__
__ http://simplified
.. _external: http://indirect.external
__ external_
__
`Full syntax anonymous external hyperlink reference`__,
`chained anonymous external reference`__,
`simplified syntax anonymous external hyperlink reference`__,
`indirect anonymous hyperlink reference`__,
`internal anonymous hyperlink reference`__.
""",
"""\
Full syntax anonymous external hyperlink reference
,
chained anonymous external reference
,
simplified syntax anonymous external hyperlink reference
,
indirect anonymous hyperlink reference
,
internal anonymous hyperlink reference
.
"""],
["""\
Duplicate external target_'s (different URIs):
.. _target: first
.. _target: second
""",
"""\
Duplicate external \n\
target_
's (different URIs):
Duplicate explicit target name: "target".
Duplicate target name, cannot be used as a unique reference: "target".
"""],
["""\
Duplicate external targets (different URIs) without reference:
.. _target: first
.. _target: second
""",
"""\
Duplicate external targets (different URIs) without reference:
Duplicate explicit target name: "target".
"""],
["""\
Several__ anonymous__ hyperlinks__, but not enough targets.
__ http://example.org
""",
"""\
Several__
\n\
anonymous__
\n\
hyperlinks__
, but not enough targets.
Anonymous hyperlink mismatch: 3 references but 1 targets.
See "backrefs" attribute for IDs.
"""],
["""\
.. _external: http://uri
.. _indirect: external_
.. _internal:
.. image:: picture.png
:target: external_
.. image:: picture.png
:target: indirect_
.. image:: picture.png
:target: internal_
""",
"""\
"""],
["""\
.. contents:: Table of Contents
.. _indirect reference to the table of contents: `table of contents`_
Section
=======
Testing an `indirect reference to the table of contents`_.
""",
"""\
Table of Contents
Section