Skip to content

fix CI#2

Merged
yibeichan merged 3 commits intoReproNim:mainfrom
yibeichan:main
Dec 2, 2025
Merged

fix CI#2
yibeichan merged 3 commits intoReproNim:mainfrom
yibeichan:main

Conversation

@yibeichan
Copy link
Collaborator

This pull request updates the test setup in tests/test_run.py to improve compatibility with Python 3.12+ and strengthen the mocking of external dependencies. The main focus is handling the deprecation of pkg_resources and ensuring that bids.BIDSLayout is properly mocked for test reliability.

Python compatibility and dependency mocking:

  • Added a try/except block to handle the import of pkg_resources, providing a mock implementation when the module is not available, which is necessary for Python 3.12+ compatibility.
  • Introduced a mock for the bids module and its BIDSLayout class, and registered both bids and pkg_resources mocks in sys.modules to ensure that downstream imports use the mocked versions.

yibeichan and others added 3 commits December 2, 2025 13:35
- Mock sys.modules['bids'] before importing src.run to prevent ModuleNotFoundError in CI
- Remove problematic patch context manager that tried to import non-existent bids module
- Tests now work in environments without pybids installed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Handle ModuleNotFoundError when pkg_resources is not available (Python 3.12+)
- Create mock pkg_resources when import fails
- Add pkg_resources to sys.modules for proper test patching
- Tests now work across Python 3.9-3.12+

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @yibeichan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses continuous integration failures by enhancing the test setup in "tests/test_run.py" to improve compatibility with Python 3.12+ and strengthen the mocking of external dependencies. The changes specifically handle the deprecation of "pkg_resources" and ensure that the "bids.BIDSLayout" class is reliably mocked, leading to more robust and future-proof tests.

Highlights

  • Python 3.12+ Compatibility: Implemented a "try-except" block for "pkg_resources" import in "tests/test_run.py" to gracefully handle its deprecation and "ModuleNotFoundError" in newer Python versions, providing a "MagicMock" fallback.
  • Enhanced BIDS Module Mocking: Introduced a global mock for the "bids" module and its "BIDSLayout" class by registering "mock_bids" in "sys.modules", ensuring consistent and reliable testing of "bids" interactions.
  • Refactored Test Setup: The import of "src.run" modules within "tests/test_run.py" was moved to occur after all necessary modules ("bids", "pkg_resources") have been mocked in "sys.modules", ensuring tests run with the intended mock objects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the CI failures on Python 3.12+ by handling the deprecation of pkg_resources and improving the mocking strategy for external dependencies in the tests. The changes are well-focused on the test setup and appear correct.

My review includes a couple of suggestions for improving maintainability. One comment points out some redundancy created by the new mocking strategy that could be cleaned up. Another suggests a more readable way to create a mock exception class.

As a future improvement, you might consider migrating src/run.py to use importlib.metadata (available since Python 3.8) instead of pkg_resources. This would remove the dependency on the deprecated library from the application code itself, providing a more permanent solution.

except ModuleNotFoundError:
# Create a mock pkg_resources for testing purposes
pkg_resources = MagicMock()
pkg_resources.DistributionNotFound = type('DistributionNotFound', (Exception,), {})

Choose a reason for hiding this comment

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

medium

Using type() to dynamically create an exception class is a bit unconventional and can harm readability. For better clarity and maintainability, it's preferable to use a standard class definition. This makes the intent clearer to developers who might work on this code in the future.

For example:

class DistributionNotFound(Exception):
    pass

pkg_resources.DistributionNotFound = DistributionNotFound

Comment on lines +77 to +86
# Mock bids module
mock_bids = MagicMock()
mock_bids.BIDSLayout = MagicMock(return_value=mock_layout)

# Configure the mocks
sys.modules['ants'] = mock_ants
sys.modules['numpy'] = np
sys.modules['nibabel'] = MagicMock()
sys.modules['bids'] = mock_bids
sys.modules['pkg_resources'] = pkg_resources

Choose a reason for hiding this comment

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

medium

This change introduces a more robust way of mocking bids and pkg_resources by manipulating sys.modules, which is a good improvement. However, this new global mock for bids.BIDSLayout makes the local patch('bids.BIDSLayout') calls within test_process_participant (line 278) and test_process_session (line 390) redundant. To improve code clarity and reduce complexity, you should remove those now-unnecessary patches.

@yibeichan yibeichan merged commit 3ce5e00 into ReproNim:main Dec 2, 2025
4 checks passed
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.

1 participant