File: test_main.py

package info (click to toggle)
textual-image 0.8.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,468 kB
  • sloc: python: 1,851; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from importlib import import_module, reload
from unittest import skipIf, skipUnless
from unittest.mock import patch

from tests.data import TEXTUAL_ENABLED


@skipUnless(TEXTUAL_ENABLED, "Textual support disabled")
def test_main() -> None:
    with patch("sys.argv", ["unittest", "rich"]):
        with patch("textual_image.demo.renderable.run") as run_rich:
            with patch("textual_image.demo.widget.run") as run_textual:
                main = import_module("textual_image.__main__")
    assert run_rich.called
    assert not run_textual.called

    with patch("sys.argv", ["unittest", "textual"]):
        with patch("textual_image.demo.renderable.run") as run_rich:
            with patch("textual_image.demo.widget.run") as run_textual:
                reload(main)
    assert not run_rich.called
    assert run_textual.called

    with patch("sys.argv", ["unittest", "textual"]):
        with patch("textual_image.demo.renderable.run") as run_rich:
            with patch("textual_image.demo.widget.run") as run_textual:
                with patch("importlib.util.find_spec", return_value=None):
                    reload(main)
    assert not run_rich.called
    assert not run_textual.called


@skipIf(TEXTUAL_ENABLED, "Textual support enabled")
def test_main_rich_only() -> None:
    with patch("sys.argv", ["unittest", "rich"]):
        with patch("textual_image.demo.renderable.run") as run_rich:
            main = import_module("textual_image.__main__")
    assert run_rich.called

    with patch("sys.argv", ["unittest", "textual"]):
        with patch("textual_image.demo.renderable.run") as run_rich:
            with patch("sys.stderr") as stderr:
                reload(main)
    assert stderr.write.called
    assert not run_rich.called