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.bin_requires: list[str] = bin_requires or list()
self.lib_requires: dict[Optional[str], list[str]] = lib_requires or dict() 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 @staticmethod
def load(filenames: list[str], target: str, features: set[str]): def load(filenames: list[str], target: str, features: set[str]):
conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())

View file

@ -7,83 +7,53 @@ from rust2rpm.conf import Rust2RpmConf
@pytest.mark.parametrize( @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", "askalono-cli-0.4.6.rust2rpm.conf",
{"diagnostics"}, {"diagnostics"},
False, Rust2RpmConf(enabled_features=["diagnostics"]),
list(),
["diagnostics"],
list(),
list(),
list(),
dict(),
), ),
( (
"chrono-0.4.23.rust2rpm.conf", "chrono-0.4.23.rust2rpm.conf",
{"__doctest"}, {"__doctest"},
True, Rust2RpmConf(all_features=True, unwanted_features=["__doctest"]),
["__doctest"],
list(),
list(),
list(),
list(),
dict(),
), ),
( (
"libsqlite3-sys-0.25.2.rust2rpm.conf", "libsqlite3-sys-0.25.2.rust2rpm.conf",
{"sqlcipher"}, {"sqlcipher"},
False, Rust2RpmConf(
list(), buildrequires=["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"],
list(), lib_requires={None: ["pkgconfig(sqlite3) >= 3.7.16"], "sqlcipher": ["pkgconfig(sqlcipher)"]},
["pkgconfig(sqlcipher)", "pkgconfig(sqlite3) >= 3.7.16"], ),
list(),
list(),
{None: ["pkgconfig(sqlite3) >= 3.7.16"], "sqlcipher": ["pkgconfig(sqlcipher)"]},
), ),
( (
"glib-sys-0.17.2.rust2rpm.conf", "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"}, {"v2_58", "v2_60", "v2_62", "v2_64", "v2_66", "v2_68", "v2_70", "v2_72", "v2_74", "v2_76"},
False, Rust2RpmConf(
["v2_76"], unwanted_features=["v2_76"],
list(), buildrequires=["pkgconfig(glib-2.0) >= 2.56"],
["pkgconfig(glib-2.0) >= 2.56"], lib_requires={
list(), None: ["pkgconfig(glib-2.0) >= 2.56"],
list(), "v2_58": ["pkgconfig(glib-2.0) >= 2.58"],
{ "v2_60": ["pkgconfig(glib-2.0) >= 2.60"],
None: ["pkgconfig(glib-2.0) >= 2.56"], "v2_62": ["pkgconfig(glib-2.0) >= 2.62"],
"v2_58": ["pkgconfig(glib-2.0) >= 2.58"], "v2_64": ["pkgconfig(glib-2.0) >= 2.64"],
"v2_60": ["pkgconfig(glib-2.0) >= 2.60"], "v2_66": ["pkgconfig(glib-2.0) >= 2.66"],
"v2_62": ["pkgconfig(glib-2.0) >= 2.62"], "v2_68": ["pkgconfig(glib-2.0) >= 2.68"],
"v2_64": ["pkgconfig(glib-2.0) >= 2.64"], "v2_70": ["pkgconfig(glib-2.0) >= 2.70"],
"v2_66": ["pkgconfig(glib-2.0) >= 2.66"], "v2_72": ["pkgconfig(glib-2.0) >= 2.72"],
"v2_68": ["pkgconfig(glib-2.0) >= 2.68"], "v2_74": ["pkgconfig(glib-2.0) >= 2.74"],
"v2_70": ["pkgconfig(glib-2.0) >= 2.70"], },
"v2_72": ["pkgconfig(glib-2.0) >= 2.72"], ),
"v2_74": ["pkgconfig(glib-2.0) >= 2.74"],
},
), ),
], ],
) )
def test_rust2rpm_conf_load( def test_rust2rpm_conf_load(
filename: str, filename: str,
features: set[str], features: set[str],
all_features: bool, expected: Rust2RpmConf,
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]],
): ):
path = str(resources.files("rust2rpm.tests.samples").joinpath(filename)) path = str(resources.files("rust2rpm.tests.samples").joinpath(filename))
conf = Rust2RpmConf.load(path, "fedora", features) conf = Rust2RpmConf.load(path, "fedora", features)
assert conf == expected
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