Guard main() behind __name__ and add a unittest suite - #17
Merged
Conversation
Importing src/collide.py started a full 15-prompt session, which hung any test that imported the entry point. The bare main() call is now guarded, and characterization tests cover IdeaCollisionGenerator's four methods plus the entry point itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
Self-reviewScored against the diff and against commands actually run on Python 3.8.10 from the repository root. This review was performed by the same session that wrote the change; it is not an independent review. Universal rubric
Repo-specific rubric
Findings folded in from the review
Per the one-intrinsic-critique-pass cap, this rubric will not be re-run absent an external signal. This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
main()insrc/collide.pyis now guarded byif __name__ == "__main__":, so importing the entry point no longer starts a 15-prompt interactive session. Runningpython3 src/collide.pyis unaffected.unittestsuite has been added undertests/:tests/test_ideaCollisionGenerator.py(12 characterization cases acrossgetKeywords(),createPairs(),promptForIdeas(), andwriteToFile()) andtests/test_collide.py(2 cases covering the entry point).keywords[i+1]index — the currentIndexErroris asserted rather than fixed, and the fix is left to the cycle that takes createPairs() raises IndexError when the keyword count is odd #9.builtins.inputis patched in every case that would otherwise read input, andrandom.shuffleis patched wherever pairing order would otherwise be nondeterministic. Anything reachingwriteToFile()runs inside atempfile.TemporaryDirectory, so nothing is written into the repository.## Testssection has been added toREADME.mdrecording the discovery command that works on the declared 3.8 floor.python3 -m unittest discover -s testsis used rather than-s tests -t .; on Python 3.8 the latter fails withImportError: Start directory is not importable, and the alternative — adding atests/__init__.pypurely to satisfy discovery — was judged the larger change.No third-party dependency, packaging layout, or top-level directory other than
tests/has been introduced. No existingcamelCasemember has been renamed, and no prompt string or output-line format has been touched.Test plan
All commands were run from the repository root on Python 3.8.10.
src/collide.pystashed, both entry-point tests fail; with it restored, all 15 pass:The second failure is worth noting on its own: with the guard removed, the import ran one session and
main()ran a second, and both appended into a single file, becausewriteToFile()opens with"a"and both runs landed in the same timestamped second. That is the behavior already filed as #11 and is not changed here.git status --porcelainwas clean of__pycache__, generatedideas/ideas-*.txt, and scratch fixtures before the commit; the fixture and generated files were removed withos.remove.Closes #8
Issues deferred this cycle
Every other open issue was left untouched, with the reason recorded here rather than as comments on each:
.github/workflows/*is a hand-off path that a separate PR should carry.writeToFile()append mode, CWD-relative path, encoding), No input validation: empty keywords accepted, EOF raises an uncaught EOFError, no way to quit #15 (no input validation) — all behavioral changes. A test-expansion cycle must not change production code, so the current behavior of each is characterized here and the fixes are left to their own cycles. The tests added here are the regression net those cycles will need."python"debugger type in.vscode/launch.json) — unrelated to the entry point and testability batch.This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson