From 87196a2523bc055acbe03c3ede6c9b69620196f4 Mon Sep 17 00:00:00 2001 From: Dan MacKinlay Date: Tue, 22 Dec 2009 00:06:25 +1100 Subject: [PATCH] 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()