| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
import pytest |
| 4 |
from pytest import CaptureFixture, MonkeyPatch |
| 5 |
|
| 6 |
from setuptools_rust.extension import RustBin, RustExtension |
| 7 |
|
| 8 |
SETUPTOOLS_RUST_DIR = Path(__file__).parent.parent |
| 9 |
|
| 10 |
|
| 11 |
@pytest.fixture() |
| 12 |
def hello_world_bin() -> RustBin: |
| 13 |
return RustBin( |
| 14 |
"hello-world", |
| 15 |
path=( |
| 16 |
SETUPTOOLS_RUST_DIR / "examples" / "hello-world" / "Cargo.toml" |
| 17 |
).as_posix(), |
| 18 |
) |
| 19 |
|
| 20 |
|
| 21 |
@pytest.fixture() |
| 22 |
def namespace_package_extension() -> RustExtension: |
| 23 |
return RustExtension( |
| 24 |
"namespace_package.rust", |
| 25 |
path=( |
| 26 |
SETUPTOOLS_RUST_DIR / "examples" / "namespace_package" / "Cargo.toml" |
| 27 |
).as_posix(), |
| 28 |
) |
| 29 |
|
| 30 |
|
| 31 |
def test_metadata_contents(hello_world_bin: RustBin) -> None: |
| 32 |
metadata = hello_world_bin.metadata(quiet=False) |
| 33 |
assert "target_directory" in metadata |
| 34 |
|
| 35 |
|
| 36 |
def test_metadata_cargo_log( |
| 37 |
capfd: CaptureFixture, monkeypatch: MonkeyPatch, hello_world_bin: RustBin |
| 38 |
) -> None: |
| 39 |
monkeypatch.setenv("CARGO_LOG", "trace") |
| 40 |
|
| 41 |
# With quiet unset, no stdout, plenty of logging stderr |
| 42 |
hello_world_bin.metadata(quiet=False) |
| 43 |
captured = capfd.readouterr() |
| 44 |
assert captured.out == "" |
| 45 |
assert "TRACE" in captured.err |
| 46 |
|
| 47 |
# With quiet set, nothing will be printed |
| 48 |
hello_world_bin.metadata(quiet=True) |
| 49 |
captured = capfd.readouterr() |
| 50 |
assert captured.out == "" |
| 51 |
assert captured.err == "" |
| 52 |
|
| 53 |
|
| 54 |
def test_get_lib_name_namespace_package( |
| 55 |
namespace_package_extension: RustExtension, |
| 56 |
) -> None: |
| 57 |
assert ( |
| 58 |
namespace_package_extension.get_lib_name(quiet=True) == "namespace_package_rust" |
| 59 |
) |