def test_tree_watcher(self): tw = create_tree_watcher(get_fallback_logger()) subdir = os.path.join(INOTIFY_DIR, 'subdir') os.mkdir(subdir) if tw.watch(INOTIFY_DIR).is_dummy: raise SkipTest('No tree watcher available') self.assertTrue(tw(INOTIFY_DIR)) self.assertFalse(tw(INOTIFY_DIR)) changed = partial(self.do_test_for_change, tw, INOTIFY_DIR) open(os.path.join(INOTIFY_DIR, 'tree1'), 'w').close() changed() open(os.path.join(subdir, 'tree1'), 'w').close() changed() os.unlink(os.path.join(subdir, 'tree1')) changed() os.rmdir(subdir) changed() os.mkdir(subdir) changed() os.rename(subdir, subdir + '1') changed() shutil.rmtree(subdir + '1') changed() os.mkdir(subdir) f = os.path.join(subdir, 'f') open(f, 'w').close() changed() with open(f, 'a') as s: s.write(' ') changed() os.rename(f, f + '1') changed()
def test_inotify_file_watcher_is_watching(self, use_bytes=use_bytes): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='inotify') except INotifyError: raise SkipTest('INotify is not available') self.do_test_file_watcher_is_watching(w, use_bytes)
def test_inotify_tree_watcher(self, use_bytes=use_bytes): try: tw = create_tree_watcher(get_fallback_logger(), watcher_type='inotify') except INotifyError: raise SkipTest('INotify is not available') self.do_test_tree_watcher(tw, use_bytes)
def test_uv_tree_watcher(self, use_bytes=use_bytes): raise SkipTest('Uv watcher tests are not stable') try: tw = create_tree_watcher(get_fallback_logger(), 'uv') except UvNotFound: raise SkipTest('Pyuv is not available') self.do_test_tree_watcher(tw, use_bytes)
def test_uv_file_watcher_is_watching(self, use_bytes=use_bytes): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='uv') except UvNotFound: raise SkipTest('Pyuv is not available') self.do_test_file_watcher_is_watching(w, use_bytes)
def test_uv_file_watcher(self, use_bytes=use_bytes): raise SkipTest('Uv watcher tests are not stable') try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='uv') except UvNotFound: raise SkipTest('Pyuv is not available') self.do_test_file_watcher(w, use_bytes)
def test_uv_file_watcher(self): raise SkipTest('Uv watcher tests are not stable') try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='uv') except UvNotFound: raise SkipTest('Pyuv is not available') return self.do_test_file_watcher(w)
def test_inotify_file_watcher(self, use_bytes=use_bytes): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='inotify') except INotifyError: raise SkipTest( 'This test is not suitable for a stat based file watcher') self.do_test_file_watcher(w, use_bytes)
def test_file_watcher(self): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='inotify') except INotifyError: raise SkipTest('This test is not suitable for a stat based file watcher') f1, f2, f3 = map(lambda x: os.path.join(INOTIFY_DIR, 'file%d' % x), (1, 2, 3)) with open(f1, 'wb'): with open(f2, 'wb'): with open(f3, 'wb'): pass ne = os.path.join(INOTIFY_DIR, 'notexists') self.assertRaises(OSError, w, ne) self.assertTrue(w(f1)) self.assertTrue(w(f2)) os.utime(f1, None), os.utime(f2, None) self.do_test_for_change(w, f1) self.do_test_for_change(w, f2) # Repeat once os.utime(f1, None), os.utime(f2, None) self.do_test_for_change(w, f1) self.do_test_for_change(w, f2) # Check that no false changes are reported self.assertFalse(w(f1), 'Spurious change detected') self.assertFalse(w(f2), 'Spurious change detected') # Check that open the file with 'w' triggers a change with open(f1, 'wb'): with open(f2, 'wb'): pass self.do_test_for_change(w, f1) self.do_test_for_change(w, f2) # Check that writing to a file with 'a' triggers a change with open(f1, 'ab') as f: f.write(b'1') self.do_test_for_change(w, f1) # Check that deleting a file registers as a change os.unlink(f1) self.do_test_for_change(w, f1) # Test that changing the inode of a file does not cause it to stop # being watched os.rename(f3, f2) self.do_test_for_change(w, f2) self.assertFalse(w(f2), 'Spurious change detected') os.utime(f2, None) self.do_test_for_change(w, f2)
def test_stat_file_watcher_is_watching(self, use_bytes=use_bytes): w = create_file_watcher(pl=get_fallback_logger(), watcher_type='stat') self.do_test_file_watcher_is_watching(w, use_bytes)
def test_uv_tree_watcher(self): raise SkipTest('Uv watcher tests are not stable') tw = create_tree_watcher(get_fallback_logger(), 'uv') return self.do_test_tree_watcher(tw)
def test_stat_file_watcher_is_watching(self): w = create_file_watcher(pl=get_fallback_logger(), watcher_type='stat') return self.do_test_file_watcher_is_watching(w)
def get_fallback_create_watcher(): from powerline.lib.watcher import create_file_watcher from powerline import get_fallback_logger from functools import partial return partial(create_file_watcher, get_fallback_logger(), 'auto')
def test_tree_watcher(self): tw = create_tree_watcher(get_fallback_logger()) return self.do_test_tree_watcher(tw)
def main(): VTERM_TEST_DIR = os.path.abspath('tests/vterm') vterm_path = os.path.join(VTERM_TEST_DIR, 'path') socket_path = os.path.join(VTERM_TEST_DIR, 'tmux-socket') rows = 50 cols = 200 tmux_exe = os.path.join(vterm_path, 'tmux') try: p = ExpectProcess( lib='tests/bot-ci/deps/libvterm/libvterm.so', rows=rows, cols=cols, cmd=tmux_exe, args=[ # Specify full path to tmux socket (testing tmux instance must # not interfere with user one) '-S', socket_path, # Force 256-color mode '-2', # Request verbose logging just in case '-v', # Specify configuration file '-f', os.path.abspath('powerline/bindings/tmux/powerline.conf'), # Run bash three times 'new-session', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', ], cwd=VTERM_TEST_DIR, env={ # Reasoning: # 1. vt* TERMs (used to be vt100 here) make tmux-1.9 use # different and identical colors for inactive windows. This # is not like tmux-1.6: foreground color is different from # separator color and equal to (0, 102, 153) for some reason # (separator has correct color). tmux-1.8 is fine, so are # older versions (though tmux-1.6 and tmux-1.7 do not have # highlighting for previously active window) and my system # tmux-1.9a. # 2. screen, xterm and some other non-256color terminals both # have the same issue and make libvterm emit complains like # `Unhandled CSI SGR 3231`. # 3. screen-256color, xterm-256color and other -256color # terminals make libvterm emit complains about unhandled # escapes to stderr. # 4. `st-256color` does not have any of the above problems, but # it may be not present on the target system because it is # installed with x11-terms/st and not with sys-libs/ncurses. # # For the given reasons decision was made: to fix tmux-1.9 tests # and not make libvterm emit any data to stderr st-256color # $TERM should be used, up until libvterm has its own terminfo # database entry (if it ever will). To make sure that relevant # terminfo entry is present on the target system it should be # distributed with powerline test package. To make distribution # not require modifying anything outside of powerline test # directory TERMINFO variable is set. 'TERMINFO': os.path.join(VTERM_TEST_DIR, 'terminfo'), 'TERM': 'st-256color', 'PATH': vterm_path, 'SHELL': os.path.join(''), 'POWERLINE_CONFIG_PATHS': os.path.abspath('powerline/config_files'), 'POWERLINE_COMMAND': 'powerline-render', 'POWERLINE_THEME_OVERRIDES': ( 'default.segments.right=[{"type":"string","name":"s1","highlight_groups":["cwd"]}];' 'default.segments.left=[{"type":"string","name":"s2","highlight_groups":["background"]}];' 'default.segment_data.s1.contents=S1 string here;' 'default.segment_data.s2.contents=S2 string here;' ), 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), 'PYTHONPATH': os.environ.get('PYTHONPATH', ''), }, ) p.start() sleep(10) last_line = [] for col in range(cols): last_line.append(p[rows - 1, col]) result = tuple(( (key, ''.join((i.text for i in subline))) for key, subline in groupby(last_line, lambda i: i.cell_properties_key) )) expected_result_new = ( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ) expected_result_old = ( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ) print('Result:') shesc_result = ''.join(( '{0}{1}\x1b[m'.format(cell_properties_key_to_shell_escape(key), text) for key, text in result )) print(shesc_result) print('Expected:') tmux_version = get_tmux_version(get_fallback_logger()) if tmux_version < (1, 8): expected_result = expected_result_old else: expected_result = expected_result_new shesc_expected_result = ''.join(( '{0}{1}\x1b[m'.format(cell_properties_key_to_shell_escape(key), text) for key, text in expected_result )) print(shesc_expected_result) if result == expected_result: return True else: p.send(b'powerline-config tmux setup\n') sleep(5) print('Screen:') screen = [] for i in range(rows): screen.append([]) for j in range(cols): screen[-1].append(p[i, j]) print('\n'.join( ''.join(( '{0}{1}\x1b[m'.format( cell_properties_key_to_shell_escape(i.cell_properties_key), i.text ) for i in line )) for line in screen )) a = shesc_result.replace('\x1b', '\\e') + '\n' b = shesc_expected_result.replace('\x1b', '\\e') + '\n' print('_' * 80) print('Diff:') print('=' * 80) print(''.join((u(line) for line in ndiff([a], [b])))) return False finally: check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={ 'PATH': vterm_path, 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), })
if watcher_type == 'inotify': # Explicitly selected inotify watcher: do not catch INotifyError then. pl.debug('Using requested inotify watcher', prefix='watcher') return INotifyWatch(expire_time=expire_time) if sys.platform.startswith('linux'): try: pl.debug('Trying to use inotify watcher', prefix='watcher') return INotifyWatch(expire_time=expire_time) except INotifyError: pl.info('Failed to create inotify watcher', prefix='watcher') pl.debug('Using stat-based watcher') return StatWatch() if __name__ == '__main__': from powerline import get_fallback_logger watcher = create_file_watcher(get_fallback_logger()) print ('Using watcher: %s' % watcher.__class__.__name__) print ('Watching %s, press Ctrl-C to quit' % sys.argv[-1]) watcher.watch(sys.argv[-1]) try: while True: if watcher(sys.argv[-1]): print ('%s has changed' % sys.argv[-1]) sleep(1) except KeyboardInterrupt: pass watcher.close()
def main(attempts=3): vterm_path = os.path.join(VTERM_TEST_DIR, 'path') socket_path = 'tmux-socket' rows = 50 cols = 200 tmux_exe = os.path.join(vterm_path, 'tmux') if os.path.exists('tests/bot-ci/deps/libvterm/libvterm.so'): lib = 'tests/bot-ci/deps/libvterm/libvterm.so' else: lib = os.environ.get('POWERLINE_LIBVTERM', 'libvterm.so') try: p = ExpectProcess( lib=lib, rows=rows, cols=cols, cmd=tmux_exe, args=[ # Specify full path to tmux socket (testing tmux instance must # not interfere with user one) '-S', socket_path, # Force 256-color mode '-2', # Request verbose logging just in case '-v', # Specify configuration file '-f', os.path.abspath('powerline/bindings/tmux/powerline.conf'), # Run bash three times 'new-session', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', ], cwd=VTERM_TEST_DIR, env={ # Reasoning: # 1. vt* TERMs (used to be vt100 here) make tmux-1.9 use # different and identical colors for inactive windows. This # is not like tmux-1.6: foreground color is different from # separator color and equal to (0, 102, 153) for some reason # (separator has correct color). tmux-1.8 is fine, so are # older versions (though tmux-1.6 and tmux-1.7 do not have # highlighting for previously active window) and my system # tmux-1.9a. # 2. screen, xterm and some other non-256color terminals both # have the same issue and make libvterm emit complains like # `Unhandled CSI SGR 3231`. # 3. screen-256color, xterm-256color and other -256color # terminals make libvterm emit complains about unhandled # escapes to stderr. # 4. `st-256color` does not have any of the above problems, but # it may be not present on the target system because it is # installed with x11-terms/st and not with sys-libs/ncurses. # # For the given reasons decision was made: to fix tmux-1.9 tests # and not make libvterm emit any data to stderr st-256color # $TERM should be used, up until libvterm has its own terminfo # database entry (if it ever will). To make sure that relevant # terminfo entry is present on the target system it should be # distributed with powerline test package. To make distribution # not require modifying anything outside of powerline test # directory TERMINFO variable is set. 'TERMINFO': os.path.join(VTERM_TEST_DIR, 'terminfo'), 'TERM': 'st-256color', 'PATH': vterm_path, 'SHELL': os.path.join(VTERM_TEST_DIR, 'path', 'bash'), 'POWERLINE_CONFIG_PATHS': os.path.abspath('powerline/config_files'), 'POWERLINE_COMMAND': 'powerline-render', 'POWERLINE_THEME_OVERRIDES': ( 'default.segments.right=[{"type":"string","name":"s1","highlight_groups":["cwd"],"priority":50}];' 'default.segments.left=[{"type":"string","name":"s2","highlight_groups":["background"],"priority":20}];' 'default.segment_data.s1.contents=S1 string here;' 'default.segment_data.s2.contents=S2 string here;' ), 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), 'PYTHONPATH': os.environ.get('PYTHONPATH', ''), }, ) p.start() sleep(5) tmux_version = get_tmux_version(get_fallback_logger()) expected_result = get_expected_result(tmux_version, expected_result_old=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 124), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ), expected_result_new=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 124), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ), expected_result_2_0=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1- '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * 125), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), )) ret = None if not test_expected_result(p, expected_result, cols, rows, not attempts): if attempts: pass # Will rerun main later. else: ret = False elif ret is not False: ret = True cols = 40 p.resize(rows, cols) sleep(5) expected_result = get_expected_result(tmux_version, ( (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' ' * cols), ), expected_result_1_7=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'h '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ') ), expected_result_new=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' <'), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'h '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ') ), expected_result_2_0=( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), '<'), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'ash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2* | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here ') )) if not test_expected_result(p, expected_result, cols, rows, not attempts): if attempts: pass else: ret = False elif ret is not False: ret = True if ret is not None: return ret finally: check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={ 'PATH': vterm_path, 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), }, cwd=VTERM_TEST_DIR) return main(attempts=(attempts - 1))
def main(attempts=3): vterm_path = os.path.join(VTERM_TEST_DIR, 'path') tmux_exe = os.path.join(vterm_path, 'tmux') socket_path = os.path.abspath('tmux-socket-{0}'.format(attempts)) if os.path.exists(socket_path): os.unlink(socket_path) env = get_env(vterm_path, VTERM_TEST_DIR, { 'POWERLINE_THEME_OVERRIDES': ';'.join(( key + '=' + json.dumps(val) for key, val in ( ('default.segments.right', [{ 'type': 'string', 'name': 's1', 'highlight_groups': ['cwd'], 'priority':50, }]), ('default.segments.left', [{ 'type': 'string', 'name': 's2', 'highlight_groups': ['background'], 'priority':20, }]), ('default.segment_data.s1.contents', 'S1 string here'), ('default.segment_data.s2.contents', 'S2 string here'), ) )), 'POWERLINE_TMUX_SOCKET_PATH': socket_path, }) conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf') conf_line = 'source "' + ( conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n' conf_file = os.path.realpath(os.path.join(VTERM_TEST_DIR, 'tmux.conf')) with open(conf_file, 'w') as cf_fd: cf_fd.write(conf_line) tmux_version = get_tmux_version(get_fallback_logger()) dim = MutableDimensions(rows=50, cols=200) def prepare_test_1(p): sleep(5) def prepare_test_2(p): dim.cols = 40 p.resize(dim) sleep(5) base_attrs = { ((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead', ((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep', ((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg', ((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd', ((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep', ((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl', } tests = ( { 'expected_result': get_expected_result( tmux_version, expected_result_old=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{6:bash }' '{bg: }{7: }{8:2* | }{9:bash }{10: }' '{bg:' + (' ' * 124) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 7, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 8, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 9, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 10, })), expected_result_1_8=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' '{bg: }{8: }{9:2* | }{10:bash }{7: }' '{bg:' + (' ' * 124) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, })), expected_result_2_0=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' '{bg: }{8: }{9:2* | }{10:bash }{7: }' '{bg:' + (' ' * 125) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, })), ), 'prep_cb': prepare_test_1, 'row': dim.rows - 1, }, { 'expected_result': get_expected_result( tmux_version, expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs), expected_result_1_7=( '{lead: 0 }' '{leadsep: }{bg: <}{4:h }{bg: }{5: }' '{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((188, 188, 188), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 8, })), expected_result_1_8=( '{lead: 0 }' '{leadsep: }{bg: <}{4:h }{bg: }{5: }' '{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, })), expected_result_2_0=( '{lead: 0 }' '{leadsep: }{bg:<}{4:ash }{bg: }{5: }' '{6:2* | }{7:bash }{4: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, })), ), 'prep_cb': prepare_test_2, 'row': dim.rows - 1, } ) args = [ # Specify full path to tmux socket (testing tmux instance must not # interfere with user one) '-S', socket_path, # Force 256-color mode '-2', # Request verbose logging just in case '-v', # Specify configuration file '-f', conf_file, # Run bash three times 'new-session', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', ] return do_terminal_tests( tests=tests, cmd=tmux_exe, dim=dim, args=args, env=env, cwd=VTERM_TEST_DIR, fin_cb=tmux_fin_cb, last_attempt_cb=print_tmux_logs, )
def main(): VTERM_TEST_DIR = os.path.abspath('tests/vterm') vterm_path = os.path.join(VTERM_TEST_DIR, 'path') socket_path = os.path.join(VTERM_TEST_DIR, 'tmux-socket') rows = 50 cols = 200 tmux_exe = os.path.join(vterm_path, 'tmux') try: p = ExpectProcess( lib='tests/bot-ci/deps/libvterm/libvterm.so', rows=rows, cols=cols, cmd=tmux_exe, args=[ # Specify full path to tmux socket (testing tmux instance must # not interfere with user one) '-S', socket_path, # Force 256-color mode '-2', # Request verbose logging just in case '-v', # Specify configuration file '-f', os.path.abspath('powerline/bindings/tmux/powerline.conf'), # Run bash three times 'new-session', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', ], cwd=VTERM_TEST_DIR, env={ # Reasoning: # 1. vt* TERMs (used to be vt100 here) make tmux-1.9 use # different and identical colors for inactive windows. This # is not like tmux-1.6: foreground color is different from # separator color and equal to (0, 102, 153) for some reason # (separator has correct color). tmux-1.8 is fine, so are # older versions (though tmux-1.6 and tmux-1.7 do not have # highlighting for previously active window) and my system # tmux-1.9a. # 2. screen, xterm and some other non-256color terminals both # have the same issue and make libvterm emit complains like # `Unhandled CSI SGR 3231`. # 3. screen-256color, xterm-256color and other -256color # terminals make libvterm emit complains about unhandled # escapes to stderr. # 4. `st-256color` does not have any of the above problems, but # it may be not present on the target system because it is # installed with x11-terms/st and not with sys-libs/ncurses. # # For the given reasons decision was made: to fix tmux-1.9 tests # and not make libvterm emit any data to stderr st-256color # $TERM should be used, up until libvterm has its own terminfo # database entry (if it ever will). To make sure that relevant # terminfo entry is present on the target system it should be # distributed with powerline test package. To make distribution # not require modifying anything outside of powerline test # directory TERMINFO variable is set. 'TERMINFO': os.path.join(VTERM_TEST_DIR, 'terminfo'), 'TERM': 'st-256color', 'PATH': vterm_path, 'SHELL': os.path.join(''), 'POWERLINE_CONFIG_PATHS': os.path.abspath('powerline/config_files'), 'POWERLINE_COMMAND': 'powerline-render', 'POWERLINE_THEME_OVERRIDES': ( 'default.segments.right=[{"type":"string","name":"s1","highlight_groups":["cwd"]}];' 'default.segments.left=[{"type":"string","name":"s2","highlight_groups":["background"]}];' 'default.segment_data.s1.contents=S1 string here;' 'default.segment_data.s2.contents=S2 string here;' ), 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), 'PYTHONPATH': os.environ.get('PYTHONPATH', ''), }, ) p.start() sleep(2) expected_result_new = ( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ) expected_result_old = ( (((0, 0, 0), (243, 243, 243), 1, 0, 0), ' 0 '), (((243, 243, 243), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' S2 string here '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 0 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((133, 133, 133), (11, 11, 11), 0, 0, 0), ' 1 '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), '| '), (((188, 188, 188), (11, 11, 11), 0, 0, 0), 'bash '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((11, 11, 11), (0, 102, 153), 0, 0, 0), ' '), (((102, 204, 255), (0, 102, 153), 0, 0, 0), '2 | '), (((255, 255, 255), (0, 102, 153), 1, 0, 0), 'bash '), (((0, 102, 153), (11, 11, 11), 0, 0, 0), ' '), (((255, 255, 255), (11, 11, 11), 0, 0, 0), ' '), (((88, 88, 88), (11, 11, 11), 0, 0, 0), ' '), (((199, 199, 199), (88, 88, 88), 0, 0, 0), ' S1 string here '), ) tmux_version = get_tmux_version(get_fallback_logger()) if tmux_version < (1, 8): expected_result = expected_result_old else: expected_result = expected_result_new return test_expected_result(p, expected_result, cols, rows) finally: check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={ 'PATH': vterm_path, 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''), })
def test_uv_file_watcher_is_watching(self): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='uv') except UvNotFound: raise SkipTest('Pyuv is not available') return self.do_test_file_watcher_is_watching(w)
def test_inotify_file_watcher(self, use_bytes=use_bytes): try: w = create_file_watcher(pl=get_fallback_logger(), watcher_type='inotify') except INotifyError: raise SkipTest('This test is not suitable for a stat based file watcher') self.do_test_file_watcher(w, use_bytes)
def main(attempts=3): vterm_path = os.path.join(TEST_ROOT, 'path') tmux_exe = os.path.join(vterm_path, 'tmux') socket_path = os.path.abspath('tmux-socket-{0}'.format(attempts)) if os.path.exists(socket_path): os.unlink(socket_path) env = get_env(vterm_path, TEST_ROOT, { 'POWERLINE_THEME_OVERRIDES': ';'.join(( key + '=' + json.dumps(val) for key, val in ( ('default.segments.right', [{ 'type': 'string', 'name': 's1', 'highlight_groups': ['cwd'], 'priority':50, }]), ('default.segments.left', [{ 'type': 'string', 'name': 's2', 'highlight_groups': ['background'], 'priority':20, }]), ('default.segment_data.s1.contents', 'S1 string here'), ('default.segment_data.s2.contents', 'S2 string here'), ) )), 'POWERLINE_TMUX_SOCKET_PATH': socket_path, }) conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf') conf_line = 'source "' + ( conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n' conf_file = os.path.realpath(os.path.join(TEST_ROOT, 'tmux.conf')) with open(conf_file, 'w') as cf_fd: cf_fd.write(conf_line) tmux_version = get_tmux_version(get_fallback_logger()) dim = MutableDimensions(rows=50, cols=200) def prepare_test_1(p): sleep(5) def prepare_test_2(p): dim.cols = 40 p.resize(dim) sleep(5) base_attrs = { ((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead', ((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep', ((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg', ((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd', ((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep', ((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl', } tests = ( { 'expected_result': get_expected_result( tmux_version, expected_result_old=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{6:bash }' '{bg: }{7: }{8:2* | }{9:bash }{10: }' '{bg:' + (' ' * 124) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 7, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 8, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 9, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 10, })), expected_result_1_8=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' '{bg: }{8: }{9:2* | }{10:bash }{7: }' '{bg:' + (' ' * 124) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, })), expected_result_2_0=( '{lead: 0 }{leadsep: }{bg: S2 string here }' '{4: 0 }{cwdhsep:| }{6:bash }' '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' '{bg: }{8: }{9:2* | }{10:bash }{7: }' '{bg:' + (' ' * 125) + '}' '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, })), ), 'prep_cb': prepare_test_1, 'row': dim.rows - 1, }, { 'expected_result': get_expected_result( tmux_version, expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs), expected_result_1_7=( '{lead: 0 }' '{leadsep: }{bg: <}{4:h }{bg: }{5: }' '{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((188, 188, 188), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, ((0, 102, 153), (11, 11, 11), 0, 0, 0): 8, })), expected_result_1_8=( '{lead: 0 }' '{leadsep: }{bg: <}{4:h }{bg: }{5: }' '{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, })), expected_result_2_0=( '{lead: 0 }' '{leadsep: }{bg:<}{4:ash }{bg: }{5: }' '{6:2* | }{7:bash }{4: }{cwdhsep: }' '{cwd: S1 string here }', updated(base_attrs, { ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, })), ), 'prep_cb': prepare_test_2, 'row': dim.rows - 1, } ) args = [ # Specify full path to tmux socket (testing tmux instance must not # interfere with user one) '-S', socket_path, # Force 256-color mode '-2', # Request verbose logging just in case '-v', # Specify configuration file '-f', conf_file, # Run bash three times 'new-session', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', 'new-window', 'bash --norc --noprofile -i', ';', ] with PowerlineTestSuite('tmux') as suite: return do_terminal_tests( tests=tests, cmd=tmux_exe, dim=dim, args=args, env=env, cwd=TEST_ROOT, fin_cb=tmux_fin_cb, last_attempt_cb=print_tmux_logs, suite=suite, )