File: test_processresult_matcher.py

package info (click to toggle)
python-pytest-shell-utilities 1.9.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: python: 2,998; makefile: 18
file content (44 lines) | stat: -rw-r--r-- 1,215 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
# Copyright 2021-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
"""
Test ``pytestshellutils.utils.processes.ProcessResult``.
"""
import pytest

from pytestshellutils.utils.processes import ProcessResult


MARY_HAD_A_LITTLE_LAMB = """\
Mary had a little lamb,
Its fleece was white as snow;
And everywhere that Mary went
The lamb was sure to go.
"""


@pytest.fixture
def process_result() -> ProcessResult:
    return ProcessResult(returncode=0, stdout=MARY_HAD_A_LITTLE_LAMB, stderr=None)


def test_instance_types() -> None:
    ret = ProcessResult(returncode=0, stdout="STDOUT", stderr="STDERR")
    assert isinstance(ret.stdout, str)
    assert isinstance(ret.stderr, str)
    ret = ProcessResult(returncode=0, stdout=None, stderr=None)
    assert ret.stdout is None
    assert ret.stderr is None
    ret = ProcessResult(returncode=0, stdout=1, stderr=2, data=None)
    assert ret.stdout == 1
    assert ret.stderr == 2


def test_matcher_attribute(process_result: ProcessResult) -> None:
    process_result.stdout.matcher.fnmatch_lines_random(
        [
            "*had a little*",
            "Its fleece was white*",
            "*Mary went",
            "The lamb was sure to go.",
        ]
    )