Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python -d
- import sys, os, re, subprocess, inspect
- from PyQt4 import QtCore, QtGui
- from etk.unittests.testconverter.scripts.nosetestsGUI import Ui_Dialog
- class nosetestUI(QtGui.QMainWindow):
- def __init__(self, parent=None):
- self.localpath = os.getcwd()
- self.localpath = os.path.abspath(os.path.join(self.localpath,
- "..", "..", "..", ".."))
- self.projectPath = 'main\\employer_toolkit\\app\\server\\etk\\unittests\\converted'
- QtGui.QWidget.__init__(self, parent)
- self.processTests = self.getTestFiles()
- self.ui = Ui_Dialog()
- self.ui.setupUi(self)
- self.filepath = ''
- for test in self.processTests.keys():
- self.ui.selectProcess.addItem(test) # name
- self.ui.selectProcess.activated['QString'].connect(self.getTestProcess)
- self.ui.selectTest.activated['QString'].connect(self.getTest)
- QtCore.QObject.connect(self.ui.testButton,
- QtCore.SIGNAL("clicked()"), self.runTest)
- QtCore.QObject.connect(self.ui.cancelButton,
- QtCore.SIGNAL("clicked()"), self.close)
- def getTestFiles(self):
- """ returns a dict of the unittest files in the converted folder, e.g.
- fileDict[studentloan] = studentloan_unittest.py
- """
- fileDict = {}
- path = os.path.join(self.localpath, self.projectPath)
- results = []
- results += [fname for fname in os.listdir(path) if fname.endswith('.py')]
- results.remove('__init__.py')
- for fname in results:
- fileDict[re.sub('_unittest.py','',fname)] = fname
- return fileDict
- def getTestProcess(self):
- self.ui.errorMsg.setText('')
- testProcess = unicode(self.ui.selectProcess.currentText())
- tests = [] # Make sure the list is clear when the process changes
- try:
- self.filepath = os.path.join(self.localpath, self.projectPath,
- self.processTests[testProcess])
- print self.filepath
- except KeyError:
- self.ui.errorMsg.setText('Select a process')
- with open(self.filepath) as f:
- lines = f.readlines()
- tests += [line.split(' ', 1)[1].split('(')[0] for line in lines
- if line.strip().startswith('def test_')]
- self.ui.selectTest.clear()
- self.ui.selectTest.addItem('All')
- for test in tests:
- test = re.sub('def','',test)
- self.ui.selectTest.addItem(re.sub('\s','',test))
- def getTest(self):
- test = unicode(self.ui.selectTest.currentText())
- return test
- def runTest(self):
- args = []
- if self.ui.verbose.checkState() == 2: args.append('-v')
- if self.ui.doctest.checkState() == 2: args.append('--with-doctest')
- if self.ui.pyDebug.checkState() == 2: args.append('--pdb')
- if self.ui.pyDebugFails.checkState() == 2: args.append('--pdb-failures')
- testProcess = unicode(self.ui.selectProcess.currentText())
- test = self.getTest()
- # Create the command to run the conversion
- if test == "All":
- cmd = "nosetests {process} {args}".format(process= self.filepath,
- args= ', '.join(args))
- else:
- cmd = "nosetests {process}:{test} {args}".format(process = self.filepath,
- test= test, args= ' '.join(args))
- print cmd
- try:
- # Run the converter tool
- os.system(cmd)
- except OSError, e:
- raise Exception, "Error: ", e
- if __name__ == "__main__":
- app = QtGui.QApplication(sys.argv)
- nosetest = nosetestUI()
- nosetest.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement