conf: fix undefined variable and improve test coverage

This commit is contained in:
Fabio Valentini 2023-03-03 00:31:54 +01:00
parent a0e869199f
commit bd09ff4106
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
4 changed files with 20 additions and 5 deletions

View file

@ -38,15 +38,15 @@ class Rust2RpmConf:
conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) conf = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
confs = conf.read(filenames) confs = conf.read(filenames)
if len(confs) > 1: if len(confs) > 1: # pragma nocover
raise FileExistsError raise FileExistsError
# clean up configuration files with deprecated names # clean up configuration files with deprecated names
if ".rust2rpm.conf" in confs: if ".rust2rpm.conf" in confs: # pragma nocover
os.rename(".rust2rpm.conf", "rust2rpm.conf") os.rename(".rust2rpm.conf", "rust2rpm.conf")
log.info("Renamed deprecated, hidden .rust2rpm.conf file to rust2rpm.conf.") log.info("Renamed deprecated, hidden .rust2rpm.conf file to rust2rpm.conf.")
if "_rust2rpm.conf" in confs: if "_rust2rpm.conf" in confs: # pragma nocover
os.rename("_rust2rpm.conf", "rust2rpm.conf") os.rename("_rust2rpm.conf", "rust2rpm.conf")
log.info("Renamed deprecated _rust2rpm.conf file to rust2rpm.conf.") log.info("Renamed deprecated _rust2rpm.conf file to rust2rpm.conf.")
@ -81,7 +81,8 @@ class Rust2RpmConf:
# parse configuration and validate settings # parse configuration and validate settings
settings = dict() settings = dict()
if all_features := merged.getboolean("all-features") and all_features is not None: all_features = merged.getboolean("all-features")
if all_features is not None:
settings["all_features"] = all_features settings["all_features"] = all_features
if unwanted_features := merged.get("unwanted-features"): if unwanted_features := merged.get("unwanted-features"):

View file

@ -39,7 +39,7 @@ def guess_main_package(metadata: Metadata, hint: Optional[str] = None, interacti
if len(with_bin) == 1: if len(with_bin) == 1:
return with_bin[0] return with_bin[0]
if interactive: if interactive: # pragma nocover
choices = [package.name for package in with_bin] + [package.name for package in with_cdylib] choices = [package.name for package in with_bin] + [package.name for package in with_cdylib]
log.warn( log.warn(
'Heuristic for determining the "main" crate of the workspace failed. ' 'Heuristic for determining the "main" crate of the workspace failed. '

View file

@ -0,0 +1,4 @@
[DEFAULT]
all-features = true
unwanted-features =
__doctest

View file

@ -9,6 +9,16 @@ from rust2rpm.conf import Rust2RpmConf
@pytest.mark.parametrize( @pytest.mark.parametrize(
"filename,features,all_features,unwanted_features,buildrequires,testrequires,bin_requires,lib_requires", "filename,features,all_features,unwanted_features,buildrequires,testrequires,bin_requires,lib_requires",
[ [
(
"chrono-0.4.23.rust2rpm.conf",
{"__doctest"},
True,
["__doctest"],
list(),
list(),
list(),
dict(),
),
( (
"libsqlite3-sys-0.25.2.rust2rpm.conf", "libsqlite3-sys-0.25.2.rust2rpm.conf",
{"sqlcipher"}, {"sqlcipher"},