From 353a265989dc650288be092e359d48e09aad5718 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Mon, 21 Dec 2009 23:24:33 +1100 Subject: [PATCH 1/8] attempt at test suite number 1 - this one doesn't seem to generate any metadata --- tests/root/contents.txt | 1 + tests/test_metadata.py | 143 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/test_metadata.py diff --git a/tests/root/contents.txt b/tests/root/contents.txt index 9891c64ef..6133f8873 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -21,6 +21,7 @@ Contents: math autodoc autosummary + metadata Python diff --git a/tests/test_metadata.py b/tests/test_metadata.py new file mode 100644 index 000000000..7da544a6a --- /dev/null +++ b/tests/test_metadata.py @@ -0,0 +1,143 @@ +# -*- coding: utf-8 -*- +""" + test_metadata + ~~~~~~~~~~~~~ + + Test our ahndling of metadata in files with bibliographic metadata + + :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + + + +# adapted from an example of bibliographic metadata at http://docutils.sourceforge.net/docs/user/rst/demo.txt +BIBLIOGRAPHIC_FIELDS_REST = """:Author: David Goodger +:Address: 123 Example Street + Example, EX Canada + A1B 2C3 +:Contact: goodger@python.org +:Authors: Me; Myself; I +:organization: humankind +:date: $Date: 2006-05-21 22:44:42 +0200 (Son, 21 Mai 2006) $ +:status: This is a "work in progress" +:revision: $Revision: 4564 $ +:version: 1 +:copyright: This document has been placed in the public domain. You + may do with it as you wish. You may copy, modify, + redistribute, reattribute, sell, buy, rent, lease, + destroy, or improve it, quote it at length, excerpt, + incorporate, collate, fold, staple, or mutilate it, or do + anything else to it that your or anyone else's heart + desires. +:field name: This is a generic bibliographic field. +:field name 2: + Generic bibliographic fields may contain multiple body elements. + + Like this. + +:Dedication: + + For Docutils users & co-developers. + +:abstract: + + This document is a demonstration of the reStructuredText markup + language, containing examples of all basic reStructuredText + constructs and many advanced constructs. + +.. meta:: + :keywords: reStructuredText, demonstration, demo, parser + :description lang=en: A demonstration of the reStructuredText + markup language, containing examples of all basic + constructs and many advanced constructs. + +================================ +reStructuredText Demonstration +================================ + +Above is the document title. +""" + +import re + +from util import * + +from docutils import frontend, utils, nodes +from docutils.parsers import rst + +from sphinx import addnodes +from sphinx.util import texescape +from sphinx.writers.html import HTMLWriter, SmartyPantsHTMLTranslator +from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator + +def setup_module(): + global app, settings, parser + texescape.init() # otherwise done by the latex builder + app = TestApp(cleanenv=True) + optparser = frontend.OptionParser( + components=(rst.Parser, HTMLWriter, LaTeXWriter)) + settings = optparser.get_default_values() + settings.env = app.builder.env + parser = rst.Parser() + +def teardown_module(): + app.cleanup() + +# since we're not resolving the markup afterwards, these nodes may remain +class ForgivingTranslator: + def visit_pending_xref(self, node): + pass + def depart_pending_xref(self, node): + pass + +class ForgivingHTMLTranslator(SmartyPantsHTMLTranslator, ForgivingTranslator): + pass + +class ForgivingLaTeXTranslator(LaTeXTranslator, ForgivingTranslator): + pass + + +def verify_re(rst, html_expected, latex_expected): + document = utils.new_document('test data', settings) + document['file'] = 'dummy' + parser.parse(rst, document) + for msg in document.traverse(nodes.system_message): + if msg['level'] == 1: + msg.replace_self([]) + + if html_expected: + html_translator = ForgivingHTMLTranslator(app.builder, document) + document.walkabout(html_translator) + html_translated = ''.join(html_translator.fragment).strip() + assert re.match(html_expected, html_translated), 'from' + rst + + if latex_expected: + latex_translator = ForgivingLaTeXTranslator(document, app.builder) + latex_translator.first_document = -1 # don't write \begin{document} + document.walkabout(latex_translator) + latex_translated = ''.join(latex_translator.body).strip() + assert re.match(latex_expected, latex_translated), 'from ' + repr(rst) + +def verify(rst, html_expected, latex_expected): + if html_expected: + html_expected = re.escape(html_expected) + '$' + if latex_expected: + latex_expected = re.escape(latex_expected) + '$' + verify_re(rst, html_expected, latex_expected) + + +def test_bibliographic_fields(): + # correct parsing of doc metadata + document = utils.new_document('test data', settings) + document['file'] = 'dummy' + parser.parse(BIBLIOGRAPHIC_FIELDS_REST, document) + import pdb; pdb.set_trace() + for msg in document.traverse(nodes.system_message): + if msg['level'] == 1: + msg.replace_self([]) + _html = ('

' + 'code   sample

') + yield verify, '``code sample``', _html, '\\code{code sample}' + yield verify, ':samp:`code sample`', _html, '\\samp{code sample}' + From 5484efed31327cf0f796b09fe979c1a4ef74f665 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Mon, 21 Dec 2009 23:40:44 +1100 Subject: [PATCH 2/8] using test_environment as a test example, I get closer, but it turns out that I have no metadata at all where I expect it --- tests/root/metadata.txt | 55 +++++++++++++++++++++ tests/test_metadata.py | 103 ++++++++++++---------------------------- 2 files changed, 86 insertions(+), 72 deletions(-) create mode 100644 tests/root/metadata.txt diff --git a/tests/root/metadata.txt b/tests/root/metadata.txt new file mode 100644 index 000000000..8eceb9e04 --- /dev/null +++ b/tests/root/metadata.txt @@ -0,0 +1,55 @@ +.. This is a comment. Note how any initial comments are moved by + transforms to after the document title, subtitle, and docinfo. + +================================ + reStructuredText Demonstration +================================ + +.. Above is the document title, and below is the subtitle. + They are transformed from section titles after parsing. + +-------------------------------- + Examples of Syntax Constructs +-------------------------------- + +.. bibliographic fields (which also require a transform): + +:Author: David Goodger +:Address: 123 Example Street + Example, EX Canada + A1B 2C3 +:Contact: goodger@python.org +:Authors: Me; Myself; I +:organization: humankind +:date: $Date: 2006-05-21 22:44:42 +0200 (Son, 21 Mai 2006) $ +:status: This is a "work in progress" +:revision: $Revision: 4564 $ +:version: 1 +:copyright: This document has been placed in the public domain. You + may do with it as you wish. You may copy, modify, + redistribute, reattribute, sell, buy, rent, lease, + destroy, or improve it, quote it at length, excerpt, + incorporate, collate, fold, staple, or mutilate it, or do + anything else to it that your or anyone else's heart + desires. +:field name: This is a generic bibliographic field. +:field name 2: + Generic bibliographic fields may contain multiple body elements. + + Like this. + +:Dedication: + + For Docutils users & co-developers. + +:abstract: + + This document is a demonstration of the reStructuredText markup + language, containing examples of all basic reStructuredText + constructs and many advanced constructs. + +.. meta:: + :keywords: reStructuredText, demonstration, demo, parser + :description lang=en: A demonstration of the reStructuredText + markup language, containing examples of all basic + constructs and many advanced constructs. diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 7da544a6a..a490e6828 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -59,85 +59,44 @@ reStructuredText Demonstration Above is the document title. """ -import re - from util import * -from docutils import frontend, utils, nodes -from docutils.parsers import rst +from sphinx.environment import BuildEnvironment +from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.builders.latex import LaTeXBuilder -from sphinx import addnodes -from sphinx.util import texescape -from sphinx.writers.html import HTMLWriter, SmartyPantsHTMLTranslator -from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator +app = env = None +warnings = [] def setup_module(): - global app, settings, parser - texescape.init() # otherwise done by the latex builder - app = TestApp(cleanenv=True) - optparser = frontend.OptionParser( - components=(rst.Parser, HTMLWriter, LaTeXWriter)) - settings = optparser.get_default_values() - settings.env = app.builder.env - parser = rst.Parser() + global app, env + app = TestApp(srcdir='(temp)') + env = BuildEnvironment(app.srcdir, app.doctreedir, app.config) + env.set_warnfunc(lambda *args: warnings.append(args)) + msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app) + for docname in it: + pass def teardown_module(): app.cleanup() -# since we're not resolving the markup afterwards, these nodes may remain -class ForgivingTranslator: - def visit_pending_xref(self, node): - pass - def depart_pending_xref(self, node): - pass - -class ForgivingHTMLTranslator(SmartyPantsHTMLTranslator, ForgivingTranslator): - pass - -class ForgivingLaTeXTranslator(LaTeXTranslator, ForgivingTranslator): - pass - - -def verify_re(rst, html_expected, latex_expected): - document = utils.new_document('test data', settings) - document['file'] = 'dummy' - parser.parse(rst, document) - for msg in document.traverse(nodes.system_message): - if msg['level'] == 1: - msg.replace_self([]) - - if html_expected: - html_translator = ForgivingHTMLTranslator(app.builder, document) - document.walkabout(html_translator) - html_translated = ''.join(html_translator.fragment).strip() - assert re.match(html_expected, html_translated), 'from' + rst - - if latex_expected: - latex_translator = ForgivingLaTeXTranslator(document, app.builder) - latex_translator.first_document = -1 # don't write \begin{document} - document.walkabout(latex_translator) - latex_translated = ''.join(latex_translator.body).strip() - assert re.match(latex_expected, latex_translated), 'from ' + repr(rst) - -def verify(rst, html_expected, latex_expected): - if html_expected: - html_expected = re.escape(html_expected) + '$' - if latex_expected: - latex_expected = re.escape(latex_expected) + '$' - verify_re(rst, html_expected, latex_expected) - - -def test_bibliographic_fields(): - # correct parsing of doc metadata - document = utils.new_document('test data', settings) - document['file'] = 'dummy' - parser.parse(BIBLIOGRAPHIC_FIELDS_REST, document) - import pdb; pdb.set_trace() - for msg in document.traverse(nodes.system_message): - if msg['level'] == 1: - msg.replace_self([]) - _html = ('

' - 'code   sample

') - yield verify, '``code sample``', _html, '\\code{code sample}' - yield verify, ':samp:`code sample`', _html, '\\samp{code sample}' +def test_second_update(): + # delete, add and "edit" (change saved mtime) some files and update again + env.all_docs['contents'] = 0 + root = path(app.srcdir) + # important: using "autodoc" because it is the last one to be included in + # the contents.txt toctree; otherwise section numbers would shift + (root / 'autodoc.txt').unlink() + (root / 'new.txt').write_text('New file\n========\n') + msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app) + assert '1 added, 3 changed, 1 removed' in msg + docnames = set() + for docname in it: + docnames.add(docname) + # "includes" and "images" are in there because they contain references + # to nonexisting downloadable or image files, which are given another + # chance to exist + assert docnames == set(['contents', 'new', 'includes', 'images']) + assert 'autodoc' not in env.all_docs + assert 'autodoc' not in env.found_docs From eef9ea3b7308edc7a4e8d20744c3ec4a10bfd514 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Mon, 21 Dec 2009 23:43:06 +1100 Subject: [PATCH 3/8] only deal with metadata in the place sphinx expects it - at the head of the document --- tests/root/metadata.txt | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/root/metadata.txt b/tests/root/metadata.txt index 8eceb9e04..9b3044ba8 100644 --- a/tests/root/metadata.txt +++ b/tests/root/metadata.txt @@ -1,19 +1,3 @@ -.. This is a comment. Note how any initial comments are moved by - transforms to after the document title, subtitle, and docinfo. - -================================ - reStructuredText Demonstration -================================ - -.. Above is the document title, and below is the subtitle. - They are transformed from section titles after parsing. - --------------------------------- - Examples of Syntax Constructs --------------------------------- - -.. bibliographic fields (which also require a transform): - :Author: David Goodger :Address: 123 Example Street Example, EX Canada @@ -53,3 +37,17 @@ :description lang=en: A demonstration of the reStructuredText markup language, containing examples of all basic constructs and many advanced constructs. + +================================ + reStructuredText Demonstration +================================ + +.. Above is the document title, and below is the subtitle. + They are transformed from section titles after parsing. + +-------------------------------- + Examples of Syntax Constructs +-------------------------------- + +.. bibliographic fields (which also require a transform): + From 87196a2523bc055acbe03c3ede6c9b69620196f4 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Tue, 22 Dec 2009 00:06:25 +1100 Subject: [PATCH 4/8] working tests for docinfo metadata --- tests/test_metadata.py | 83 ++++++++---------------------------------- 1 file changed, 16 insertions(+), 67 deletions(-) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index a490e6828..d106fcc42 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -12,55 +12,11 @@ # adapted from an example of bibliographic metadata at http://docutils.sourceforge.net/docs/user/rst/demo.txt -BIBLIOGRAPHIC_FIELDS_REST = """:Author: David Goodger -:Address: 123 Example Street - Example, EX Canada - A1B 2C3 -:Contact: goodger@python.org -:Authors: Me; Myself; I -:organization: humankind -:date: $Date: 2006-05-21 22:44:42 +0200 (Son, 21 Mai 2006) $ -:status: This is a "work in progress" -:revision: $Revision: 4564 $ -:version: 1 -:copyright: This document has been placed in the public domain. You - may do with it as you wish. You may copy, modify, - redistribute, reattribute, sell, buy, rent, lease, - destroy, or improve it, quote it at length, excerpt, - incorporate, collate, fold, staple, or mutilate it, or do - anything else to it that your or anyone else's heart - desires. -:field name: This is a generic bibliographic field. -:field name 2: - Generic bibliographic fields may contain multiple body elements. - - Like this. - -:Dedication: - - For Docutils users & co-developers. - -:abstract: - - This document is a demonstration of the reStructuredText markup - language, containing examples of all basic reStructuredText - constructs and many advanced constructs. - -.. meta:: - :keywords: reStructuredText, demonstration, demo, parser - :description lang=en: A demonstration of the reStructuredText - markup language, containing examples of all basic - constructs and many advanced constructs. - -================================ -reStructuredText Demonstration -================================ - -Above is the document title. -""" from util import * +from nose.tools import assert_equals + from sphinx.environment import BuildEnvironment from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.latex import LaTeXBuilder @@ -69,10 +25,12 @@ app = env = None warnings = [] def setup_module(): + # Is there a better way of generating this doctree than manually iterating? global app, env app = TestApp(srcdir='(temp)') env = BuildEnvironment(app.srcdir, app.doctreedir, app.config) - env.set_warnfunc(lambda *args: warnings.append(args)) + # Huh. Why do I need to do this? + env.set_warnfunc(lambda *args: warnings.append(args)) msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app) for docname in it: pass @@ -80,23 +38,14 @@ def setup_module(): def teardown_module(): app.cleanup() - -def test_second_update(): - # delete, add and "edit" (change saved mtime) some files and update again - env.all_docs['contents'] = 0 - root = path(app.srcdir) - # important: using "autodoc" because it is the last one to be included in - # the contents.txt toctree; otherwise section numbers would shift - (root / 'autodoc.txt').unlink() - (root / 'new.txt').write_text('New file\n========\n') - msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app) - assert '1 added, 3 changed, 1 removed' in msg - docnames = set() - for docname in it: - docnames.add(docname) - # "includes" and "images" are in there because they contain references - # to nonexisting downloadable or image files, which are given another - # chance to exist - assert docnames == set(['contents', 'new', 'includes', 'images']) - assert 'autodoc' not in env.all_docs - assert 'autodoc' not in env.found_docs +def test_docinfo(): + exampledocinfo = env.metadata['metadata'] + expected_metadata = { + 'author': u'David Goodger', + u'field name': u'This is a generic bibliographic field.', + u'field name 2': u'Generic bibliographic fields may contain multiple body elements.\n\nLike this.'} + # I like this way of comparing dicts - easier to see the error. + for key in exampledocinfo: + yield assert_equals, exampledocinfo[key], expected_metadata[key] + #but then we still have to check for missing keys + yield assert_equals, expected_metadata.keys(), exampledocinfo.keys() From 55059117cb8ba0e1555acb06a3a8484882810a77 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Tue, 22 Dec 2009 16:35:30 +1100 Subject: [PATCH 5/8] handle key ordering silliness in tests --- tests/test_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index d106fcc42..481e35af9 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -48,4 +48,4 @@ def test_docinfo(): for key in exampledocinfo: yield assert_equals, exampledocinfo[key], expected_metadata[key] #but then we still have to check for missing keys - yield assert_equals, expected_metadata.keys(), exampledocinfo.keys() + yield assert_equals, set(expected_metadata.keys()), set(exampledocinfo.keys()) From d532fc2d9f035ec3024abee4ed424d570c6a89bc Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Tue, 22 Dec 2009 16:49:40 +1100 Subject: [PATCH 6/8] sphinx now preserves lots of useful document metadata --- sphinx/environment.py | 11 +++++++---- tests/test_metadata.py | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/sphinx/environment.py b/sphinx/environment.py index d4f16819b..64c745a79 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -757,6 +757,7 @@ class BuildEnvironment: def process_metadata(self, docname, doctree): """ Process the docinfo part of the doctree as metadata. + Keep processing minimal - just return what docutils says. """ self.metadata[docname] = md = {} try: @@ -768,10 +769,12 @@ class BuildEnvironment: # nothing to see here return for node in docinfo: - if node.__class__ is nodes.author: - # handled specially by docutils - md['author'] = node.astext() - elif node.__class__ is nodes.field: + # nodes are multiply inherited... + if isinstance(node, nodes.authors): + md['authors'] = [author.astext() for author in node] + elif isinstance(node, nodes.TextElement): #e.g. author + md[node.__class__.__name__] = node.astext() + else: name, body = node md[name.astext()] = body.astext() del doctree[0] diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 481e35af9..ea41fc11d 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -39,13 +39,29 @@ def teardown_module(): app.cleanup() def test_docinfo(): + """ + inspect the 'docinfo' metadata stored in the first node of the document. + Note this doesn't give us access to data stored in subsequence blocks + that might be considered document metadata, such as 'abstract' or + 'dedication' blocks, or the 'meta' role. Doing otherwise is probably more + messing with the internals of sphinx than this rare use case merits. + """ exampledocinfo = env.metadata['metadata'] expected_metadata = { 'author': u'David Goodger', - u'field name': u'This is a generic bibliographic field.', - u'field name 2': u'Generic bibliographic fields may contain multiple body elements.\n\nLike this.'} + 'authors': [u'Me', u'Myself', u'I'], + 'address': u'123 Example Street\nExample, EX Canada\nA1B 2C3', + 'field name': u'This is a generic bibliographic field.', + 'field name 2': u'Generic bibliographic fields may contain multiple body elements.\n\nLike this.', + 'status': u'This is a "work in progress"', + 'version': u'1', + 'copyright': u"This document has been placed in the public domain. You\nmay do with it as you wish. You may copy, modify,\nredistribute, reattribute, sell, buy, rent, lease,\ndestroy, or improve it, quote it at length, excerpt,\nincorporate, collate, fold, staple, or mutilate it, or do\nanything else to it that your or anyone else's heart\ndesires.", + 'contact': u'goodger@python.org', + 'date': u'2006-05-21', + 'organization': u'humankind', + 'revision': u'4564'} # I like this way of comparing dicts - easier to see the error. for key in exampledocinfo: - yield assert_equals, exampledocinfo[key], expected_metadata[key] + yield assert_equals, exampledocinfo.get(key), expected_metadata.get(key) #but then we still have to check for missing keys yield assert_equals, set(expected_metadata.keys()), set(exampledocinfo.keys()) From 9e7c5e88c4ae24381f866b7c01819cc592f17a31 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 23 Dec 2009 11:53:19 +0100 Subject: [PATCH 7/8] Fix some nits after pulling from http://bitbucket.org/howthebodyworks/sphinx/ and add changelog and authors entries. --- AUTHORS | 1 + CHANGES | 3 +++ sphinx/environment.py | 6 ++--- tests/test_metadata.py | 53 +++++++++++++++++++++++------------------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/AUTHORS b/AUTHORS index 259c0949c..09be75330 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,6 +13,7 @@ Other contributors, listed alphabetically, are: * Martin Hans -- autodoc improvements * Dave Kuhlman -- original LaTeX writer * Thomas Lamb -- linkcheck builder +* Dan MacKinlay -- metadata fixes * Will Maier -- directory HTML builder * Christopher Perkins -- autosummary integration * Benjamin Peterson -- unittests diff --git a/CHANGES b/CHANGES index 8d4e4f861..66d1ab08c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 1.0 (in development) ============================ +* All docinfo metadata is now put into the document metadata, not just + the author. + * Added new HTML theme ``agogo``, created by Andi Albrecht. * Added new minimal theme called scrolls, created by Armin Ronacher. diff --git a/sphinx/environment.py b/sphinx/environment.py index 64c745a79..426d78c25 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -12,12 +12,10 @@ import re import os import time -import heapq import types import codecs import imghdr import string -import difflib import cPickle as pickle from os import path from glob import glob @@ -757,7 +755,7 @@ class BuildEnvironment: def process_metadata(self, docname, doctree): """ Process the docinfo part of the doctree as metadata. - Keep processing minimal - just return what docutils says. + Keep processing minimal -- just return what docutils says. """ self.metadata[docname] = md = {} try: @@ -772,7 +770,7 @@ class BuildEnvironment: # nodes are multiply inherited... if isinstance(node, nodes.authors): md['authors'] = [author.astext() for author in node] - elif isinstance(node, nodes.TextElement): #e.g. author + elif isinstance(node, nodes.TextElement): # e.g. author md[node.__class__.__name__] = node.astext() else: name, body = node diff --git a/tests/test_metadata.py b/tests/test_metadata.py index ea41fc11d..9675947ac 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -3,23 +3,20 @@ test_metadata ~~~~~~~~~~~~~ - Test our ahndling of metadata in files with bibliographic metadata + Test our handling of metadata in files with bibliographic metadata. :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ - - -# adapted from an example of bibliographic metadata at http://docutils.sourceforge.net/docs/user/rst/demo.txt +# adapted from an example of bibliographic metadata at +# http://docutils.sourceforge.net/docs/user/rst/demo.txt from util import * from nose.tools import assert_equals from sphinx.environment import BuildEnvironment -from sphinx.builders.html import StandaloneHTMLBuilder -from sphinx.builders.latex import LaTeXBuilder app = env = None warnings = [] @@ -30,7 +27,7 @@ def setup_module(): app = TestApp(srcdir='(temp)') env = BuildEnvironment(app.srcdir, app.doctreedir, app.config) # Huh. Why do I need to do this? - env.set_warnfunc(lambda *args: warnings.append(args)) + env.set_warnfunc(lambda *args: warnings.append(args)) msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app) for docname in it: pass @@ -40,28 +37,36 @@ def teardown_module(): def test_docinfo(): """ - inspect the 'docinfo' metadata stored in the first node of the document. + Inspect the 'docinfo' metadata stored in the first node of the document. Note this doesn't give us access to data stored in subsequence blocks that might be considered document metadata, such as 'abstract' or 'dedication' blocks, or the 'meta' role. Doing otherwise is probably more messing with the internals of sphinx than this rare use case merits. """ exampledocinfo = env.metadata['metadata'] - expected_metadata = { - 'author': u'David Goodger', - 'authors': [u'Me', u'Myself', u'I'], - 'address': u'123 Example Street\nExample, EX Canada\nA1B 2C3', - 'field name': u'This is a generic bibliographic field.', - 'field name 2': u'Generic bibliographic fields may contain multiple body elements.\n\nLike this.', - 'status': u'This is a "work in progress"', - 'version': u'1', - 'copyright': u"This document has been placed in the public domain. You\nmay do with it as you wish. You may copy, modify,\nredistribute, reattribute, sell, buy, rent, lease,\ndestroy, or improve it, quote it at length, excerpt,\nincorporate, collate, fold, staple, or mutilate it, or do\nanything else to it that your or anyone else's heart\ndesires.", - 'contact': u'goodger@python.org', - 'date': u'2006-05-21', - 'organization': u'humankind', - 'revision': u'4564'} + expecteddocinfo = { + 'author': u'David Goodger', + 'authors': [u'Me', u'Myself', u'I'], + 'address': u'123 Example Street\nExample, EX Canada\nA1B 2C3', + 'field name': u'This is a generic bibliographic field.', + 'field name 2': (u'Generic bibliographic fields may contain multiple ' + u'body elements.\n\nLike this.'), + 'status': u'This is a "work in progress"', + 'version': u'1', + 'copyright': (u'This document has been placed in the public domain. ' + u'You\nmay do with it as you wish. You may copy, modify,' + u'\nredistribute, reattribute, sell, buy, rent, lease,\n' + u'destroy, or improve it, quote it at length, excerpt,\n' + u'incorporate, collate, fold, staple, or mutilate it, or ' + u'do\nanything else to it that your or anyone else\'s ' + u'heart\ndesires.'), + 'contact': u'goodger@python.org', + 'date': u'2006-05-21', + 'organization': u'humankind', + 'revision': u'4564', + } # I like this way of comparing dicts - easier to see the error. for key in exampledocinfo: - yield assert_equals, exampledocinfo.get(key), expected_metadata.get(key) - #but then we still have to check for missing keys - yield assert_equals, set(expected_metadata.keys()), set(exampledocinfo.keys()) + yield assert_equals, exampledocinfo.get(key), expecteddocinfo.get(key) + # but then we still have to check for missing keys + yield assert_equals, set(expecteddocinfo.keys()), set(exampledocinfo.keys()) From 769838883565a76f0b0e7d40e68c5050ed5c87db Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 23 Dec 2009 12:00:37 +0100 Subject: [PATCH 8/8] Add issue number. --- CHANGES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 66d1ab08c..54fe76bbd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,8 @@ Release 1.0 (in development) ============================ -* All docinfo metadata is now put into the document metadata, not just - the author. +* #284: All docinfo metadata is now put into the document metadata, not + just the author. * Added new HTML theme ``agogo``, created by Andi Albrecht.