Skip to content

Restructure _utils#41

Merged
kwabenantim merged 4 commits into
developfrom
35-restructure-utils
Jul 5, 2026
Merged

Restructure _utils#41
kwabenantim merged 4 commits into
developfrom
35-restructure-utils

Conversation

@kwabenantim

Copy link
Copy Markdown
Member

Supports #35

kwabenantim and others added 3 commits July 5, 2026 10:38
_utils.py mixed four unrelated concerns. Redistribute its functions to
homes that match what they do, and delete the module:

  search_ast_type                 -> _expressions.py (AST helpers)
  to_cpp_name/to_camel_case/
    generate_header_guard         -> _names.py (C++ identifier naming)
  get_compartment_size/
    get_function_definition_args   -> _sbml_reader.py (renamed from
                                     _sbml_loader.py: SBML loading + readers)

Naming tests move alongside (test_utils.py -> test_names.py). Also drop the
resolved "Add priority" TODO in _format_events and correct the trigger
distance multi-operand comment.

Pure move: reference outputs regenerate unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add direct tests for the pure helpers that previously had only incidental
coverage:

  _expressions: collect_ast_names, substitute_ast_names,
                replace_avogadro_csymbol, strip_ast_units, search_ast_type
  _sbml_reader: load_sbml_model (valid + read-error), get_compartment_size
                (set + default), get_function_definition_arguments

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add assertion-based tests for two logic-heavy ModelBuilder paths that were
previously only verified by the byte-for-byte semantic-case diff:

  _event_trigger_distance: all six relational operators (only < appears in
    the reference models) plus the non-relational constant case
  _compensate_compartment_resizes: direct resize, indirect resize via an
    assignment rule, scaling an existing species assignment, and skipping
    amount-tracked species

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kwabenantim
kwabenantim requested a review from Copilot July 5, 2026 09:40
@kwabenantim kwabenantim linked an issue Jul 5, 2026 that may be closed by this pull request
@kwabenantim kwabenantim added the enhancement New feature or request label Jul 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures internal “utility” functionality into more cohesive modules, splitting SBML-reading helpers, name/identifier utilities, and AST-expression helpers into their respective components. It aligns with the goal in #35 by consolidating identifier-derivation utilities alongside the name-conflict management code.

Changes:

  • Removed chaste_sbml/_utils.py and redistributed functionality into _sbml_reader.py, _names.py, and _expressions.py.
  • Updated imports across the package (including reference-model tooling) to use the new module locations.
  • Reorganized and expanded tests: moved name/header-guard tests into test_names.py, added test_sbml_reader.py, and added more coverage around expression AST utilities and event-related ModelBuilder behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
chaste_sbml/tests/test_utils.py Removed; its coverage is migrated to more specific test modules.
chaste_sbml/tests/test_sbml_reader.py New tests for SBML loading and small SBML-element reader helpers.
chaste_sbml/tests/test_names.py Now also tests generate_header_guard, to_camel_case, and to_cpp_name from _names.
chaste_sbml/tests/test_model_builder.py Adds unit coverage for event-trigger distance formatting and compartment-resize compensation behavior.
chaste_sbml/tests/test_expressions.py Adds tests for new/expanded AST helper functions (name collection/substitution, unit stripping, type search, avogadro handling).
chaste_sbml/SbmlRefModels/generate_cases.py Updates import to generate_header_guard from _names.
chaste_sbml/chaste_sbml_model.py Updates imports and docstring reference from _sbml_loader/_utils to _sbml_reader/_names.
chaste_sbml/_utils.py Deleted; prior mixed responsibilities are moved into focused modules.
chaste_sbml/_sbml_reader.py Now contains SBML file loading plus small “reader” helpers previously in _utils.
chaste_sbml/_names.py Now contains string-to-C++ identifier utilities (camel/cpp/header guard) alongside NameManager logic.
chaste_sbml/_model_builder.py Swaps SBML helper imports to _sbml_reader and updates inline TODO/comments.
chaste_sbml/_expressions.py Inlines search_ast_type (previously from _utils) into the expressions module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread chaste_sbml/_expressions.py Outdated
Correct hints that contradicted the code and annotate value-returning
functions that lacked a return type:

  search_ast_type / collect_ast_names roots -> Optional[ASTNode] (both
    guard against None; noted in review)
  Equation.math -> Optional[ASTNode] (_format_equations guards `if eq.math`)
  load_sbml_model -> Model
  _species_conversion_factor -> Optional[str] (returns an SId, not a float)
  _add_species_initial_value -> Optional[float]
  _event_priority -> Optional[str]
  parse_args -> argparse.Namespace

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kwabenantim
kwabenantim marked this pull request as ready for review July 5, 2026 09:56
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.68421% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.72%. Comparing base (7231498) to head (9076679).

Files with missing lines Patch % Lines
chaste_sbml/__main__.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #41      +/-   ##
===========================================
+ Coverage    91.93%   92.72%   +0.78%     
===========================================
  Files           55       54       -1     
  Lines         6364     6361       -3     
===========================================
+ Hits          5851     5898      +47     
+ Misses         513      463      -50     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kwabenantim
kwabenantim merged commit 92113fe into develop Jul 5, 2026
15 checks passed
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.

Resolve variable name conflicts

2 participants