Skip to content

Commit

Permalink
Fix parsing of 'hidden' configuration option
Browse files Browse the repository at this point in the history
As explained in previous commit, we were setting UISection.hidden to
None when no value was present in the configuration file, instead of
keeping the default value from model. Making the parsing logic more
specific resolves the issue.
  • Loading branch information
dlax committed Aug 24, 2023
1 parent 97ea4c8 commit f369b9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions pgactivity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ def from_config_section(cls: Type[_T], section: configparser.SectionProxy) -> _T
unknown_options = set(section) - set(known_options)
if unknown_options:
raise ValueError(f"invalid option(s): {', '.join(sorted(unknown_options))}")
for opt, getter in (("hidden", section.getboolean), ("width", section.getint)):
try:
values[opt] = getter(opt)
except configparser.NoOptionError:
pass
try:
hidden = section.getboolean("hidden")
except configparser.NoOptionError:
pass
else:
if hidden is not None:
values["hidden"] = hidden
try:
values["width"] = section.getint("width")
except configparser.NoOptionError:
pass
return cls(**values)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def asdict(cfg: Configuration) -> Dict[str, Any]:

(tmp_path / "pg_activity.conf").write_text("\n".join(["[client]", "width=5"]))
cfg = Configuration.lookup(user_config_home=tmp_path)
assert cfg is not None and asdict(cfg) == {"client": {"hidden": None, "width": 5}}
assert cfg is not None and asdict(cfg) == {"client": {"hidden": False, "width": 5}}

0 comments on commit f369b9a

Please sign in to comment.