File: test_doctests.py

package info (click to toggle)
sprox 0.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 480 kB
  • ctags: 1,040
  • sloc: python: 3,235; sh: 20; makefile: 6
file content (76 lines) | stat: -rw-r--r-- 2,496 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from sprox.configbase import ConfigBase, ConfigBaseError
from sprox.test.base import setup_database, sorted_user_columns, SproxTest, setup_records, Example, Document, eq_xml
from sprox.test.model import User, Town
import os.path, re
from nose.tools import raises, eq_
from nose.util import anyp, getpackage, test_address, resolve_name, src, tolist

import inspect
import doctest

import unittest

from nose.plugins import doctests as nose_doctest

from sprox import configbase, fillerbase, formbase, saormprovider, sprockets, tablebase, metadata, validators, validatorselector, widgets, widgetselector
from sprox.dojo import formbase as dojo_formbase

import sprox

session = None
engine  = None
connection = None
trans = None
metadata = None
def setup():
    global session, engine, metadata, trans
    session, engine, metadata = setup_database()
    user = setup_records(session)
    #this may be needed if we end up testing the provider with doctests
    #session.commit()
    

def check_output_xml(want, got, optionsflags):
    return eq_xml(want, got)

from doctest import OutputChecker
original_check_output = OutputChecker.check_output
import doctest

XML_OUTPUT = doctest.register_optionflag("XML")

class MyOutputChecker(doctest.OutputChecker):
    def check_output(self, want, got, optionflags):
        if optionflags & XML_OUTPUT:
            return check_output_xml(want, got, optionflags)
        return original_check_output(self, want, got, optionflags)

doctest.OutputChecker = MyOutputChecker

def teardown():
    session.rollback()

def test_doctests():
    global session, metadata
    import unittest
    import doctest
    
    def setUp(self):
        #this may be needed if we end up testing the provider with doctests
        pass
    def tearDown(self):
        #this may be needed if we end up testing the provider with doctests
        #session.rollback()
        pass
    suite = unittest.TestSuite()
    for mod in dir(sprox):
        mod = getattr(sprox, mod)
        if inspect.ismodule(mod):
            try:
                suite.addTest(doctest.DocTestSuite(mod, globs={'session':session, 'User': User, 'Town':Town, 'metadata':metadata}, setUp=setUp, tearDown=tearDown))
            except ValueError:
                pass
    suite.addTest(doctest.DocTestSuite(dojo_formbase, globs={'session':session, 'User': User, 'Town':Town, 'metadata':metadata}, setUp=setUp, tearDown=tearDown))

    runner = unittest.TextTestRunner(verbosity=10)
    runner.run(suite)