Skip to content

fix(configfile): fix bugs, optimize parser, add support for normal an inline comments and add unit tests#198

Open
gmmcosta15 wants to merge 3 commits intodevfrom
ref/config-file
Open

fix(configfile): fix bugs, optimize parser, add support for normal an inline comments and add unit tests#198
gmmcosta15 wants to merge 3 commits intodevfrom
ref/config-file

Conversation

@gmmcosta15
Copy link
Collaborator

@gmmcosta15 gmmcosta15 commented Mar 13, 2026

Description

  • Feature
  • Bug fix
  • Code refactor
  • Documentation

This pull request intruduces:

  • Fix data-corruption bug in _parse_file: separator normalisation was replacing every : and = in a line instead of just the first one, silently mangling URLs, tokens, and section names with colons
  • Fix get(), getint(), getfloat(), getboolean() default-handling: missing options with no default now raise NoOptionError instead of returning Sentinel.MISSING; get() no longer passes the fallback through the parser
  • Fix add_option(value=None) writing the literal string "None" instead of a value-less option line
  • Convert all logger calls to %-style, add exc_info=True and file path to save_configuration error, add exception chaining (from e) throughout
  • Ignore regular and inline comments in configfile
  • Add 80 unit tests covering all of the above plus thread safety, view sharing, and factory behaviour

Motivation

The configfile module had several subtle parsing bugs and inconsistent behaviors that could corrupt configuration values (e.g., URLs, tokens, or section names) and return incorrect results in some edge cases.

This PR stabilizes the module by fixing multiple correctness issues, tightening error handling, and improving logging. It also refactors parts of the parser to simplify internal tracking and avoid repeated regex compilation.

To prevent regressions and make future changes safer, a comprehensive unit test suite (80 tests) was added, covering parsing behavior, configuration access methods, lifecycle operations, and concurrency aspects.

Tests

tests/util/test_configfile_unit.py: 80 unit tests. Covers parsing, comment handling, deduplication, all read methods, get_section view sharing, add/update/ save lifecycle, get_configparser factory, RLock reentrancy, thread safety, and stale-view-after-reload.

… inline comments and add unit tests

loadWidget: fix bug that would result in a crash
@gmmcosta15 gmmcosta15 requested a review from HugoCLSC March 13, 2026 12:17
@gmmcosta15 gmmcosta15 self-assigned this Mar 13, 2026
@gmmcosta15 gmmcosta15 added the enhancement New feature or request. label Mar 13, 2026
@gmmcosta15 gmmcosta15 marked this pull request as ready for review March 13, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant