"""
$Id: __init__.py,v 1.2 2005/02/26 17:56:10 sidnei Exp $
"""

import os, sys
from cStringIO import StringIO

if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

import unittest
from Testing import ZopeTestCase
from Testing.ZopeTestCase import placeless
from Products.PloneTestCase import PloneTestCase

# Register sample content.
import Products.Fate.tests.sample.content

import Products.CMFCore
import Products.Archetypes
import Products.Fate
import Products.Five
import Products.testing

ZopeTestCase.installProduct('Archetypes')
ZopeTestCase.installProduct('MimetypesRegistry')
ZopeTestCase.installProduct('PortalTransforms')
ZopeTestCase.installProduct('Fate')

PloneTestCase.setupPloneSite()

def register_zcml(with_setup=False):
    if with_setup:
        placeless.setUp()
    load = placeless.zcml.load_config
    load('meta.zcml', Products.Five)
    load('permissions.zcml', Products.Five)
    load('traversal.zcml', Products.testing)
    load('configure.zcml', Products.CMFCore)
    load('configure.zcml', Products.Archetypes)
    load('meta.zcml', Products.Fate)


class BaseTest(PloneTestCase.PloneTestCase):

    def _setup(self):
        PloneTestCase.PloneTestCase._setup(self)
        register_zcml(with_setup=True)

    def beforeTearDown(self):
        placeless.tearDown()

    def failIfRaises(self, exc, method, *args, **kw):
        try:
            method(*args, **kw)
        except exc, e:
            import traceback
            out = StringIO()
            traceback.print_exc(file=out)
            self.fail('Got exception %r where it '
                      'should not happen.\n%s' % (e, out.getvalue()))
