[py-svn] r11001 - in py/dist/py: . misc/testing test/tkinter

hpk at codespeak.net hpk at codespeak.net
Thu Apr 21 22:42:12 CEST 2005


Author: hpk
Date: Thu Apr 21 22:42:12 2005
New Revision: 11001

Added:
   py/dist/py/test/tkinter/tixsession.py
      - copied, changed from r10994, py/dist/py/test/tkinter/tixgui.py
Modified:
   py/dist/py/__init__.py
   py/dist/py/misc/testing/test_initpkg.py
Log:
let tests mostly pass on platforms that don't have 
tkinter or tix. 



Modified: py/dist/py/__init__.py
==============================================================================
--- py/dist/py/__init__.py	(original)
+++ py/dist/py/__init__.py	Thu Apr 21 22:42:12 2005
@@ -16,7 +16,7 @@
     # for customization of collecting/running tests
     'test.Session'           : ('./test/session.py', 'Session'),
     'test.TerminalSession'   : ('./test/terminal/terminal.py', 'TerminalSession'),
-    'test.TkinterSession'    : ('./test/tkinter/tixgui.py', 'TixSession'),
+    'test.TkinterSession'    : ('./test/tkinter/tixsession.py', 'TixSession'),
     'test.collect.Collector' : ('./test/collect.py', 'Collector'),
     'test.collect.Directory' : ('./test/collect.py', 'Directory'),
     'test.collect.Module'    : ('./test/collect.py', 'Module'),

Modified: py/dist/py/misc/testing/test_initpkg.py
==============================================================================
--- py/dist/py/misc/testing/test_initpkg.py	(original)
+++ py/dist/py/misc/testing/test_initpkg.py	Thu Apr 21 22:42:12 2005
@@ -36,6 +36,7 @@
 def test_importall():
     base = py.path.local(py.__file__).dirpath()
     nodirs = (
+        base.join('test', 'tkinter'), 
         base.join('test', 'testing', 'data'),
         base.join('test', 'testing', 'test'),
         base.join('magic', 'greenlet.py'), 

Copied: py/dist/py/test/tkinter/tixsession.py (from r10994, py/dist/py/test/tkinter/tixgui.py)
==============================================================================
--- py/dist/py/test/tkinter/tixgui.py	(original)
+++ py/dist/py/test/tkinter/tixsession.py	Thu Apr 21 22:42:12 2005
@@ -1,263 +1,4 @@
 import py
-from py.__impl__.test.tkinter import backend
-from py.__impl__.test.tkinter import util
-Null = util.Null
-
-
-import ScrolledText
-from Tkinter import PhotoImage
-import Tix
-from Tkconstants import *
-import re
-import os
-
-class StatusBar(Tix.Frame):
-
-    def __init__(self, master=None, **kw):
-        if master is None:
-            master = Tk()
-        apply(Tix.Frame.__init__, (self, master), kw)
-        self.labels = {}
-
-    def set_label(self, name, text='', side=LEFT):
-        if not self.labels.has_key(name):
-            label = Tix.Label(self, bd=1, relief=SUNKEN, anchor=W)
-            label.pack(side=side)
-            self.labels[name] = label
-        else:
-            label = self.labels[name]
-        label.config(text='%s:\t%s' % (name,text))
-
-    def _get_label(self, name):
-        if not self.labels.has_key(name):
-            self.set_label(name, 'NoText')
-        return self.labels[name]
-
-    def update(self, testrepository):
-        failed = testrepository.keys(testrepository.failed_id)
-        self.set_label('Failed', str(len(failed)))
-        self._get_label('Failed').configure(bg = 'Red', fg = 'White')
-        skipped = testrepository.keys(testrepository.skipped_id)
-        self.set_label('Skipped', str(len(skipped)))
-        self._get_label('Skipped').configure(bg = 'Yellow')
-        self.set_label('Collectors',
-                                  str(len(testrepository.keys())-2))
-        root_report =  testrepository.find()
-        if root_report.status != testrepository.ReportClass.Status.NotExecuted():
-            self.set_label('Time', '%0.2f seconds' % testrepository.find().time)
-        else:
-            self.set_label('Time', '%0.2f seconds' % 0.0)
-
-class ReportListBox(Tix.LabelFrame):
-
-    def __init__(self, *args, **kwargs):
-        Tix.LabelFrame.__init__(self, *args, **kwargs)
-        self.callback = Null()
-        self.data = {}
-        self.createwidgets()
-        self.label.configure(text = 'Idle')
-        
-    def createwidgets(self):
-        self.listbox = Tix.Listbox(self.frame,  foreground='red',
-                                   selectmode=SINGLE)
-
-        self.scrollbar = Tix.Scrollbar(self.frame, command=self.listbox.yview)
-        self.scrollbar.pack(side = RIGHT, fill = Y, anchor = N)
-        self.listbox.pack(side = LEFT, fill = BOTH, expand = YES, anchor = NW)
-        self.listbox.configure(yscrollcommand = self.scrollbar.set)
-
-    def set_callback(self, callback):
-        self.callback = callback
-        self.listbox.bind('<Double-1>', self.do_callback)
-
-    def do_callback(self, *args):
-        report_ids = [self.data[self.listbox.get(int(item))] for item in self.listbox.curselection()]
-        for report_id in report_ids:
-            self.callback(report_id)
-
-    def update_label(self, report_path):
-        label = report_path
-        if not label:
-            label = 'Idle'
-        self.label.configure(text = label)
-
-    def update_list(self, repository):
-        failed_childs = repository.find_children(repository.failed_id)
-        skipped_childs = repository.find_children(repository.skipped_id)
-        if len(failed_childs + skipped_childs) == len(self.data.keys()):
-            return
-        old_selection = [int(sel) for sel in self.listbox.curselection()]
-        self.listbox.delete(0, END)
-        self.data = {}
-        for report_id in failed_childs + skipped_childs:
-            report = repository.find(report_id)
-            label = '%s: %s' % (report.status, report.label)
-            self.data[label] = report.full_id
-            self.listbox.insert(END, label)
-        for index in old_selection:
-            try:
-                self.listbox.select_set(index)
-            except:
-                pass
-            
-        
-
-        
-
-class TixGui:
-
-    def __init__(self, parent, config):
-        self._parent = parent
-        self._config = config
-        self._should_stop = False
-        #XXX needed?
-        self._paths = []
-        self.backend = backend.RepositoryBackend(config)
-        self.createwidgets()
-        self.timer_update()
-
-    def createwidgets(self):
-        self._buttonframe = Tix.Frame(self._parent)
-        self._entry = Tix.FileEntry(self._buttonframe, label = 'Tests:',
-                                    command = self.start_tests)
-        self._entry.pack(side = LEFT, fill = X, expand = YES)
-        self._stop = Tix.Button(self._buttonframe, text = 'Stop',
-                                command = self.stop)
-        self._stop.pack(side = RIGHT)
-        self._run = Tix.Button(self._buttonframe, text = 'Run',
-                               command = self._entry.invoke)
-        self._run.pack(side = RIGHT)
-        self._buttonframe.pack(side = TOP, fill = X)
-        self._reportlist = ReportListBox(self._parent)
-        self._reportlist.label.configure(width=80,anchor=W )
-        self._reportlist.pack(side = TOP, fill = BOTH, expand = YES)
-        self._reportlist.set_callback(self.show_error)
-        #self._tree = reporttree.ReportTree(self._parent, backend = self.backend)
-        #self._tree.pack(side = TOP, fill = BOTH, expand = YES)
-        self._statusbar = StatusBar(self._parent)
-        self._statusbar.pack(side=BOTTOM, fill=X)
-        self.update_status(self.backend.get_repository())
-
-
-    def show_error(self, report_id):
-        report = self.backend.get_repository().find(report_id)
-        window = Tix.Toplevel(self._parent)
-        window.title(report.label)
-        window.protocol('WM_DELETE_WINDOW', window.quit)
-        Tix.Label(window, text='%s: %s' % (report.status, report.label),
-                 foreground="red", justify=LEFT).pack(anchor=W)
-        text = ScrolledText.ScrolledText(window)
-        text.tag_config('sel', relief=FLAT)
-        text.insert(END, report.error_report)
-        if len(report.error_report.splitlines()) < 20:
-            text.config(height=len(report.error_report.splitlines()) + 5)
-        text.yview_pickplace(END)
-        text['state'] = DISABLED
-        text['cursor'] = window['cursor']
-        self.attacheditorhotspots(text)
-        text.pack(expand=1, fill=BOTH)
-        ##
-        b = Tix.Button(window, text="Close",
-                      command=window.quit)
-        b.pack(side=BOTTOM)
-        b.focus_set()
-        window.bind('<Key-Return>', lambda e, w=window: w.quit())
-        window.mainloop()
-        window.destroy()
-
-    def attacheditorhotspots(self, text):
-        # Attach clickable regions to a Text widget.
-        filelink = re.compile(r"""\[(?:testcode\s*:)?\s*(.+):(\d+)\]""")
-        skippedlink = re.compile(r"""in\s+(/.*):(\d+)\s+""")
-        lines = text.get('1.0', END).splitlines(1)
-        if not lines:
-            return
-        tagname = ''
-        start, end = 0,0
-        for index, line in enumerate(lines):
-            match = filelink.search(line)
-            if match is None:
-                match = skippedlink.search(line)
-            if match is None:
-                continue
-            file, line = match.group(1, 2)
-            start, end = match.span()
-            tagname = "ref%d" % index
-            text.tag_add(tagname,
-                         "%d.%d" % (index + 1, start),
-                         "%d.%d" % (index + 1, end))
-            text.tag_bind(tagname, "<Enter>",
-                          lambda e, n=tagname:
-                          e.widget.tag_config(n, underline=1))
-            text.tag_bind(tagname, "<Leave>",
-                          lambda e, n=tagname:
-                          e.widget.tag_config(n, underline=0))
-            text.tag_bind(tagname, "<Button-1>",
-                          lambda e, self=self, f=file, l=line:
-                          self.launch_editor(f, l))
-                    
-    def launch_editor(self, file, line):
-        editor = (py.std.os.environ.get('PYUNIT_EDITOR', None) or
-                  py.std.os.environ.get('EDITOR_REMOTE', None) or
-                  os.environ.get('EDITOR', None) or "emacsclient --no-wait ")
-                  #"emacsclient --no-wait ")
-        if editor:
-            print "%s +%s %s" % (editor, line, file)
-            #py.process.cmdexec('%s +%s %s' % (editor, line, file))
-            os.system('%s +%s %s' % (editor, line, file))
-
-    def timer_update(self):
-        self.backend.update()
-        self._parent.after(100, self.timer_update)
-
-    def start_tests(self, dont_care_event=None):
-        paths = [path.strip() for path in self._entry.entry.get().split(',')]
-        self.backend.set_messages_callback(self.messages_callback)
-        self.backend.set_message_callback(self.message_callback)
-        self.backend.start_tests(args = paths)
-
-    def update_status(self, repository):
-        self._statusbar.update(repository)
-        bgcolor = 'White'
-        fgcolor = 'Black'
-        root_status = repository.root_status()
-        if root_status == repository.ReportClass.Status.Passed():
-            bgcolor = 'Green'
-        elif root_status == repository.ReportClass.Status.Failed():
-            bgcolor = 'Red'
-            fgcolor = 'White'
-        elif root_status == repository.ReportClass.Status.Skipped() :
-            bgcolor = 'Yellow'
-        self._entry.entry.configure(bg = bgcolor, fg = fgcolor)
-                
-    def messages_callback(self, report_ids):
-        if not report_ids:
-            return
-        repository = self.backend.get_repository()
-        self.update_status(repository)
-        self._reportlist.update_list(repository)
-
-    def message_callback(self, report_id):
-        if report_id is None:
-            report_label = None
-        else:
-            report_label = self.backend.get_repository().find(report_id).path
-        self._reportlist.update_label(report_label)
-        
-    def set_paths(self, paths):
-        self._paths = paths
-        self._entry.entry.insert(END, ', '.join(paths))
-
-    def stop(self):
-        self.backend.shutdown()
-        self.backend.update()
-        self.messages_callback([None])
-        self.message_callback(None)
-
-    def shutdown(self):
-        self.should_stop = True
-        self.backend.shutdown()
-        py.std.sys.exit()
 
 class TixSession:
     def __init__(self, config):
@@ -265,6 +6,7 @@
         
     def main(self, paths):
         root = Tix.Tk()
+        from tixgui import TixGui 
         tixgui = TixGui(root, self.config)
         tixgui.set_paths(paths)
         root.protocol('WM_DELETE_WINDOW', tixgui.shutdown)



More information about the pytest-commit mailing list