birkenfeld / sphinx-contrib (http://sphinx.pocoo.org/)

Contributed extensions for Sphinx. This shared repository is open for anyone who wants to maintain a Sphinx extension publicly.

commit 96: 3844cba2727d
parent 95: 5ed5ecc481bb
branch: default
Some handy help methods for nose are the secret sauce that make this test suite manageable. I feel a passing test suite approach
Dan MacKinlay
4 months ago

Changed (Δ1.2 KB):

raw changeset »

feed/sphinxcontrib/feed/__init__.py (2 lines added, 4 lines removed)

feed/tests/assert_operators.py (37 lines added, 0 lines removed)

feed/tests/run.py (24 lines added, 15 lines removed)

feed/tests/test_build.py (17 lines added, 20 lines removed)

feed/tests/util.py (0 lines added, 3 lines removed)

Up to file-list feed/sphinxcontrib/feed/__init__.py:

@@ -37,7 +37,7 @@ def create_feed_container(app):
37
37
def create_feed_item(app, pagename, templatename, ctx, doctree):
38
38
    """
39
39
    Here we have access to nice HTML fragments to use in, say, an RSS feed.
40
    """
40
    """    
41
41
    import dateutil.parser
42
42
    date_parser = dateutil.parser.parser()
43
43
    env = app.builder.env
@@ -63,7 +63,6 @@ def create_feed_item(app, pagename, temp
63
63
    ctx['rss_link'] = app.config.feed_base_url + '/' + app.config.feed_filename
64
64
  
65
65
def emit_feed(app, exc):
66
    assert False
67
66
    import os.path
68
67
    ordered_items = app.builder.env.feed_items.values()
69
68
    feed = app.builder.env.feed_feed
@@ -72,10 +71,9 @@ def emit_feed(app, exc):
72
71
      reverse=True)
73
72
    for item in ordered_items:
74
73
        feed.add_item(**item)     
75
    outfilename = os.path.join(app.builder.outdir, 'html',
74
    outfilename = os.path.join(app.builder.outdir,
76
75
      app.config.feed_filename)
77
76
    fp = open(outfilename, 'w')
78
    assert False
79
77
    feed.write(fp, 'utf-8')
80
78
    fp.close()
81
79
    

Up to file-list feed/tests/assert_operators.py:

1
"""
2
Look away! this just turns the operators in the operator modules into
3
functions of the same name that assert their own truth. Codegen FTW.
4
This uses the exec function, which is insane and ugly. but types.FunctionTpe/types.CodeType is insane, ugly, AND very tedious
5
"""
6
import operator
7
from string import Template
8
9
INTERESTING_OPS = [
10
'and_',
11
'contains',
12
'eq',
13
'ge',
14
'gt',
15
'isCallable',
16
'isMappingType',
17
'isNumberType',
18
'isSequenceType',
19
'is_',
20
'is_not',
21
'le',
22
'lt',
23
'ne',
24
'not_',
25
'or_',
26
'repeat',
27
'sequenceIncludes',
28
'truth']
29
30
FUNCTION_TEMPLATE = Template("""
31
def $op_name(*args, **kwargs):
32
    assert operator.$op_name(*args, **kwargs)
33
""")
34
35
for op_name in INTERESTING_OPS:
36
    exec(FUNCTION_TEMPLATE.substitute(op_name=op_name))
37
 

Up to file-list feed/tests/run.py:

13
13
import sys
14
14
from os import path
15
15
16
# always test the FeedBuilder package from this directory
17
sys.path.insert(0, path.join(path.dirname(__file__), path.pardir))
16
def run(bonus_args=[]):
17
    # always test the FeedBuilder package from this directory
18
    sys.path.insert(0, path.join(path.dirname(__file__), path.pardir))
18
19
19
try:
20
    import nose
21
except ImportError:
22
    print "The nose package is needed to run the FeedBuilder test suite."
23
    sys.exit(1)
20
    try:
21
        import nose
22
    except ImportError:
23
        print "The nose package is needed to run the FeedBuilder test suite."
24
        sys.exit(1)
24
25
25
nose_argv = ['nosetests']
26
# Everything after '--' is passed to nose.
27
if '--' in sys.argv:
28
    hyphen_pos = sys.argv.index('--')
29
    nose_argv.extend(sys.argv[hyphen_pos + 1:])
26
    try:
27
        import sphinx
28
    except ImportError:
29
        print "The sphinx package is needed to run the FeedBuilder test suite."
30
30
31
nose.run(argv=nose_argv)
31
    nose_argv = ['nosetests']
32
    
32
33
33
print "Running FeedBuilder test suite..."
34
nose.run()
34
    # Everything after '--' is passed to nose.
35
    if '--' in sys.argv:
36
        hyphen_pos = sys.argv.index('--')
37
        nose_argv.extend(bonus_args + sys.argv[hyphen_pos + 1:])
38
39
    print "Running FeedBuilder test suite..."
40
    nose.run(argv=nose_argv)
41
42
if __name__ == '__main__':
43
    run()

Up to file-list feed/tests/test_build.py:

10
10
"""
11
11
12
12
import os
13
from os.path import exists
13
14
import re
14
15
import sys
15
16
import difflib
16
17
import htmlentitydefs
17
18
from StringIO import StringIO
18
from operator import eq, truth
19
from tests.util import test_root, raises, raises_msg, Struct,\
19
import assert_operators as ops
20
from util import test_root, raises, raises_msg, Struct,\
20
21
  ListOutput, TestApp, with_app, gen_with_app, path, with_tempdir,\
21
22
  write_file, sprint
22
23
@@ -39,29 +40,25 @@ FEED_WARNINGS = ENV_WARNINGS + ""
39
40
# %(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.*'
40
41
# """
41
42
42
@gen_with_app(buildername='html', warning=feed_warnfile, cleanenv=True,
43
              tags=['testtag'])
43
def exists(p):
44
    assert os.path.exists(p)
45
    
46
@gen_with_app(buildername='html', warning=feed_warnfile, cleanenv=True)
44
47
def test_feed(app):
45
    app.builder.build_all()
48
    app.build(all_files=True, filenames=[]) #build_all misses the crucial finish signal
46
49
    feed_warnings = feed_warnfile.getvalue().replace(os.sep, '/')
47
50
    feed_warnings_exp = FEED_WARNINGS % {'root': app.srcdir}
48
    # yield eq, feed_warnings, feed_warnings_exp, 'Warnings don\'t match:\n' + \
49
    #        '\n'.join(difflib.ndiff(feed_warnings_exp.splitlines(),
50
    #                                feed_warnings.splitlines()))
51
    yield eq, feed_warnings, feed_warnings_exp
52
    assert feed_warnings == feed_warnings_exp
51
    yield ops.eq, feed_warnings, feed_warnings_exp
53
52
    rss_path = os.path.join(app.outdir, 'rss.xml')
54
    yield os.path.exists, rss_path
55
    assert os.path.exists(rss_path)
53
    yield exists, rss_path
54
    yield ops.eq, app.builder.env.feed_items.keys(), ['older', 'most_aged', 'latest']
56
55
    # see http://www.feedparser.org/
57
56
    f = feedparser.parse(rss_path)
58
    assert False
59
57
    entries = f.entries
60
    yield eq, len(entries), 3
61
    yield eq, entries[0].updated_parsed, (2001, 8, 11)
62
    yield eq, entries[0].title, "The latest blog post"
63
    yield eq, entries[1].updated_parsed, (2001, 8, 1)
64
    yield eq, entries[1].title, "An older blog post"
65
    yield eq, entries[2].updated_parsed, (1979, 1, 1)
66
    yield eq, entries[2].title, "The oldest blog post"
58
    yield ops.eq, entries[0].updated_parsed, (2001, 8, 11)
59
    yield ops.eq, entries[0].title, "The latest blog post"
60
    yield ops.eq, entries[1].updated_parsed, (2001, 8, 1)
61
    yield ops.eq, entries[1].title, "An older blog post"
62
    yield ops.eq, entries[2].updated_parsed, (1979, 1, 1)
63
    yield ops.eq, entries[2].title, "The oldest blog post"
67
64

Up to file-list feed/tests/util.py:

@@ -24,8 +24,6 @@ from sphinx.ext.autodoc import AutoDirec
24
24
25
25
from path import path
26
26
27
import nose.tools
28
29
27
__all__ = [
30
28
    'test_root',
31
29
    'raises', 'raises_msg', 'Struct',
@@ -88,7 +86,6 @@ class ListOutput(object):
88
86
    def write(self, text):
89
87
        self.content.append(text)
90
88
91
@nose.tools.nottest
92
89
class TestApp(application.Sphinx):
93
90
    """
94
91
    A subclass of :class:`Sphinx` that runs on the test root, with some