Skip to content

Expand gaussian coverage and fix handler crashes, Windows renames and directory handling - #474

Merged
shyuep merged 2 commits into
masterfrom
test/gaussian-coverage
Oct 20, 2026
Merged

shyuep merged 2 commits into
masterfrom
test/gaussian-coverage

Conversation

@shyuep

@shyuep shyuep commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Expands coverage of the Gaussian handlers and job, and fixes the bugs the new tests exposed. subprocess is mocked.

File Before After
gaussian/handlers.py 79% 100%
gaussian/jobs.py 77% 100%

Tests assert the applied corrections (route/link0 changes, %Mem scaling, geom=(checkpoint,newdefinition), z-matrix switch, int grid keywords for G09/G16), every unfixable branch, WallTimeErrorHandler restart contents, and generate_better_guess.

Fixes (each has a regression test that fails on master, except the Windows one, which the Windows CI jobs cover):

  1. Run log serialization: six unfixable branches returned {"errors": [self.errors]}, a set inside a list, so writing the run log raised TypeError. They now return list(self.errors).
  2. Missing geom / guess keywords: "connectivity" in route_parameters.get("geom") and "read" in route_parameters.get("guess") raised TypeError when the keyword was absent.
  3. Windows: os.rename onto an existing .prev / input file fails on Windows (FileExistsError); now os.replace.
  4. Symmetry check: not nosymmetry or symmetry != "none" was always true, partly because nosymmetry is a bare keyword whose value is None. symmetry=none is now added only if symmetry is not already off.
  5. directory ignored:
    • GaussianJob.run now passes cwd=directory to Popen.
    • The convergence plot is written to directory.
    • The *.chk lookups in missing_mol and generate_better_guess search directory.
    • The walltime restart input refers to the rwf file by name relative to the run directory, instead of a cwd-relative path with OS-specific separators.

Behaviour change: GaussianJob.run now launches Gaussian in directory instead of the cwd. This is identical for the default directory="./".

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.28%. Comparing base (4b6c1e2) to head (8937ad6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
+ Coverage   92.98%   95.28%   +2.29%     
==========================================
  Files          39       39              
  Lines        3720     3730      +10     
==========================================
+ Hits         3459     3554      +95     
+ Misses        261      176      -85     

☔ 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.

@shyuep

shyuep commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Automated PR review generated by Claude (posted from @shyuep's account). Based on code and CI status only, nothing was run. Please sanity-check before acting.

CI: lint and both Ubuntu jobs pass; test (windows-latest, 3.13) fails with 2 tests and windows-latest, 3.11 was cancelled by fail-fast. Both failures are in tests this PR adds, and both point at real Windows bugs in custodian/gaussian/handlers.py.

Good:

  • Broad, parametrised coverage of GaussianErrorHandler (route-keyword helpers, each correction branch, unfixable paths) and of GaussianJob (run/terminate, better-guess chaining) with fixtures in tmp_path.
  • The three strict xfails document real bugs precisely: {"errors": [self.errors]} wraps a set in a list (not JSON-serialisable), and 'connectivity' in route_parameters.get('geom') / 'read' in route_parameters.get('guess') raise TypeError when the keyword is absent.

Substantive:

  1. test_linear_bend_check_restores_prev_input fails on Windows with FileExistsError at GaussianErrorHandler.check (handlers.py:474): os.rename(<input>.prev, <input>) cannot overwrite an existing file on Windows. The library fix is os.replace; I would fix that here rather than skip the test.
  2. test_walltime_restart_input fails on Windows: WallTimeErrorHandler.correct writes %rwf={rwf} where rwf comes from glob(os.path.join(directory, ...)), giving .\Gau-mock.rwf. Gaussian on Windows accepts either separator, so either normalise in the handler (Path(rwf).as_posix() or just the basename, since the input is in directory) or compare with Path in the test. The handler-side fix is cleaner because the restart input should not depend on the OS that wrote it.

Nits:

  • The three xfails could be converted to fixes in a follow-up; each is a one-line change (list(self.errors), route_parameters.get("geom") or "", route_parameters.get("guess") or "").

Coverage (src/custodian/gaussian):
- handlers.py: 79% -> 100%
- jobs.py: 77% -> 100%

Add pytest-style tests asserting the actual route/link0/input-parameter
corrections, the unfixable branches of every error type, _add_int grid
handling, memory parsing, WallTimeErrorHandler restart input, and
GaussianJob run/terminate (mocked Popen) and the second better-guess job.

Three strict xfails document handler bugs: unfixable branches return
{"errors": [self.errors]} (a set inside a list, not JSON serializable),
and correct() raises TypeError for "coords"/"missing_mol" errors when the
geom/guess route keyword is absent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shyuep
shyuep force-pushed the test/gaussian-coverage branch from 1a9f417 to 413494a Compare October 20, 2026 22:17
- Return list(self.errors) in unfixable branches; [self.errors] wrapped a
  set, which broke JSON serialization of the run log.
- Guard `in` checks on absent geom/guess route keywords (TypeError).
- Use os.replace for .prev swaps; os.rename fails on Windows when the
  target exists.
- internal_coords: only add symmetry=none if nosymmetry/symmetry=none
  is not already set (the old condition was always true).
- Honor `directory`: GaussianJob.run sets cwd, the convergence plot and
  *.chk lookups (handler and generate_better_guess) use the run dir, and
  the walltime restart refers to the rwf file relative to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shyuep shyuep changed the title test: expand coverage for gaussian module Expand gaussian coverage and fix handler crashes, Windows renames and directory handling Oct 20, 2026
@shyuep
shyuep merged commit 0aef827 into master Oct 20, 2026
9 of 10 checks passed
@shyuep
shyuep deleted the test/gaussian-coverage branch October 20, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants