Back to index

plone3  3.1.7
test_baseunit.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 """
00026 """
00027 
00028 import os
00029 import glob
00030 
00031 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00032 from Products.Archetypes.tests.utils import PACKAGE_HOME
00033 from Products.Archetypes.tests.utils import normalize_html
00034 from Products.Archetypes.tests.utils import ZOPE28
00035 from Products.Archetypes.atapi import *
00036 from Products.Archetypes.tests.test_classgen import Dummy
00037 from Products.Archetypes.tests.test_classgen import gen_dummy
00038 
00039 
00040 class BaseUnitTest( ATSiteTestCase ):
00041 
00042     def testSame(self):
00043         gen_dummy()
00044         # The BaseUnit expects 'instance' to be
00045         # acquisition wrapped, or else it does return
00046         # the untransformed text -- this was introduced
00047         # for compatibility with APE.
00048         parent = Dummy(oid='parent')
00049         dummy = Dummy(oid='dummy', init_transforms=1).__of__(parent)
00050         input = open(self.input)
00051         bu = BaseUnit(name='test', file=input,
00052                       mimetype='text/restructured',
00053                       instance=dummy)
00054         input.close()
00055         got = normalize_html(bu.transform(dummy, 'text/html'))
00056         
00057         try:
00058             output = open(self.output)
00059         except IOError:
00060             print "Creating %s" % self.output
00061             output = open(self.output, 'w')
00062             output.write(got)
00063             output.close()
00064             
00065         output = open(self.output)
00066         expected = normalize_html(output.read())
00067         output.close()
00068     
00069         try:
00070             self.assertEqual(got, expected)
00071         except self.failureException:
00072             # Zope < 2.8 has a buggy reStructuredText package, don't bother
00073             if ZOPE28:
00074                 raise
00075 
00076 tests = []
00077 
00078 input_files = glob.glob(os.path.join(PACKAGE_HOME, "input", "rest*.rst"))
00079 for f in input_files:
00080     fname = os.path.split(f)[1]
00081     outname = os.path.join(PACKAGE_HOME, "output", '%s.out' % fname.split('.')[0])
00082 
00083     class BaseUnitTestSubclass(BaseUnitTest):
00084         input = f
00085         output = outname
00086 
00087     tests.append(BaseUnitTestSubclass)
00088 
00089 
00090 def test_suite():
00091     from unittest import TestSuite, makeSuite
00092     suite = TestSuite()
00093     for test in tests:
00094         suite.addTest(makeSuite(test))
00095     return suite