diff --git a/rust2rpm/conf.py b/rust2rpm/conf.py index b239421..f4672f7 100644 --- a/rust2rpm/conf.py +++ b/rust2rpm/conf.py @@ -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()) diff --git a/rust2rpm/tests/test_conf.py b/rust2rpm/tests/test_conf.py index f932579..b8ef9db 100644 --- a/rust2rpm/tests/test_conf.py +++ b/rust2rpm/tests/test_conf.py @@ -7,83 +7,53 @@ 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(), - { - None: ["pkgconfig(glib-2.0) >= 2.56"], - "v2_58": ["pkgconfig(glib-2.0) >= 2.58"], - "v2_60": ["pkgconfig(glib-2.0) >= 2.60"], - "v2_62": ["pkgconfig(glib-2.0) >= 2.62"], - "v2_64": ["pkgconfig(glib-2.0) >= 2.64"], - "v2_66": ["pkgconfig(glib-2.0) >= 2.66"], - "v2_68": ["pkgconfig(glib-2.0) >= 2.68"], - "v2_70": ["pkgconfig(glib-2.0) >= 2.70"], - "v2_72": ["pkgconfig(glib-2.0) >= 2.72"], - "v2_74": ["pkgconfig(glib-2.0) >= 2.74"], - }, + 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"], + "v2_62": ["pkgconfig(glib-2.0) >= 2.62"], + "v2_64": ["pkgconfig(glib-2.0) >= 2.64"], + "v2_66": ["pkgconfig(glib-2.0) >= 2.66"], + "v2_68": ["pkgconfig(glib-2.0) >= 2.68"], + "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( 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