Coverage for rust2rpm/tests/test_patching.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-26 13:52 +0100
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-26 13:52 +0100
1import os
2from importlib import resources
3from pathlib import Path
4from typing import cast
6import pytest
8from rust2rpm.patching import preprocess_cargo_toml
11@pytest.mark.parametrize(
12 ("filename", "expected"),
13 [
14 (
15 "cxx-build-1.0.71.toml",
16 "cxx-build-1.0.71.toml.patched",
17 ),
18 (
19 "nix-0.24.1.toml",
20 "nix-0.24.1.toml.patched",
21 ),
22 (
23 "tokio-1.19.2.toml",
24 "tokio-1.19.2.toml.patched",
25 ),
26 ],
27)
28def test_drop_foreign_dependencies(filename: str, expected: str):
29 before_path = resources.files("rust2rpm.tests.data.cargo").joinpath(filename)
30 before_path = cast(Path, before_path)
31 after_path = resources.files("rust2rpm.tests.data.cargo").joinpath(expected)
32 after_path = cast(Path, after_path)
34 toml_before = before_path.read_text()
35 patched = preprocess_cargo_toml(toml_before) or toml_before
37 if os.getenv("UPDATE_FIXTURES") == "1": # pragma nocover
38 # helper mode to create / update test fixtures
39 after_path.write_text(patched)
41 toml_after = after_path.read_text()
43 assert patched == toml_after