File: test_extension.py

package info (click to toggle)
python-setuptools-rust 1.9.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 648 kB
  • sloc: python: 1,703; javascript: 95; sh: 14; makefile: 13
file content (59 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path

import pytest
from pytest import CaptureFixture, MonkeyPatch

from setuptools_rust.extension import RustBin, RustExtension

SETUPTOOLS_RUST_DIR = Path(__file__).parent.parent


@pytest.fixture()
def hello_world_bin() -> RustBin:
    return RustBin(
        "hello-world",
        path=(
            SETUPTOOLS_RUST_DIR / "examples" / "hello-world" / "Cargo.toml"
        ).as_posix(),
    )


@pytest.fixture()
def namespace_package_extension() -> RustExtension:
    return RustExtension(
        "namespace_package.rust",
        path=(
            SETUPTOOLS_RUST_DIR / "examples" / "namespace_package" / "Cargo.toml"
        ).as_posix(),
    )


def test_metadata_contents(hello_world_bin: RustBin) -> None:
    metadata = hello_world_bin.metadata(quiet=False)
    assert "target_directory" in metadata


def test_metadata_cargo_log(
    capfd: CaptureFixture, monkeypatch: MonkeyPatch, hello_world_bin: RustBin
) -> None:
    monkeypatch.setenv("CARGO_LOG", "trace")

    # With quiet unset, no stdout, plenty of logging stderr
    hello_world_bin.metadata(quiet=False)
    captured = capfd.readouterr()
    assert captured.out == ""
    assert "TRACE cargo::util::config" in captured.err

    # With quiet set, nothing will be printed
    hello_world_bin.metadata(quiet=True)
    captured = capfd.readouterr()
    assert captured.out == ""
    assert captured.err == ""


def test_get_lib_name_namespace_package(
    namespace_package_extension: RustExtension,
) -> None:
    assert (
        namespace_package_extension.get_lib_name(quiet=True) == "namespace_package_rust"
    )