Added a SAP connector and integrated the test system with coverage.py
This commit is contained in:
parent
b541ecb651
commit
01487db688
8 changed files with 450 additions and 115 deletions
|
@ -1,3 +1,6 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
import os, os.path, sys
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
class TestMixin:
|
||||
'''This class is mixed in with any PloneTestCase.'''
|
||||
|
@ -12,16 +15,81 @@ class TestMixin:
|
|||
self.logout()
|
||||
self.login(userId)
|
||||
|
||||
def getNonEmptySubModules(self, moduleName):
|
||||
'''Returns the list fo sub-modules of p_app that are non-empty.'''
|
||||
res = []
|
||||
try:
|
||||
exec 'import %s' % moduleName
|
||||
exec 'moduleObj = %s' % moduleName
|
||||
moduleFile = moduleObj.__file__
|
||||
if moduleFile.endswith('.pyc'):
|
||||
moduleFile = moduleFile[:-1]
|
||||
except ImportError, ie:
|
||||
return res
|
||||
except SyntaxError, se:
|
||||
return res
|
||||
# Include the module if not empty. "Emptyness" is determined by the
|
||||
# absence of names beginning with other chars than "__".
|
||||
for elem in moduleObj.__dict__.iterkeys():
|
||||
if not elem.startswith('__'):
|
||||
print 'Element found in this module!!!', moduleObj, elem
|
||||
res.append(moduleObj)
|
||||
break
|
||||
# Include sub-modules if any
|
||||
if moduleFile.find("__init__.py") != -1:
|
||||
# Potentially, sub-modules exist.
|
||||
moduleFolder = os.path.dirname(moduleFile)
|
||||
for elem in os.listdir(moduleFolder):
|
||||
if elem.startswith('.'): continue
|
||||
subModuleName, ext = os.path.splitext(elem)
|
||||
if ((ext == '.py') and (subModuleName != '__init__')) or \
|
||||
os.path.isdir(os.path.join(moduleFolder, subModuleName)):
|
||||
# Submodules may be sub-folders or Python files
|
||||
subModuleName = '%s.%s' % (moduleName, subModuleName)
|
||||
res += self.getNonEmptySubModules(subModuleName)
|
||||
return res
|
||||
|
||||
def getCovFolder(self):
|
||||
'''Returns the folder where to put the coverage folder if needed.'''
|
||||
for arg in sys.argv:
|
||||
if arg.startswith('[coverage'):
|
||||
return arg[10:].strip(']')
|
||||
return None
|
||||
|
||||
# Functions executed before and after every test -------------------------------
|
||||
def beforeTest(test):
|
||||
'''Is executed before every test.'''
|
||||
g = test.globs
|
||||
g['tool'] = test.app.plone.get('portal_%s' % g['appName'].lower()).appy()
|
||||
g['appFolder'] = g['tool'].o.getProductConfig().diskFolder
|
||||
cfg = g['tool'].o.getProductConfig()
|
||||
g['appFolder'] = cfg.diskFolder
|
||||
moduleOrClassName = g['test'].name # Not used yet.
|
||||
# Initialize the test
|
||||
test.createUser('admin', ('Member','Manager'))
|
||||
test.login('admin')
|
||||
g['t'] = g['test']
|
||||
# Must we perform test coverage ?
|
||||
covFolder = test.getCovFolder()
|
||||
if covFolder:
|
||||
try:
|
||||
print 'COV!!!!', covFolder
|
||||
import coverage
|
||||
app = getattr(cfg, g['tool'].o.getAppName())
|
||||
from coverage import coverage
|
||||
cov = coverage()
|
||||
g['cov'] = cov
|
||||
g['covFolder'] = covFolder
|
||||
cov.start()
|
||||
except ImportError:
|
||||
print 'You must install the "coverage" product.'
|
||||
|
||||
def afterTest(test): pass
|
||||
def afterTest(test):
|
||||
'''Is executed after every test.'''
|
||||
g = test.globs
|
||||
if g.has_key('covFolder'):
|
||||
cov = g['cov']
|
||||
cov.stop()
|
||||
# Dumps the coverage report
|
||||
appModules = test.getNonEmptySubModules(g['tool'].o.getAppName())
|
||||
cov.html_report(directory=g['covFolder'], morfs=appModules)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -190,7 +190,7 @@
|
|||
</tal:editField>
|
||||
<tal:viewField tal:condition="not: isEdit">
|
||||
<tal:fileField condition="python: (appyType['type'] == 'File')">
|
||||
<span tal:condition="showLabel" tal:content="label"></span>
|
||||
<span tal:condition="showLabel" tal:content="label" class="appyLabel"></span>
|
||||
<metal:viewField use-macro="python: contextObj.widget(field.getName(), 'view', use_label=0)"/>
|
||||
</tal:fileField>
|
||||
<tal:date condition="python: appyType['type'] == 'Date'">
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
}
|
||||
|
||||
.appyList {
|
||||
line-height: 0;
|
||||
line-height: 1.1em;
|
||||
margin: 0 0 0.5em 1.2em;
|
||||
padding: 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
class ToolWrapper:
|
||||
|
||||
def getInitiator(self):
|
||||
'''Retrieves the object that triggered the creation of the object
|
||||
being currently created (if any).'''
|
||||
|
@ -13,4 +12,8 @@ class ToolWrapper:
|
|||
def getObject(self, uid):
|
||||
'''Allow to retrieve an object from its unique identifier p_uid.'''
|
||||
return self.o.getObject(uid, appy=True)
|
||||
|
||||
def getDiskFolder(self):
|
||||
'''Returns the disk folder where the Appy application is stored.'''
|
||||
return self.o.getProductConfig().diskFolder
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue