source: trunk/tester/testview.tcl @ 2055

Last change on this file since 2055 was 2055, checked in by braffert, 13 years ago

Regression tester: cleaning up and adding comments

File size: 10.1 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: testview - display the results of a test
3#
4#  Entire right hand side of the regression tester.  Displays the
5#  golden test results, and compares them to the new results if the test
6#  has been ran.  Also show tree representation of all inputs and
7#  outputs.  The -test configuration option is used to provide a Test
8#  object to display.
9# ======================================================================
10#  AUTHOR:  Ben Rafferty, Purdue University
11#  Copyright (c) 2010  Purdue Research Foundation
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Itk
17package require BLT
18
19namespace eval Rappture::Tester::TestView { #forward declaration }
20
21option add *TestView.font \
22    -*-helvetica-medium-r-normal-*-12-* widgetDefault
23option add *TestView.codeFont \
24    -*-courier-medium-r-normal-*-12-* widgetDefault
25option add *TestView.textFont \
26    -*-helvetica-medium-r-normal-*-12-* widgetDefault
27option add *TestView.boldTextFont \
28    -*-helvetica-bold-r-normal-*-12-* widgetDefault
29
30itcl::class Rappture::Tester::TestView {
31    inherit itk::Widget
32
33    itk_option define -test test Test ""
34
35    constructor {args} { #defined later }
36
37    protected method reset
38    protected method showDescription {text}
39    protected method showStatus {text}
40    protected method updateResults {}
41    protected method updateInputs {}
42    protected method updateOutputs {}
43
44}
45
46# ----------------------------------------------------------------------
47# CONSTRUCTOR
48# ----------------------------------------------------------------------
49itcl::body Rappture::Tester::TestView::constructor {args} {
50
51    itk_component add status {
52        label $itk_interior.status
53    }
54    pack $itk_component(status) -expand no -fill none -side top -anchor w
55
56    itk_component add descScroller {
57        Rappture::Scroller $itk_interior.descScroller \
58            -xscrollmode auto -yscrollmode auto
59    }
60
61    itk_component add description {
62        text $itk_interior.descScroller.description -height 0 -wrap word \
63            -relief flat
64    }
65    $itk_component(descScroller) contents $itk_component(description)
66    pack $itk_component(descScroller) -expand no -fill x -side top
67
68    itk_component add tabs {
69        blt::tabset $itk_interior.tabs -borderwidth 0 -relief flat \
70            -side left -tearoff 0 -highlightthickness 0 \
71            -selectbackground $itk_option(-background)
72    } {
73    }
74    $itk_component(tabs) insert end "Results" -ipady 25 -fill both
75    $itk_component(tabs) insert end "Inputs" -ipady 25 -fill both \
76        -state disabled
77    $itk_component(tabs) insert end "Outputs" -ipady 25 -fill both \
78        -state disabled
79
80    itk_component add results {
81        Rappture::ResultsPage $itk_component(tabs).results
82    }
83    $itk_component(tabs) tab configure "Results" \
84        -window $itk_component(tabs).results
85
86    itk_component add inputScroller {
87        Rappture::Scroller $itk_component(tabs).inputScroller \
88            -xscrollmode auto -yscrollmode auto
89    }
90
91    itk_component add inputs {
92        blt::treeview $itk_component(inputScroller).inputs -separator . \
93            -autocreate true
94    } {
95        keep -foreground -font -cursor
96    }
97    $itk_component(inputs) column insert end "Value"
98    $itk_component(inputScroller) contents $itk_component(inputs)
99    $itk_component(tabs) tab configure "Inputs" \
100        -window $itk_component(inputScroller)
101
102    itk_component add outputScroller {
103        Rappture::Scroller $itk_component(tabs).outputScroller \
104            -xscrollmode auto -yscrollmode auto
105    }
106
107    itk_component add outputs {
108        blt::treeview $itk_component(outputScroller).outputs -separator . \
109            -autocreate true
110    } {
111        keep -foreground -font -cursor
112    }
113    $itk_component(outputs) column insert end "Status"
114    $itk_component(outputScroller) contents $itk_component(outputs)
115    $itk_component(tabs) tab configure "Outputs" \
116        -window $itk_component(outputScroller)
117
118    pack $itk_component(tabs) -expand yes -fill both -side top
119
120    eval itk_initialize $args
121
122}
123
124# ----------------------------------------------------------------------
125# CONFIGURATION OPTION: -test
126#
127# When the -test configuration option is modified, update the display
128# accordingly.  The data passed in should be a Test object, or an empty
129# string to clear the display.
130# ----------------------------------------------------------------------
131itcl::configbody Rappture::Tester::TestView::test {
132    set test $itk_option(-test)
133    # If an empty string is passed in then clear everything
134    if {$test == ""} {
135        reset
136    } else {
137        if {![$test isa Test]} {
138            error "-test option must be a Test object.  $test was given."
139        }
140        if {[$test hasRan]} {
141            switch [$test getResult] {
142                Pass {showStatus "Test passed."}
143                Fail {showStatus "Test failed."}
144                Error {showStatus "Error while running test."}
145            }
146        } else {
147            showStatus "Test has not yet ran."
148        }
149        updateResults
150        updateInputs
151        updateOutputs
152        set descr [[$test getTestobj] get test.description]
153        if {$descr == ""} {
154            set descr "No description."
155        }
156        showDescription $descr
157    }
158}
159
160itk::usual TestView {
161    keep -background -foreground -font
162}
163
164# ----------------------------------------------------------------------
165# USAGE: reset
166#
167# Resets the entire TestView widget back to the default state.
168# ----------------------------------------------------------------------
169itcl::body Rappture::Tester::TestView::reset {} {
170    updateResults
171    updateInputs
172    updateOutputs
173    showStatus ""
174    showDescription ""
175}
176
177# ----------------------------------------------------------------------
178# USAGE: showDescription <text>
179#
180# Displays a string in the description text space near the top of the
181# widget.  If given an empty string, disable the sunken relief effect
182# to partially hide the text box.
183# ----------------------------------------------------------------------
184itcl::body Rappture::Tester::TestView::showDescription {text} {
185    $itk_component(description) configure -state normal
186    $itk_component(description) delete 0.0 end
187    $itk_component(description) insert end "$text"
188    $itk_component(description) configure -state disabled
189    if {$text == ""} {
190        $itk_component(description) configure -relief flat
191    } else {
192        $itk_component(description) configure -relief sunken
193    }
194}
195
196# ----------------------------------------------------------------------
197# USAGE: showStatus <text>
198#
199# Displays a string in the status info space at the top of the widget.
200# ----------------------------------------------------------------------
201itcl::body Rappture::Tester::TestView::showStatus {text} {
202    $itk_component(status) configure -text "$text"
203}
204
205# ----------------------------------------------------------------------
206# USAGE: updateResults
207
208# Used internally to update the results tab according to the test
209# currently specified by the -test configuration option.  Show the
210# golden results contained in the test xml, and if the the test has been
211# ran, show the new results as well.
212# ----------------------------------------------------------------------
213itcl::body Rappture::Tester::TestView::updateResults {} {
214    $itk_component(results) clear -nodelete
215    set test $itk_option(-test)
216    if {$test == ""} {
217        # Already cleared, do nothing.
218        # TODO: Eventually display some kinds of message here.
219    } else {
220        set test $itk_option(-test)
221        $itk_component(results) load [$test getTestobj]
222        if {[$test hasRan]  && [Rappture::library isvalid [$test getRunobj]]} {
223            $itk_component(results) load [$test getRunobj]
224        }
225    }
226}
227
228# ----------------------------------------------------------------------
229# USAGE: updateInputs
230#
231# Used internally to update the inputs tab according to the test
232# currently specified by the -test configuration option.  Shows a tree
233# representation of all inputs given in the test xml and their given
234# values.
235# ----------------------------------------------------------------------
236itcl::body Rappture::Tester::TestView::updateInputs {} {
237    $itk_component(inputs) delete 0
238    set test $itk_option(-test)
239    if {$test != ""} {
240        $itk_component(tabs) tab configure "Inputs" -state normal
241        foreach {path val} [$test getInputs] {
242            $itk_component(inputs) insert end $path -data [list Value $val]
243        }
244        $itk_component(inputs) open -recurse root
245    }
246}
247
248# ----------------------------------------------------------------------
249# USAGE: updateOutputs
250#
251# Used internally to update the outputs tab according to the test
252# currently specified by the -test configuration option.  Shows a tree
253# representation of all outputs in the runfile generated by the last run
254# of the test, along with their status (ok, diff, added, or missing).
255# Disable the outputs tab if test has not been ran, or resulted in an
256# error.
257# ----------------------------------------------------------------------
258itcl::body Rappture::Tester::TestView::updateOutputs {} {
259    $itk_component(outputs) delete 0
260    set test $itk_option(-test)
261    if {$test != "" && [$test hasRan] && [$test getResult] != "Error"} {
262        $itk_component(tabs) tab configure "Outputs" -state normal
263        foreach {path status} [$test getOutputs] {
264            $itk_component(outputs) insert end $path -data [list Status $status]
265        }
266        $itk_component(outputs) open -recurse root
267    } else {
268        $itk_component(tabs) tab configure "Outputs" -state disabled
269        # Switch back to results tab if the outputs tab is open and the
270        # selected test has not been ran.
271        if {[$itk_component(tabs) index select] == \
272            [$itk_component(tabs) index -name "Outputs"]} {
273            set index [$itk_component(tabs) index -name "Results"]
274            $itk_component(tabs) select $index
275            $itk_component(tabs) focus $index
276        }
277    }
278}
279       
280       
281
Note: See TracBrowser for help on using the repository browser.