<s> from threading import Thread <EOL> import contextlib <EOL> import os <EOL> import unittest <EOL> import sublime <EOL> import sublime_plugin <EOL> class __vi_tests_write_buffer ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit , text = '<STR_LIT>' ) : <EOL> self . view . replace ( edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) , text ) <EOL> class __vi_tests_erase_all ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit ) : <EOL> self . view . erase ( edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) <EOL> class OutputPanel ( object ) : <EOL> def __init__ ( self , name , <EOL> file_regex = '<STR_LIT>' , <EOL> line_regex = '<STR_LIT>' , <EOL> base_dir = None , <EOL> word_wrap = False , <EOL> line_numbers = False , <EOL> gutter = False , <EOL> scroll_past_end = False , <EOL> syntax = '<STR_LIT>' , <EOL> ) : <EOL> self . name = name <EOL> self . window = sublime . active_window ( ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . output_view = self . window . create_output_panel ( self . name ) <EOL> if ( not base_dir and self . window . active_view ( ) and <EOL> self . window . active_view ( ) . file_name ( ) ) : <EOL> base_dir = os . path . dirname ( <EOL> self . window . active_view ( ) . file_name ( ) <EOL> ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , file_regex ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , line_regex ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , base_dir ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , word_wrap ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , line_numbers ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , gutter ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , scroll_past_end ) <EOL> self . output_view . settings ( ) . set ( '<STR_LIT>' , syntax ) <EOL> self . window . create_output_panel ( self . name ) <EOL> def write ( self , s ) : <EOL> f = lambda : self . output_view . run_command ( '<STR_LIT>' , { '<STR_LIT>' : s } ) <EOL> sublime . set_timeout ( f , <NUM_LIT:0> ) <EOL> def flush ( self ) : <EOL> pass <EOL> def show ( self ) : <EOL> self . window . run_command ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' + self . name } <EOL> ) <EOL> def close ( self ) : <EOL> pass <EOL> class RunVintageousTests ( sublime_plugin . WindowCommand ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , working_dir , <EOL> loader_pattern = "<STR_LIT>" , <EOL> tests_dir = "<STR_LIT>" , <EOL> ** kwargs ) : <EOL> assert os . path . exists ( working_dir ) , '<STR_LIT>' <EOL> with self . chdir ( working_dir ) : <EOL> p = os . path . join ( os . getcwd ( ) , tests_dir ) <EOL> patt = loader_pattern <EOL> if kwargs . get ( '<STR_LIT>' ) is True : <EOL> patt = os . path . basename ( self . window . active_view ( ) . file_name ( ) ) <EOL> if patt . endswith ( ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> patt = '<STR_LIT>' <EOL> suite = unittest . TestLoader ( ) . discover ( p , pattern = patt ) <EOL> file_regex = r'<STR_LIT>' <EOL> display = OutputPanel ( '<STR_LIT>' , <EOL> file_regex = file_regex , <EOL> word_wrap = True <EOL> ) <EOL> display . show ( ) <EOL> runner = unittest . TextTestRunner ( stream = display , verbosity = <NUM_LIT:1> ) <EOL> def run_and_display ( ) : <EOL> runner . run ( suite ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> Thread ( target = run_and_display ) . start ( ) <EOL> @ contextlib . contextmanager <EOL> def chdir ( self , path = None ) : <EOL> old_path = os . getcwd ( ) <EOL> if path : <EOL> assert os . path . exists ( path ) , "<STR_LIT>" . format ( path ) <EOL> os . chdir ( path ) <EOL> yield <EOL> if path is not None : <EOL> os . chdir ( old_path ) </s>
