def __exit__(self, exc_type, exc_val, tb): if self.thread.profile: self.thread.profile.disable() self.thread.profile.dump_stats(options.profile + str(self.profileNumber)) if exc_val: self.thread.exception = exc_val else: # remove very-short-lived async actions if elapsed_s(self.thread) < min_thread_time_s: vd().threads.remove(self.thread)
def test_baseCommands(self): 'exec each global command at least once' cmdlist = visidata.baseCommands vs = visidata.SheetObject('test_commands', self) vs.reload() for keystrokes in cmdlist.keys(): testname = keystrokes if testname in expectedErrors: continue # print(testname) # visidata.vd.cache_clear() # so vd() returns a new VisiData object for each command vd = visidata.vd() vd.scr = self.scr if testname in inputLines: line = [ch for ch in inputLines[testname]] + ['^J'] vd.getkeystroke = Mock(side_effect=line) else: vd.getkeystroke = Mock(side_effect=['^J']) vs = visidata.SheetObject('test_commands', 'some object') vs.reload() vd.sheets = [vs] vs.draw(self.scr) vs.exec_command(vars(visidata), cmdlist[keystrokes]) self.assertFalse( vd.lastErrors and (keystrokes, cmdlist[keystrokes][2], vd.lastErrors)) vs.checkCursor()
def test_commands(self): 'exec each command at least once' vs = visidata.SheetObject('test_commands', self) vs.reload() for keystrokes in itertools.chain(vs.commands.keys(), visidata.base_commands.keys()): testname = keystrokes # print(testname) if testname in expected_errors: continue if testname in input_lines: line = [ch for ch in input_lines[testname]] + ['^J'] visidata.getkeystroke = Mock(side_effect=line) else: visidata.getkeystroke = Mock(side_effect=['^J']) visidata.vd.cache_clear( ) # so vd() returns a new VisiData object for each command vd = visidata.vd() vs = visidata.SheetObject('test_commands', 'some object') vd.scr = self.scr vd.push(vs) vs.draw(self.scr) vs.exec_command(vars(visidata), keystrokes)
def setUp(self): self.scr = Mock() self.scr.addstr = Mock() self.scr.move = Mock() self.chars = [] visidata.vd().getkeystroke = Mock(side_effect=self.chars)
def reload(self): self.rows = list(vs for vs in self.source.keys() if vs not in vd().sheets)
self.rows = [] for k in options.keys(): opt = options._get(k) self.addRow(opt) self.columns[ 1].name = 'global_value' if self.source == 'override' else 'sheet_value' OptionsSheet.addCommand(None, 'edit-option', 'editOption(cursorRow)') bindkeys.set('e', 'edit-option', OptionsSheet) bindkeys.set(ENTER, 'edit-option', OptionsSheet) vd.optionsSheet = OptionsSheet('global_options', source='override') vd.sheetsSheet = SheetsSheet("sheets", source=vd().sheets) vd.graveyardSheet = GraveyardSheet("sheets_graveyard", source=vd().allSheets) def combineColumns(cols): 'Return Column object formed by joining fields in given columns.' return Column("+".join(c.name for c in cols), getter=lambda col, row, cols=cols, ch=' ': ch.join( c.getDisplayValue(row) for c in cols)) # used ColumnsSheet, affecting the 'row' (source column) ColumnsSheet.addCommand('g!', 'key-selected', 'setKeys(selectedRows or [cursorRow])') ColumnsSheet.addCommand('gz!', 'key-off-selected', 'unsetKeys(selectedRows or [cursorRow])')
def toggleProfiling(t): if not t.profile: t.profile = cProfile.Profile() t.profile.enable() if not options.profile: options.set('profile', 'vdprofile') else: t.profile.disable() t.profile = None options.set('profile', '') status('profiling ' + ('ON' if t.profile else 'OFF')) @functools.wraps(vd().toplevelTryFunc) def threadProfileCode(func, *args, **kwargs): 'Toplevel thread profile wrapper.' with ThreadProfiler(threading.current_thread()) as prof: try: prof.thread.status = threadProfileCode.__wrapped__( func, *args, **kwargs) except EscapeException as e: prof.thread.status = e class ThreadProfiler: numProfiles = 0 def __init__(self, thread): self.thread = thread