File: test_release_console_control.py

package info (click to toggle)
python-briefcase 0.3.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,596 kB
  • sloc: python: 62,519; makefile: 60
file content (70 lines) | stat: -rw-r--r-- 2,489 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from unittest.mock import Mock


def test_console_is_controlled(console):
    """Console control is released and then restored."""

    console.is_console_controlled = True

    with console.release_console_control():
        assert console.is_console_controlled is False

    assert console.is_console_controlled is True


def test_console_is_not_controlled(console):
    """Effective no-op when console is not currently controlled."""
    assert console.is_console_controlled is False

    with console.release_console_control():
        assert console.is_console_controlled is False

    assert console.is_console_controlled is False


def test_wait_bar_is_active(console):
    """An active Wait Bar is stopped."""
    with console.wait_bar("Testing..."):
        # Wrap the Wait Bar stop and start methods
        console._wait_bar.stop = Mock(wraps=console._wait_bar.stop)
        console._wait_bar.start = Mock(wraps=console._wait_bar.start)

        # Wait Bar is active
        assert console._wait_bar.live.is_started is True
        assert console.is_console_controlled is True

        with console.release_console_control():
            # Wait Bar is not active
            console._wait_bar.stop.assert_called_once()
            assert console._wait_bar.live.is_started is False
            assert console.is_console_controlled is False

        # Wait bar is restored and active again
        console._wait_bar.stop.assert_called_once()
        assert console._wait_bar.live.is_started is True
        assert console.is_console_controlled is True


def test_wait_bar_is_not_active(console):
    """An inactive Wait Bar is not effected."""
    # Instantiate the Wait Bar
    with console.wait_bar("Testing..."):
        pass

    # Mock the Wait Bar stop and start methods
    console._wait_bar.stop = Mock(wraps=console._wait_bar.stop)
    console._wait_bar.start = Mock(wraps=console._wait_bar.start)

    assert console._wait_bar.live.is_started is False
    assert console.is_console_controlled is False

    with console.release_console_control():
        # A stop request was not made for the Wait Bar
        console._wait_bar.stop.assert_not_called()
        assert console._wait_bar.live.is_started is False
        assert console.is_console_controlled is False

    # A start request was not made for the Wait Bar
    console._wait_bar.start.assert_not_called()
    assert console._wait_bar.live.is_started is False
    assert console.is_console_controlled is False