Package pysys :: Package manual :: Module ui
[hide private]
[frames] | no frames]

Source Code for Module pysys.manual.ui

  1  #!/usr/bin/env python 
  2  # PySys System Test Framework, Copyright (C) 2006-2013  M.B.Grieve 
  3   
  4  # This library is free software; you can redistribute it and/or 
  5  # modify it under the terms of the GNU Lesser General Public 
  6  # License as published by the Free Software Foundation; either 
  7  # version 2.1 of the License, or (at your option) any later version. 
  8   
  9  # This library is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 12  # Lesser General Public License for more details. 
 13   
 14  # You should have received a copy of the GNU Lesser General Public 
 15  # License along with this library; if not, write to the Free Software 
 16  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
 17   
 18  # Contact: moraygrieve@users.sourceforge.net 
 19   
 20  try: 
 21          import tkMessageBox 
 22          from Tkinter import * 
 23  except: 
 24          pass 
 25   
 26  from pysys.constants import * 
 27  from pysys.exceptions import * 
 28  from pysys.xml.manual import * 
 29   
 30   
31 -class ManualTester:
32 - def __init__(self, owner, filename, logname=None):
33 self.owner = owner 34 self.isRunning = 1 35 self.intToRes = ["FAILED", "PASSED", "N/A"] 36 self.logicMap = {"false" : 0, "true" : 1, "" : 1, 0 : "false", 1 : "true"} 37 self.filename = filename 38 self.steps = self.parseInputXML(self.filename) 39 self.currentStep = -1 40 self.results = {} 41 self.defect = ""
42
43 - def build(self):
44 self.parentContainer = Tk() 45 self.parentContainer.protocol('WM_DELETE_WINDOW', self.quitPressed) 46 self.parentContainer.wm_geometry("500x400") 47 self.parentContainer.title("PySys Manual Tester - [%s]" % self.owner.descriptor.id) 48 self.parentContainer.resizable(True, True) 49 self.container = Frame(self.parentContainer) 50 self.containerDetails = Frame(self.container) 51 self.titleBox = Label(self.containerDetails, text="Test Title Here", font=("Verdana 10 "), anchor=W, wraplength=480) 52 self.titleBox.pack(fill=X) 53 self.messageBoxDetails = Text(self.containerDetails, wrap=WORD, width=1, height=1, padx=10, pady=10) 54 self.messageBoxDetails.insert(INSERT, "Test Body Here") 55 self.messageBoxDetails.pack(fill=BOTH, expand=YES, side=LEFT) 56 self.yscrollbarDetails = Scrollbar(self.containerDetails, orient=VERTICAL) 57 self.yscrollbarDetails.pack(fill=Y, side=LEFT) 58 self.yscrollbarDetails.config(command=self.messageBoxDetails.yview) 59 self.containerDetails.pack(fill=BOTH, expand=YES, padx=5, pady=5) 60 self.messageBoxDetails.config(yscrollcommand=self.yscrollbarDetails.set, font=("Helvetica 10")) 61 self.containerExpected = Frame(self.container) 62 self.labelExpected = Label(self.containerExpected, text="Expected Result", font=("Verdana 10"), anchor=W) 63 self.labelExpected.pack(fill=X) 64 self.messageBoxExpected = Text(self.containerExpected, wrap=WORD, width=1, height=1, padx=10, pady=10) 65 self.messageBoxExpected.insert(INSERT, "Test Body Here") 66 self.messageBoxExpected.pack(fill=BOTH, expand=YES, side=LEFT) 67 self.yscrollbarExpected = Scrollbar(self.containerExpected, orient=VERTICAL) 68 self.yscrollbarExpected.pack(fill=Y, side=LEFT) 69 self.yscrollbarExpected.config(command=self.messageBoxExpected.yview) 70 self.containerExpected.pack(fill=BOTH, expand=YES, padx=5, pady=5) 71 self.messageBoxExpected.config(yscrollcommand=self.yscrollbarExpected.set, font=("Helvetica 10")) 72 self.container.pack(fill=BOTH, expand=YES, padx=5, pady=5) 73 self.separator = Frame(height=2, bd=1, relief=SUNKEN) 74 self.separator.pack(fill=X, pady=2) 75 self.inputContainer = Frame(self.parentContainer, relief=GROOVE) 76 self.quitButton = Button(self.inputContainer, text="Quit", command=self.quitPressed, pady=5, padx=5, font=("Verdana 9 bold")) 77 self.quitButton.pack(side=LEFT, padx=5, pady=5) 78 self.backButton = Button(self.inputContainer, text="< Back", command=self.backPressed, state=DISABLED, pady=5, padx=5, font=("Verdana 9 bold")) 79 self.backButton.pack(side=LEFT, padx=5, pady=5) 80 self.multiButton = Button(self.inputContainer, text="Start", command=self.multiPressed, default=ACTIVE, pady=5, padx=5, font=("Verdana 9 bold")) 81 self.multiButton.pack(side=RIGHT, padx=5, pady=5) 82 self.failButton = Button(self.inputContainer, text="Fail", command=self.failPressed, pady=5, padx=5, font=("Verdana 9 bold")) 83 self.failButton.pack(side=RIGHT, padx=5, pady=5) 84 self.inputContainer.pack(fill=X, padx=5, pady=5) 85 self.doStep()
86
87 - def quitPressed(self):
88 self.owner.log.critical("Application terminated by user (BLOCKED)") 89 self.owner.outcome.append(BLOCKED) 90 self.stop()
91
92 - def backPressed(self):
93 if self.currentStep >= 0: 94 self.currentStep = self.currentStep - 1 95 self.doStep()
96
97 - def failPressed(self):
98 if self.currentStep >= 0: 99 self.results[self.currentStep] = 0 100 self.currentStep = self.currentStep + 1 101 self.doStep()
102
103 - def multiPressed(self):
104 if self.currentStep == len(self.steps): 105 self.stop() 106 return 107 elif self.currentStep >= 0: 108 if self.steps[self.currentStep].validate == 'true': 109 self.results[self.currentStep] = 1 110 else: self.results[self.currentStep] = 2 111 self.currentStep = self.currentStep + 1 112 self.doStep()
113
114 - def doStep(self):
115 self.messageBoxDetails.config(state=NORMAL) 116 self.messageBoxDetails.delete(1.0, END) 117 self.messageBoxExpected.config(state=NORMAL) 118 self.messageBoxExpected.delete(1.0, END) 119 if self.currentStep < 0: 120 self.multiButton.config(text="Start") 121 self.backButton.config(state=DISABLED) 122 self.failButton.forget() 123 self.containerExpected.forget() 124 self.messageBoxDetails.insert(INSERT, self.owner.descriptor.purpose) 125 self.titleBox.config(text="Title - %s" % self.owner.descriptor.title) 126 elif self.currentStep == len(self.steps): 127 self.multiButton.config(text="Finish") 128 self.containerExpected.forget() 129 self.messageBoxDetails.insert(INSERT, self.reportToString()) 130 self.titleBox.config(text="Test Complete - Summary Report") 131 elif self.currentStep >= 0: 132 self.backButton.config(state=NORMAL) 133 self.failButton.pack(side=RIGHT, padx=5, pady=5) 134 self.multiButton.config(text="Pass") 135 self.failButton.config(text="Fail") 136 self.messageBoxDetails.insert(INSERT, self.steps[self.currentStep].description) 137 expectedResult = self.steps[self.currentStep].expectedResult 138 if expectedResult != "": 139 self.messageBoxExpected.insert(INSERT, expectedResult) 140 self.containerExpected.pack(side=TOP, fill=BOTH, expand=YES, padx=5, pady=5) 141 else: 142 self.containerExpected.forget() 143 self.titleBox.config(text="Step %s of %s - %s" % (self.currentStep + 1, len(self.steps), self.steps[self.currentStep].title)) 144 if self.steps[self.currentStep].validate == 'false': 145 self.multiButton.config(text="Next >") 146 self.failButton.forget() 147 self.messageBoxDetails.config(state=DISABLED) 148 self.messageBoxExpected.config(state=DISABLED)
149
150 - def dlgSavePressed(self):
151 self.defect = self.dlgTextField.get() 152 self.dlg.destroy()
153
154 - def dlgNoPressed(self):
155 self.dlg.destroy()
156
157 - def reportToString(self):
158 result = "" 159 for r in range(len(self.steps)): 160 try: 161 result += "\nStep %s - %s: %s" % (r + 1, self.steps[r].title, self.intToRes[self.results[r]]) 162 except: pass 163 if self.defect != "": result += "\n\nDefect - %s recorded with test failure" % self.defect 164 return result
165
166 - def logResults(self):
167 for r in range(len(self.results)): 168 if r < self.currentStep: 169 try: 170 self.owner.log.info("Step %s - %s: %s" % (r + 1, self.steps[r].title, self.intToRes[self.results[r]])) 171 if self.results[r] == 0: self.owner.outcome.append(FAILED) 172 elif self.results[r] == 1: self.owner.outcome.append(PASSED) 173 except: pass 174 if self.defect != "": self.owner.log.info("Defect - %s recorded with test failure" % self.defect)
175
176 - def start(self):
177 self.build() 178 self.parentContainer.mainloop()
179
180 - def stop(self):
181 self.logResults() 182 self.isRunning = 0 183 self.parentContainer.quit() 184 self.parentContainer.destroy()
185
186 - def running(self):
187 return self.isRunning
188
189 - def parseInputXML(self, input):
190 parser = XMLManualTestParser(input) 191 steps = parser.getSteps() 192 parser.unlink() 193 return steps
194