🧪 Add logic tests for preserved function definitions by AST#11
Conversation
Adds comprehensive test coverage for `CodeGenerator._has_preserved_definition` in `src/exportify/export_manager/generator.py`, validating its ability to detect regular and async function definitions, as well as regular and annotated assignments. Also fixes `sample_type_aliases.py` to use correct pre-3.12 syntax, passing the type alias detection tests. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds missing unit coverage for CodeGenerator._has_preserved_definition to ensure preserved sections in generated __init__.py are correctly detected via AST parsing, and updates a type-alias fixture to match the intended “pre-3.12” alias style.
Changes:
- Add tests covering
_has_preserved_definitionforFunctionDef,AsyncFunctionDef,Assign,AnnAssign, syntax errors, and empty input. - Update
tests/fixtures/sample_type_aliases.pyto useTypeAliasassignment syntax for “pre-3.12” examples.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/test_generator.py | Adds targeted tests for _has_preserved_definition logic branches. |
| tests/fixtures/sample_type_aliases.py | Fixes the “pre-3.12” type-alias examples to use TypeAlias assignment style. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| test_file_path: FilePath | None = None | ||
|
|
||
| from typing import TypeAlias | ||
|
|
tests/test_generator.py
Outdated
| import pytest | ||
| from exportify.export_manager.generator import CodeGenerator | ||
|
|
|
|
||
| def test_has_preserved_definition_function(generator: CodeGenerator): | ||
| """Test _has_preserved_definition detects a function.""" | ||
| assert generator._has_preserved_definition("def my_func(): pass", "my_func") | ||
| assert not generator._has_preserved_definition("def my_func(): pass", "other_func") | ||
|
|
||
| def test_has_preserved_definition_async_function(generator: CodeGenerator): | ||
| """Test _has_preserved_definition detects an async function.""" | ||
| assert generator._has_preserved_definition("async def my_async_func(): pass", "my_async_func") | ||
|
|
||
| def test_has_preserved_definition_assign(generator: CodeGenerator): | ||
| """Test _has_preserved_definition detects a variable assignment.""" | ||
| assert generator._has_preserved_definition("my_var = 1", "my_var") | ||
| assert generator._has_preserved_definition("my_var = my_other_var = 1", "my_var") | ||
| assert generator._has_preserved_definition("my_var = my_other_var = 1", "my_other_var") | ||
|
|
||
| def test_has_preserved_definition_ann_assign(generator: CodeGenerator): | ||
| """Test _has_preserved_definition detects an annotated assignment.""" | ||
| assert generator._has_preserved_definition("my_var: int = 1", "my_var") | ||
| assert not generator._has_preserved_definition("my_var: int = 1", "other_var") | ||
|
|
||
| def test_has_preserved_definition_syntax_error(generator: CodeGenerator): | ||
| """Test _has_preserved_definition handles syntax errors gracefully.""" | ||
| # Invalid syntax will be suppressed, resulting in False | ||
| assert not generator._has_preserved_definition("def my_func(:: pass", "my_func") | ||
|
|
Add `# ruff: noqa: UP040` to `tests/fixtures/sample_type_aliases.py` to prevent the linter from enforcing the modern `type X = Y` syntax, as this file explicitly tests pre-Python 3.12 type alias parsing backward compatibility. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
Removed unused import of pytest from test_generator.py Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
…320126471 Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
🎯 What: The gap in testing for
_has_preserved_definitioninCodeGeneratorwas addressed. Previously, it lacked test cases to verify thatast.FunctionDef,ast.AsyncFunctionDef,ast.Assign, andast.AnnAssignwere correctly identified within the preserved sections of generated__init__.pycode. Additionally,tests/fixtures/sample_type_aliases.pywas fixed to properly reflect pre-python3.12 syntax.📊 Coverage: Covered all logical branches of
_has_preserved_definition(functions, async functions, assignments, annotated assignments, syntax errors, empty strings).✨ Result: Increased test suite reliability and guaranteed 100% coverage on
exportify/export_manager/generator.pyline 372.PR created automatically by Jules for task 434298203320126471 started by @bashandbone