Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
unittestgui.TkTestRunner Class Reference
Inheritance diagram for unittestgui.TkTestRunner:
Inheritance graph
[legend]
Collaboration diagram for unittestgui.TkTestRunner:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def initGUI
def getDirectoryToDiscover
def settingsClicked
def notifyTestsDiscovered
def createWidgets
def errorDialog
def notifyRunning
def notifyStopped
def notifyTestStarted
def notifyTestFailed
def notifyTestErrored
def notifyTestSkipped
def notifyTestFailedExpectedly
def notifyTestFinished
def showSelectedError
def runClicked
def stopClicked
def discoverClicked

Public Attributes

 root
 statusVar
 runCountVar
 failCountVar
 errorCountVar
 skipCountVar
 expectFailCountVar
 remainingCountVar
 top
 top_level_dir
 test_file_glob_pattern
 progressBar
 stopGoButton
 errorListbox
 errorInfo
 currentResult
 running
 test_suite
 directory_to_read
 totalTests
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

An implementation of BaseGUITestRunner using Tkinter.

Definition at line 246 of file unittestgui.py.


Member Function Documentation

Creates and packs the various widgets.

Why is it that GUI code always ends up looking a mess, despite all the
best intentions to keep it tidy? Answers on a postcard, please.

Definition at line 290 of file unittestgui.py.

00290 
00291     def createWidgets(self):
00292         """Creates and packs the various widgets.
00293 
00294         Why is it that GUI code always ends up looking a mess, despite all the
00295         best intentions to keep it tidy? Answers on a postcard, please.
00296         """
00297         # Status bar
00298         statusFrame = tk.Frame(self.top, relief=tk.SUNKEN, borderwidth=2)
00299         statusFrame.pack(anchor=tk.SW, fill=tk.X, side=tk.BOTTOM)
00300         tk.Label(statusFrame, width=1, textvariable=self.statusVar).pack(side=tk.TOP, fill=tk.X)
00301 
00302         # Area to enter name of test to run
00303         leftFrame = tk.Frame(self.top, borderwidth=3)
00304         leftFrame.pack(fill=tk.BOTH, side=tk.LEFT, anchor=tk.NW, expand=1)
00305         suiteNameFrame = tk.Frame(leftFrame, borderwidth=3)
00306         suiteNameFrame.pack(fill=tk.X)
00307 
00308         # Progress bar
00309         progressFrame = tk.Frame(leftFrame, relief=tk.GROOVE, borderwidth=2)
00310         progressFrame.pack(fill=tk.X, expand=0, anchor=tk.NW)
00311         tk.Label(progressFrame, text="Progress:").pack(anchor=tk.W)
00312         self.progressBar = ProgressBar(progressFrame, relief=tk.SUNKEN,
00313                                        borderwidth=2)
00314         self.progressBar.pack(fill=tk.X, expand=1)
00315 
00316 
00317         # Area with buttons to start/stop tests and quit
00318         buttonFrame = tk.Frame(self.top, borderwidth=3)
00319         buttonFrame.pack(side=tk.LEFT, anchor=tk.NW, fill=tk.Y)
00320 
00321         tk.Button(buttonFrame, text="Discover Tests",
00322                   command=self.discoverClicked).pack(fill=tk.X)
00323 
00324 
00325         self.stopGoButton = tk.Button(buttonFrame, text="Start",
00326                                       command=self.runClicked, state=tk.DISABLED)
00327         self.stopGoButton.pack(fill=tk.X)
00328 
00329         tk.Button(buttonFrame, text="Close",
00330                   command=self.top.quit).pack(side=tk.BOTTOM, fill=tk.X)
00331         tk.Button(buttonFrame, text="Settings",
00332                   command=self.settingsClicked).pack(side=tk.BOTTOM, fill=tk.X)
00333 
00334         # Area with labels reporting results
00335         for label, var in (('Run:', self.runCountVar),
00336                            ('Failures:', self.failCountVar),
00337                            ('Errors:', self.errorCountVar),
00338                            ('Skipped:', self.skipCountVar),
00339                            ('Expected Failures:', self.expectFailCountVar),
00340                            ('Remaining:', self.remainingCountVar),
00341                            ):
00342             tk.Label(progressFrame, text=label).pack(side=tk.LEFT)
00343             tk.Label(progressFrame, textvariable=var,
00344                      foreground="blue").pack(side=tk.LEFT, fill=tk.X,
00345                                              expand=1, anchor=tk.W)
00346 
00347         # List box showing errors and failures
00348         tk.Label(leftFrame, text="Failures and errors:").pack(anchor=tk.W)
00349         listFrame = tk.Frame(leftFrame, relief=tk.SUNKEN, borderwidth=2)
00350         listFrame.pack(fill=tk.BOTH, anchor=tk.NW, expand=1)
00351         self.errorListbox = tk.Listbox(listFrame, foreground='red',
00352                                        selectmode=tk.SINGLE,
00353                                        selectborderwidth=0)
00354         self.errorListbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=1,
00355                                anchor=tk.NW)
00356         listScroll = tk.Scrollbar(listFrame, command=self.errorListbox.yview)
00357         listScroll.pack(side=tk.LEFT, fill=tk.Y, anchor=tk.N)
00358         self.errorListbox.bind("<Double-1>",
00359                                lambda e, self=self: self.showSelectedError())
00360         self.errorListbox.configure(yscrollcommand=listScroll.set)

Here is the call graph for this function:

Definition at line 96 of file unittestgui.py.

00096 
00097     def discoverClicked(self):
00098         self.__rollbackImporter.rollbackImports()
00099         directory = self.getDirectoryToDiscover()
00100         if not directory:
00101             return
00102         self.directory_to_read = directory
00103         try:
00104             # Explicitly use 'None' value if no top level directory is
00105             # specified (indicated by empty string) as discover() explicitly
00106             # checks for a 'None' to determine if no tld has been specified
00107             top_level_dir = self.top_level_dir or None
00108             tests = unittest.defaultTestLoader.discover(directory, self.test_file_glob_pattern, top_level_dir)
00109             self.test_suite = tests
00110         except:
00111             exc_type, exc_value, exc_tb = sys.exc_info()
00112             traceback.print_exception(*sys.exc_info())
00113             self.errorDialog("Unable to run test '%s'" % directory,
00114                              "Error loading specified test: %s, %s" % (exc_type, exc_value))
00115             return
00116         self.notifyTestsDiscovered(self.test_suite)

Here is the call graph for this function:

def unittestgui.TkTestRunner.errorDialog (   self,
  title,
  message 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 361 of file unittestgui.py.

00361 
00362     def errorDialog(self, title, message):
00363         messagebox.showerror(parent=self.root, title=title,
00364                              message=message)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 270 of file unittestgui.py.

00270 
00271     def getDirectoryToDiscover(self):
00272         return filedialog.askdirectory()

def unittestgui.TkTestRunner.initGUI (   self,
  root,
  initialTestName 
)
Set up the GUI inside the given root window. The test name entry
field will be pre-filled with the given initialTestName.

Definition at line 249 of file unittestgui.py.

00249 
00250     def initGUI(self, root, initialTestName):
00251         """Set up the GUI inside the given root window. The test name entry
00252         field will be pre-filled with the given initialTestName.
00253         """
00254         self.root = root
00255 
00256         self.statusVar = tk.StringVar()
00257         self.statusVar.set("Idle")
00258 
00259         #tk vars for tracking counts of test result types
00260         self.runCountVar = tk.IntVar()
00261         self.failCountVar = tk.IntVar()
00262         self.errorCountVar = tk.IntVar()
00263         self.skipCountVar = tk.IntVar()
00264         self.expectFailCountVar = tk.IntVar()
00265         self.remainingCountVar = tk.IntVar()
00266 
00267         self.top = tk.Frame()
00268         self.top.pack(fill=tk.BOTH, expand=1)
00269         self.createWidgets()

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 365 of file unittestgui.py.

00365 
00366     def notifyRunning(self):
00367         self.runCountVar.set(0)
00368         self.failCountVar.set(0)
00369         self.errorCountVar.set(0)
00370         self.remainingCountVar.set(self.totalTests)
00371         self.errorInfo = []
00372         while self.errorListbox.size():
00373             self.errorListbox.delete(0)
00374         #Stopping seems not to work, so simply disable the start button
00375         #self.stopGoButton.config(command=self.stopClicked, text="Stop")
00376         self.stopGoButton.config(state=tk.DISABLED)
00377         self.progressBar.setProgressFraction(0.0)
00378         self.top.update_idletasks()

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 379 of file unittestgui.py.

00379 
00380     def notifyStopped(self):
00381         self.stopGoButton.config(state=tk.DISABLED)
00382         #self.stopGoButton.config(command=self.runClicked, text="Start")
00383         self.statusVar.set("Idle")

def unittestgui.TkTestRunner.notifyTestErrored (   self,
  test,
  err 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 393 of file unittestgui.py.

00393 
00394     def notifyTestErrored(self, test, err):
00395         self.errorCountVar.set(1 + self.errorCountVar.get())
00396         self.errorListbox.insert(tk.END, "Error: %s" % test)
00397         self.errorInfo.append((test,err))

def unittestgui.TkTestRunner.notifyTestFailed (   self,
  test,
  err 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 388 of file unittestgui.py.

00388 
00389     def notifyTestFailed(self, test, err):
00390         self.failCountVar.set(1 + self.failCountVar.get())
00391         self.errorListbox.insert(tk.END, "Failure: %s" % test)
00392         self.errorInfo.append((test,err))

def unittestgui.TkTestRunner.notifyTestFailedExpectedly (   self,
  test,
  err 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 402 of file unittestgui.py.

00402 
00403     def notifyTestFailedExpectedly(self, test, err):
00404         super(TkTestRunner, self).notifyTestFailedExpectedly(test, err)
00405         self.expectFailCountVar.set(1 + self.expectFailCountVar.get())
00406 

def unittestgui.TkTestRunner.notifyTestFinished (   self,
  test 
)
Override to indicate that a test has finished (it may already have
   failed or errored)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 407 of file unittestgui.py.

00407 
00408     def notifyTestFinished(self, test):
00409         self.remainingCountVar.set(self.remainingCountVar.get() - 1)
00410         self.runCountVar.set(1 + self.runCountVar.get())
00411         fractionDone = float(self.runCountVar.get())/float(self.totalTests)
00412         fillColor = len(self.errorInfo) and "red" or "green"
00413         self.progressBar.setProgressFraction(fractionDone, fillColor)

def unittestgui.TkTestRunner.notifyTestsDiscovered (   self,
  test_suite 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 278 of file unittestgui.py.

00278 
00279     def notifyTestsDiscovered(self, test_suite):
00280         discovered = test_suite.countTestCases()
00281         self.runCountVar.set(0)
00282         self.failCountVar.set(0)
00283         self.errorCountVar.set(0)
00284         self.remainingCountVar.set(discovered)
00285         self.progressBar.setProgressFraction(0.0)
00286         self.errorListbox.delete(0, tk.END)
00287         self.statusVar.set("Discovering tests from %s. Found: %s" %
00288             (self.directory_to_read, discovered))
00289         self.stopGoButton['state'] = tk.NORMAL

def unittestgui.TkTestRunner.notifyTestSkipped (   self,
  test,
  reason 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 398 of file unittestgui.py.

00398 
00399     def notifyTestSkipped(self, test, reason):
00400         super(TkTestRunner, self).notifyTestSkipped(test, reason)
00401         self.skipCountVar.set(1 + self.skipCountVar.get())

def unittestgui.TkTestRunner.notifyTestStarted (   self,
  test 
)

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 384 of file unittestgui.py.

00384 
00385     def notifyTestStarted(self, test):
00386         self.statusVar.set(str(test))
00387         self.top.update_idletasks()

def unittestgui.BaseGUITestRunner.runClicked (   self) [inherited]

Definition at line 77 of file unittestgui.py.

00077 
00078     def runClicked(self):
00079         "To be called in response to user choosing to run a test"
00080         if self.running: return
00081         if not self.test_suite:
00082             self.errorDialog("Test Discovery", "You discover some tests first!")
00083             return
00084         self.currentResult = GUITestResult(self)
00085         self.totalTests = self.test_suite.countTestCases()
00086         self.running = 1
00087         self.notifyRunning()
00088         self.test_suite.run(self.currentResult)
00089         self.running = 0
00090         self.notifyStopped()

Here is the call graph for this function:

Definition at line 273 of file unittestgui.py.

00273 
00274     def settingsClicked(self):
00275         d = DiscoverSettingsDialog(self.top, self.top_level_dir, self.test_file_glob_pattern)
00276         self.top_level_dir = d.top_level_dir
00277         self.test_file_glob_pattern = d.test_file_glob_pattern

Definition at line 414 of file unittestgui.py.

00414 
00415     def showSelectedError(self):
00416         selection = self.errorListbox.curselection()
00417         if not selection: return
00418         selected = int(selection[0])
00419         txt = self.errorListbox.get(selected)
00420         window = tk.Toplevel(self.root)
00421         window.title(txt)
00422         window.protocol('WM_DELETE_WINDOW', window.quit)
00423         test, error = self.errorInfo[selected]
00424         tk.Label(window, text=str(test),
00425                  foreground="red", justify=tk.LEFT).pack(anchor=tk.W)
00426         tracebackLines =  traceback.format_exception(*error)
00427         tracebackText = "".join(tracebackLines)
00428         tk.Label(window, text=tracebackText, justify=tk.LEFT).pack()
00429         tk.Button(window, text="Close",
00430                   command=window.quit).pack(side=tk.BOTTOM)
00431         window.bind('<Key-Return>', lambda e, w=window: w.quit())
00432         window.mainloop()
00433         window.destroy()
00434 

Here is the call graph for this function:

def unittestgui.BaseGUITestRunner.stopClicked (   self) [inherited]

Definition at line 91 of file unittestgui.py.

00091 
00092     def stopClicked(self):
00093         "To be called in response to user stopping the running of a test"
00094         if self.currentResult:
00095             self.currentResult.stop()


Member Data Documentation

Definition at line 56 of file unittestgui.py.

Definition at line 63 of file unittestgui.py.

Definition at line 261 of file unittestgui.py.

Definition at line 370 of file unittestgui.py.

Definition at line 350 of file unittestgui.py.

Definition at line 263 of file unittestgui.py.

Definition at line 260 of file unittestgui.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 311 of file unittestgui.py.

Definition at line 264 of file unittestgui.py.

Definition at line 253 of file unittestgui.py.

Definition at line 259 of file unittestgui.py.

Definition at line 57 of file unittestgui.py.

Definition at line 262 of file unittestgui.py.

Definition at line 255 of file unittestgui.py.

Definition at line 324 of file unittestgui.py.

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 276 of file unittestgui.py.

Definition at line 60 of file unittestgui.py.

Definition at line 266 of file unittestgui.py.

Reimplemented from unittestgui.BaseGUITestRunner.

Definition at line 275 of file unittestgui.py.

Definition at line 84 of file unittestgui.py.


The documentation for this class was generated from the following file: