Commits

dan mackinlay committed 2ee0426

working tests for docinfo metadata

Comments (0)

Files changed (1)

tests/test_metadata.py

 
 
 # 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
 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
 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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.