Debian Codegraph @

python/mozterm/test/test_widgets.py

raw
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 [
36 ("bright_black", "foo"),
37 ("green", "bar"),
38 ]
39 )
40 value = terminal.stream.getvalue()
41 expected = "\x1b7\x1b[90mfoo\x1b(B\x1b[m \x1b[32mbar\x1b(B\x1b[m\x1b8"
42 assert value == expected
43
44 footer.clear()
45 value = terminal.stream.getvalue()[len(value) :]
46 expected = "\x1b[1G\x1b[K"
47 assert value == expected
48
49
50 if __name__ == "__main__":
51 mozunit.main()