conf: simplify rust2rpm.conf file parsing tests

This commit is contained in:
Fabio Valentini 2023-03-03 19:02:50 +01:00
parent a4475f92da
commit 851f7468ea
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
2 changed files with 41 additions and 55 deletions

View file

@ -35,6 +35,22 @@ class Rust2RpmConf:
self.bin_requires: list[str] = bin_requires or list()
self.lib_requires: dict[Optional[str], list[str]] = lib_requires or dict()
def __eq__(self, other):
if not isinstance(other, Rust2RpmConf):
return False # pragma nocover
# order of items in the list is consistent:
# lists are sorted when parsing rust2rpm.conf files
return (
self.all_features == other.all_features
and self.unwanted_features == other.unwanted_features
and self.enabled_features == other.enabled_features
and self.buildrequires == other.buildrequires
and self.testrequires == other.testrequires
and self.bin_requires == other.bin_requires
and self.lib_requires == other.lib_requires
)
@staticmethod
def load(filenames: list[str], target: str, features: set[str]):
conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())

View file

@ -7,51 +7,33 @@ from rust2rpm.conf import Rust2RpmConf
@pytest.mark.parametrize(
"filename,features,all_features,unwanted_features,enabled_features,buildrequires,testrequires,bin_requires,lib_requires",
"filename,features,expected",
[
(
"askalono-cli-0.4.6.rust2rpm.conf",
{"diagnostics"},
False,
list(),
["diagnostics"],
list(),
list(),
list(),
dict(),
Rust2RpmConf(enabled_features=["diagnostics"]),
),
(
"chrono-0.4.23.rust2rpm.conf",
{"__doctest"},
True,
["__doctest"],
list(),
list(),
list(),
list(),
dict(),
Rust2RpmConf(all_features=True, unwanted_features=["__doctest"]),
),
(
"libsqlite3-sys-0.25.2.rust2rpm.conf",
{"sqlcipher"},
False,
list(),
list(),
["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"],
list(),
list(),
{None: ["pkgconfig(sqlite3) >= 3.7.16"], "sqlcipher": ["pkgconfig(sqlcipher)"]},
Rust2RpmConf(
buildrequires=["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"],
lib_requires={None: ["pkgconfig(sqlite3) >= 3.7.16"], "sqlcipher": ["pkgconfig(sqlcipher)"]},
),
),
(
"glib-sys-0.17.2.rust2rpm.conf",
{"v2_58", "v2_60", "v2_62", "v2_64", "v2_66", "v2_68", "v2_70", "v2_72", "v2_74", "v2_76"},
False,
["v2_76"],
list(),
["pkgconfig(glib-2.0) >= 2.56"],
list(),
list(),
{
Rust2RpmConf(
unwanted_features=["v2_76"],
buildrequires=["pkgconfig(glib-2.0) >= 2.56"],
lib_requires={
None: ["pkgconfig(glib-2.0) >= 2.56"],
"v2_58": ["pkgconfig(glib-2.0) >= 2.58"],
"v2_60": ["pkgconfig(glib-2.0) >= 2.60"],
@ -64,26 +46,14 @@ from rust2rpm.conf import Rust2RpmConf
"v2_74": ["pkgconfig(glib-2.0) >= 2.74"],
},
),
),
],
)
def test_rust2rpm_conf_load(
filename: str,
features: set[str],
all_features: bool,
unwanted_features: list[str],
enabled_features: list[str],
buildrequires: list[str],
testrequires: list[str],
bin_requires: list[str],
lib_requires: dict[Optional[str], list[str]],
expected: Rust2RpmConf,
):
path = str(resources.files("rust2rpm.tests.samples").joinpath(filename))
conf = Rust2RpmConf.load(path, "fedora", features)
assert conf.all_features == all_features
assert conf.unwanted_features == unwanted_features
assert conf.enabled_features == enabled_features
assert conf.buildrequires == buildrequires
assert conf.testrequires == testrequires
assert conf.bin_requires == bin_requires
assert conf.lib_requires == lib_requires
assert conf == expected