File: test_logcat.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (45 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (2)
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
import subprocess
from unittest import mock

import pytest


@pytest.mark.parametrize("is_color_enabled", [True, False])
def test_logcat(mock_tools, adb, is_color_enabled, monkeypatch):
    """Invoking `logcat()` calls `Popen()` with the appropriate parameters."""
    # Mock whether color is enabled for the console
    monkeypatch.setattr(
        type(mock_tools.console),
        "is_color_enabled",
        mock.PropertyMock(return_value=is_color_enabled),
    )

    # Mock the result of calling Popen so we can compare against this return value
    popen = mock.MagicMock()
    mock_tools.subprocess.Popen.return_value = popen

    # Invoke logcat
    result = adb.logcat("1234")

    # Validate call parameters.
    mock_tools.subprocess.Popen.assert_called_once_with(
        [
            mock_tools.android_sdk.adb_path,
            "-s",
            "exampleDevice",
            "logcat",
            "--format=tag",
            "--pid",
            "1234",
            "EGL_emulation:S",
        ]
        + (["--format=color"] if is_color_enabled else []),
        env=mock_tools.android_sdk.env,
        encoding="UTF-8",
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        bufsize=1,
    )

    # The Popen object is returned
    assert result == popen