test_widgets.py (1230B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import sys 6 from io import StringIO 7 8 import mozunit 9 import pytest 10 11 from mozterm import Terminal 12 from mozterm.widgets import Footer 13 14 15 @pytest.fixture 16 def terminal(): 17 blessed = pytest.importorskip("blessed") 18 19 kind = "xterm-256color" 20 try: 21 term = Terminal(stream=StringIO(), force_styling=True, kind=kind) 22 except blessed.curses.error: 23 pytest.skip(f"terminal '{kind}' not found") 24 25 return term 26 27 28 @pytest.mark.skipif( 29 not sys.platform.startswith("win"), 30 reason="Only do ANSI Escape Sequence comparisons on Windows.", 31 ) 32 def test_footer(terminal): 33 footer = Footer(terminal=terminal) 34 footer.write([ 35 ("bright_black", "foo"), 36 ("green", "bar"), 37 ]) 38 value = terminal.stream.getvalue() 39 expected = "\x1b7\x1b[90mfoo\x1b(B\x1b[m \x1b[32mbar\x1b(B\x1b[m\x1b8" 40 assert value == expected 41 42 footer.clear() 43 value = terminal.stream.getvalue()[len(value) :] 44 expected = "\x1b[1G\x1b[K" 45 assert value == expected 46 47 48 if __name__ == "__main__": 49 mozunit.main()