File: test_warning.py

package info (click to toggle)
python-pipdeptree 2.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: python: 3,286; sh: 28; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 1,140 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
from __future__ import annotations

import pytest

from pipdeptree._warning import WarningPrinter, WarningType


@pytest.mark.parametrize(
    ("warning", "expected_type"),
    [
        ("silence", WarningType.SILENCE),
        ("suppress", WarningType.SUPPRESS),
        ("fail", WarningType.FAIL),
    ],
)
def test_warning_type_from_str_normal(warning: str, expected_type: WarningType) -> None:
    warning_type = WarningType.from_str(warning)
    assert expected_type == warning_type


def test_warning_type_from_str_invalid_warning() -> None:
    with pytest.raises(ValueError, match="Unknown WarningType string value provided"):
        WarningType.from_str("non-existent-warning-type")


def test_warning_printer_print_single_line(capsys: pytest.CaptureFixture[str]) -> None:
    # Use WarningType.FAIL so that we can be able to test to see if WarningPrinter remembers it has warned before.
    warning_printer = WarningPrinter(WarningType.FAIL)
    warning_printer.print_single_line("test")
    assert warning_printer.has_warned_with_failure()
    out, err = capsys.readouterr()
    assert len(out) == 0
    assert err == "test\n"