File: cmdline.py

package info (click to toggle)
python-scrapy 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,308 kB
  • sloc: python: 55,321; xml: 199; makefile: 25; sh: 7
file content (38 lines) | stat: -rw-r--r-- 935 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
from __future__ import annotations

import subprocess
import sys
from typing import Any

import pytest

from scrapy.utils.test import get_testenv


def call(*args: str, **popen_kwargs: Any) -> int:
    args = (sys.executable, "-m", "scrapy.cmdline", *args)
    return subprocess.call(
        args,
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        env=get_testenv(),
        **popen_kwargs,
    )


def proc(*args: str, **popen_kwargs: Any) -> tuple[int, str, str]:
    args = (sys.executable, "-m", "scrapy.cmdline", *args)
    try:
        p = subprocess.run(
            args,
            check=False,
            capture_output=True,
            encoding="utf-8",
            timeout=15,
            env=get_testenv(),
            **popen_kwargs,
        )
    except subprocess.TimeoutExpired:
        pytest.fail("Command took too much time to complete")

    return p.returncode, p.stdout, p.stderr