-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for class-generator scripts #2285
Conversation
WalkthroughThe pull request introduces changes across three files: a new test function in Changes
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Report bugs in Issues The following are automatically added:
Available user actions:
Supported /retest check runs
Supported labels
|
/verified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
class_generator/scripts/tools.py (1)
Line range hint
61-71
: Improve error handling in generate_resource.The current error handling silently continues on any exception. Consider logging the error or handling specific exceptions.
def generate_resource(kinds: list[str], yes: bool) -> None: for _kind in kinds: _generate = "y" if yes else click.prompt(f"Do you want to generate {_kind} resource? (y/n) ") if _generate.lower() == "y": try: class_generator(kind=_kind, called_from_cli=False) - except Exception: + except Exception as exc: + click.echo(f"Failed to generate {_kind}: {exc}", err=True) continue
🧹 Nitpick comments (2)
class_generator/scripts/tests/test_scripts.py (1)
4-7
: Add docstring and enhance test coverage.Good use of type hints and safe dictionary access. However, consider these improvements:
- Add a docstring explaining the test's purpose
- Add assertions to verify the structure and content of the values in the dictionary
def test_get_generated_files(): + """ + Test that get_generated_files returns a dictionary with expected keys + and proper file paths for each category. + """ _files: dict[str, dict[str, str]] = get_generated_files() for _key in ("with_end_comment", "without_end_comment", "not_generated"): assert _files.get(_key), f"{_key} is missing in generated files" + # Verify each category contains valid file paths + assert isinstance(_files[_key], dict), f"{_key} value is not a dictionary" + for kind, path in _files[_key].items(): + assert isinstance(kind, str), f"Invalid kind type in {_key}" + assert isinstance(path, str), f"Invalid path type in {_key}" + assert path.endswith(".py"), f"Invalid file extension in {_key}: {path}"class_generator/scripts/tools.py (1)
20-22
: Add type hints for dictionary values.The type hints for the dictionaries are good, but consider being more specific about the value types.
- resources_with_end_comment: dict[str, str] = {} - resources_without_end_comment: dict[str, str] = {} - resources_not_generated: dict[str, str] = {} + ResourceDict = dict[str, str] # Type alias for better readability + resources_with_end_comment: ResourceDict = {} + resources_without_end_comment: ResourceDict = {} + resources_not_generated: ResourceDict = {}
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
class_generator/scripts/tests/test_scripts.py
(1 hunks)class_generator/scripts/tools.py
(6 hunks)tox.toml
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: tox
- GitHub Check: python-module-install
🔇 Additional comments (1)
tox.toml (1)
30-30
: LGTM! Good simplification of test commands.The change to run all tests in the
class_generator/
directory is a good improvement that:
- Reduces maintenance by avoiding explicit file listing
- Automatically includes new test files
- Follows common pytest test discovery practices
Summary by CodeRabbit
Tests
class_generator/
directoryRefactor