Commit b0e60784 authored by Benjamin Long's avatar Benjamin Long

ENH: Added Script to create basic Translator and player unit tests.

parent 24d549c4
#!/usr/bin/env python
import sys
import os
import fnmatch
def findSource(dir):
fileList = []
for root, subFolders, files in os.walk(dir):
for file in files:
if fnmatch.fnmatch(file, "*.h") or \
fnmatch.fnmatch(file, "*.cxx") or \
fnmatch.fnmatch(file, "*.cpp") or \
fnmatch.fnmatch(file, "CMakeLists.txt") or \
fnmatch.fnmatch(file, "*.ui") or \
fnmatch.fnmatch(file, "*.qrc") or \
fnmatch.fnmatch(file, "*.py") or \
fnmatch.fnmatch(file, "*.png"):
file = os.path.join(root,file)
file = file[len(dir):] # strip common dir
fileList.append(file)
return fileList
def copyAndReplace(inFile, template, target, key, moduleName):
newFile = os.path.join( target, inFile.replace(key, moduleName) )
#newFile = os.path.join(target + "EventTranslatorPlayerTest1.cxx")
print "creating %s" % newFile
path = os.path.dirname(newFile)
if not os.path.exists(path):
os.makedirs(path)
fp = open(os.path.join(template,inFile))
contents = fp.read()
fp.close()
contents = contents.replace(key, moduleName)
contents = contents.replace(key.upper(), moduleName.upper())
fp = open(newFile, "w")
fp.write(contents)
fp.close()
def usage():
print ""
print "Usage:"
print "ModuleWizard [--template <dir>] [--templateKey <key>] [--target <dir>] <moduleName>"
print " --template default ../TemplateTranslatorPlayer/"
print " --templateKey default is Template"
print " --target default ../<moduleName>/"
def main(argv):
template = ""
templateKey = ""
target = ""
moduleName = ""
while argv != []:
arg = argv.pop(0)
if arg == "--template":
template = argv.pop(0)
continue
if arg == "--templateKey":
templateKey = argv.pop(0)
continue
if arg == "--target":
target = argv.pop(0)
continue
if arg == "--help":
usage()
exit()
moduleName = arg
if moduleName == "":
print "Please specify module name"
usage()
exit()
if template == "":
template = "../TemplatePlayerTest/"
if template[-1] != '/':
template += '/'
if templateKey == "":
templateKey = "Template"
#templateKey = os.path.split(template[:-1])[-1]
if target == "":
target = "../" + moduleName
if os.path.exists(target):
print target, "exists - delete it first"
exit()
if not os.path.exists(template):
print template, "does not exist - run from source dir or specify with --template"
usage()
exit()
print "\nWill copy \n\t%s \nto \n\t%s \nreplacing \"%s\" with \"%s\"\n" % (template, target, templateKey, moduleName)
sources = findSource( template )
print sources
for file in sources:
copyAndReplace(file, template, target, templateKey, moduleName)
print '\nModule %s created!' % moduleName
if __name__ == "__main__":
main(sys.argv[1:])
#!/usr/bin/env python
import sys
import os
import fnmatch
def findSource(dir):
fileList = []
for root, subFolders, files in os.walk(dir):
for file in files:
if fnmatch.fnmatch(file, "*.h") or \
fnmatch.fnmatch(file, "*.cxx") or \
fnmatch.fnmatch(file, "*.cpp") or \
fnmatch.fnmatch(file, "CMakeLists.txt") or \
fnmatch.fnmatch(file, "*.ui") or \
fnmatch.fnmatch(file, "*.qrc") or \
fnmatch.fnmatch(file, "*.py") or \
fnmatch.fnmatch(file, "*.png"):
file = os.path.join(root,file)
file = file[len(dir):] # strip common dir
fileList.append(file)
return fileList
def copyAndReplace(inFile, template, target, key, moduleName):
newFile = os.path.join( target, inFile.replace(key, moduleName) )
#newFile = os.path.join(target + "EventTranslatorPlayerTest1.cxx")
print "creating %s" % newFile
path = os.path.dirname(newFile)
if not os.path.exists(path):
os.makedirs(path)
fp = open(os.path.join(template,inFile))
contents = fp.read()
fp.close()
contents = contents.replace(key, moduleName)
contents = contents.replace(key.upper(), moduleName.upper())
fp = open(newFile, "w")
fp.write(contents)
fp.close()
def usage():
print ""
print "Usage:"
print "ModuleWizard [--template <dir>] [--templateKey <key>] [--target <dir>] <moduleName>"
print " --template default ../TemplateTranslatorPlayer/"
print " --templateKey default is Template"
print " --target default ../<moduleName>/"
def main(argv):
template = ""
templateKey = ""
target = ""
moduleName = ""
while argv != []:
arg = argv.pop(0)
if arg == "--template":
template = argv.pop(0)
continue
if arg == "--templateKey":
templateKey = argv.pop(0)
continue
if arg == "--target":
target = argv.pop(0)
continue
if arg == "--help":
usage()
exit()
moduleName = arg
if moduleName == "":
print "Please specify module name"
usage()
exit()
if template == "":
template = "../TemplateTranslatorTest/"
if template[-1] != '/':
template += '/'
if templateKey == "":
templateKey = "Template"
#templateKey = os.path.split(template[:-1])[-1]
if target == "":
target = "../" + moduleName
if os.path.exists(target):
print target, "exists - delete it first"
exit()
if not os.path.exists(template):
print template, "does not exist - run from source dir or specify with --template"
usage()
exit()
print "\nWill copy \n\t%s \nto \n\t%s \nreplacing \"%s\" with \"%s\"\n" % (template, target, templateKey, moduleName)
sources = findSource( template )
print sources
for file in sources:
copyAndReplace(file, template, target, templateKey, moduleName)
print '\nModule %s created!' % moduleName
if __name__ == "__main__":
main(sys.argv[1:])
/*=========================================================================
Program: ParaView
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QApplication>
#include <QtTest/QtTest>
#include <QTemplate>
// QtTesting includes
#include "pqTestUtility.h"
#include "pqTest.h"
// ----------------------------------------------------------------------------
class pqTemplateEventPlayerTester: public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void cleanupTestCase();
private:
QTemplate* Template;
pqTestUtility* TestUtility;
};
// ----------------------------------------------------------------------------
void pqTemplateEventPlayerTester::initTestCase()
{
this->TestUtility = new pqTestUtility();
this->TestUtility->addEventObserver("xml", new pqDummyEventObserver);
this->TestUtility->addEventSource("xml", new pqDummyEventSource());
this->Template = 0;
}
// ----------------------------------------------------------------------------
void pqTemplateEventPlayerTester::init()
{
// Init the QTemplate
this->Template = new QTemplate();
this->Template->setObjectName("TemplateTest");
this->Template->setMinimum(-99);
}
// ----------------------------------------------------------------------------
void pqTemplateEventPlayerTester::cleanup()
{
delete this->Template;
}
// ----------------------------------------------------------------------------
void pqTemplateEventPlayerTester::cleanupTestCase()
{
delete this->TestUtility;
}
// ----------------------------------------------------------------------------
CTK_TEST_MAIN( pqTemplateEventPlayerTest )
#include "moc_pqTemplateEventPlayerTest.cpp"
/*=========================================================================
Program: ParaView
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QApplication>
#include <QStyle>
#include <QtTest/QtTest>
#include <QTemplate>
// QtTesting includes
#include "pqTestUtility.h"
#include "pqTest.h"
// ----------------------------------------------------------------------------
class pqTemplateEventTranslatorTester: public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void cleanupTestCase();
private:
QTemplate* Template;
pqTestUtility* TestUtility;
pqDummyEventObserver* EventObserver;
};
// ----------------------------------------------------------------------------
void pqTemplateEventTranslatorTester::initTestCase()
{
this->TestUtility = new pqTestUtility();
this->EventObserver = new pqDummyEventObserver();
this->TestUtility->addEventObserver("xml", this->EventObserver);
this->TestUtility->addEventSource("xml", new pqDummyEventSource());
this->Template = 0;
}
// ----------------------------------------------------------------------------
void pqTemplateEventTranslatorTester::init()
{
// Init the Template
this->Template = new QTemplate();
this->Template->setObjectName("TemplateTest");
// Start to record events
this->TestUtility->recordTestsBySuffix("xml");
// Fire the event "enter" to connect Template signals to the translator slots
QEvent enter(QEvent::Enter);
qApp->notify(this->Template, &enter);
}
// ----------------------------------------------------------------------------
void pqTemplateEventTranslatorTester::cleanup()
{
this->TestUtility->stopRecords(0);
delete this->Template;
}
// ----------------------------------------------------------------------------
void pqTemplateEventTranslatorTester::cleanupTestCase()
{
this->EventObserver = 0;
delete this->TestUtility;
}
// ----------------------------------------------------------------------------
CTK_TEST_MAIN( pqTemplateEventTranslatorTest )
#include "moc_pqTemplateEventTranslatorTest.cpp"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment