File: test_compat.py

package info (click to toggle)
streamlink 7.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,428 kB
  • sloc: python: 49,104; sh: 184; makefile: 145
file content (30 lines) | stat: -rw-r--r-- 894 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
import importlib.util
from io import BufferedWriter
from os import devnull
from unittest.mock import Mock, call

import pytest

import streamlink_cli.compat


def test_no_stdout(monkeypatch: pytest.MonkeyPatch):
    monkeypatch.setattr("sys.stdout", None)

    mock_atexit_register = Mock()
    monkeypatch.setattr("atexit.register", mock_atexit_register)

    spec = importlib.util.find_spec("streamlink_cli.compat")
    assert spec
    assert spec.loader

    module = importlib.util.module_from_spec(spec)
    assert module is not streamlink_cli.compat

    spec.loader.exec_module(module)
    assert module.sys.stdout is None
    assert isinstance(module.stdout, BufferedWriter)
    assert module.stdout.name == devnull

    assert mock_atexit_register.call_args_list == [call(module.stdout.close)]
    module.stdout.close()  # close manually, since we've mocked the atexit.register() call