Skip to content
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

Minor test cleanup: skipif tests that require optional dependencies, migrate unittest skipif to pytest, minor import/typing clean up #742

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Jan 18, 2025

Copy link

coderabbitai bot commented Jan 18, 2025

Walkthrough

The pull request introduces several modifications across multiple files in the monty library, primarily focusing on import statements, type checking, and test framework updates. The changes include conditional imports using TYPE_CHECKING, migration from unittest to pytest for test decorators, and improved handling of optional dependencies. These modifications aim to optimize type hinting, reduce runtime overhead, and enhance test robustness by gracefully handling missing libraries.

Changes

File Change Summary
src/monty/multiprocessing.py Conditional import of Callable and Iterable under TYPE_CHECKING
src/monty/string.py Removed Iterable from general imports, moved to conditional TYPE_CHECKING block
tests/test_design_patterns.py Updated to use pytest decorators; no functional changes
tests/test_dev.py Added conditional import for ultratb, new test with dependency check
tests/test_functools.py Updated to use pytest decorators for skipping tests
tests/test_json.py Added conditional import for json_util from bson
tests/test_multiprocessing.py Conditional tqdm import and skip logic
tests/test_os.py Moved Path import to TYPE_CHECKING block
tests/test_serialization.py Updated to use pytest decorators for skipping tests
tests/test_shutil.py Updated to use pytest decorators for skipping tests
tests/test_string.py Removed TODO comment and minor variable naming change
tests/test_termcolor.py Removed placeholder comment

Assessment against linked issues

Objective Addressed Explanation
Fix YAML test file collection error [#731] No direct changes addressing the YAML test file collection issue
Handle missing IPython module [#736] Added conditional import and skip logic for ultratb in test_dev.py
Resolve ControlledDict test failure [#736] No changes related to ControlledDict test

Possibly related PRs

Poem

🐰 Imports dance, type hints prance,
Conditional magic, a coding romance!
Pytest leaps, unittest fades,
Dependencies skip, no test parades!
Code evolves with rabbit's grace 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d6165b and 07c92dd.

📒 Files selected for processing (6)
  • src/monty/string.py (1 hunks)
  • tests/test_dev.py (2 hunks)
  • tests/test_functools.py (1 hunks)
  • tests/test_multiprocessing.py (1 hunks)
  • tests/test_serialization.py (1 hunks)
  • tests/test_shutil.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/test_shutil.py
  • tests/test_dev.py
  • tests/test_multiprocessing.py
  • tests/test_serialization.py
  • src/monty/string.py
  • tests/test_functools.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, 3.13)
  • GitHub Check: build (windows-latest, 3.12)
  • GitHub Check: build (windows-latest, 3.11)
  • GitHub Check: build (windows-latest, 3.10)
  • GitHub Check: build (windows-latest, 3.9)
  • GitHub Check: build (ubuntu-latest, 3.12)
  • GitHub Check: build (ubuntu-latest, 3.11)
  • GitHub Check: build (ubuntu-latest, 3.10)
  • GitHub Check: build (ubuntu-latest, 3.9)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.75%. Comparing base (35ffd2d) to head (07c92dd).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #742   +/-   ##
=======================================
  Coverage   84.75%   84.75%           
=======================================
  Files          27       27           
  Lines        1653     1653           
  Branches      315      315           
=======================================
  Hits         1401     1401           
  Misses        192      192           
  Partials       60       60           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanielYang59 DanielYang59 force-pushed the fix-some-tests branch 2 times, most recently from 445dfcc to 4d6165b Compare January 18, 2025 10:32
@DanielYang59 DanielYang59 changed the title Fix some tests Minor test cleanup: skip tests that require optional dependencies, migrate unittest skipif to pytest, minor import/typing clean up Jan 18, 2025
@DanielYang59 DanielYang59 marked this pull request as ready for review January 18, 2025 10:36
Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
tests/test_dev.py (1)

11-14: Fix unused exception variable.

The exception variable exc is assigned but never used.

-except ImportError as exc:
+except ImportError:
🧰 Tools
🪛 Ruff (0.8.2)

13-13: Local variable exc is assigned to but never used

Remove assignment to unused variable exc

(F841)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35ffd2d and 4d6165b.

⛔ Files ignored due to path filters (1)
  • tests/test_files/test_settings.yaml.gz is excluded by !**/*.gz
📒 Files selected for processing (13)
  • src/monty/multiprocessing.py (1 hunks)
  • src/monty/string.py (1 hunks)
  • tests/test_design_patterns.py (1 hunks)
  • tests/test_dev.py (2 hunks)
  • tests/test_functools.py (1 hunks)
  • tests/test_itertools.py (0 hunks)
  • tests/test_json.py (3 hunks)
  • tests/test_multiprocessing.py (1 hunks)
  • tests/test_os.py (1 hunks)
  • tests/test_serialization.py (1 hunks)
  • tests/test_shutil.py (2 hunks)
  • tests/test_string.py (1 hunks)
  • tests/test_termcolor.py (0 hunks)
💤 Files with no reviewable changes (2)
  • tests/test_termcolor.py
  • tests/test_itertools.py
✅ Files skipped from review due to trivial changes (2)
  • tests/test_string.py
  • tests/test_design_patterns.py
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/test_dev.py

13-13: Local variable exc is assigned to but never used

Remove assignment to unused variable exc

(F841)

🔇 Additional comments (11)
tests/test_multiprocessing.py (2)

5-5: LGTM! Clean implementation of optional dependency handling.

The try-except block for tqdm import and the conditional test skip implementation align well with the PR's objective of handling optional dependencies.

Also applies to: 7-12


15-15: LGTM! Proper migration to pytest skip marker.

The migration from unittest to pytest skip marker is correctly implemented, maintaining the same functionality while standardizing the testing approach.

src/monty/multiprocessing.py (1)

8-11: LGTM! Proper implementation of conditional type imports.

Moving type hints under TYPE_CHECKING condition follows best practices and improves runtime performance by avoiding unnecessary imports during execution.

tests/test_serialization.py (1)

68-68: LGTM! Consistent migration to pytest skip marker.

The migration from unittest.skipIf to pytest.mark.skipif maintains the same functionality while aligning with the project's standardization on pytest.

tests/test_os.py (1)

4-4: LGTM! Proper implementation of conditional type imports.

Moving the Path import under TYPE_CHECKING condition follows best practices and is consistent with the type hint optimization pattern applied across the codebase.

Also applies to: 11-12

src/monty/string.py (1)

Line range hint 7-14: LGTM! Good optimization of import statements.

Moving Iterable to the TYPE_CHECKING block is a good practice as it reduces runtime overhead while maintaining type checking capabilities during development.

tests/test_dev.py (1)

207-209: LGTM! Good handling of optional dependency.

The test is properly skipped when IPython is not installed, using the correct pytest marker.

tests/test_shutil.py (1)

191-191: LGTM! Good migration to pytest skip markers.

The migration from unittest.skipIf to pytest.mark.skipif is consistent across all test methods, maintaining the same skip conditions and messages.

Also applies to: 199-199, 205-205, 218-218

tests/test_functools.py (1)

622-622: LGTM! Good migration to pytest skip marker.

The migration from unittest.skipIf to pytest.mark.skipif maintains the same skip condition and message, consistent with changes in other test files.

tests/test_json.py (2)

51-55: LGTM! Clean implementation of optional dependency import.

The import follows the established pattern in the file for handling optional dependencies.


Line range hint 1264-1285: LGTM! Well-structured test for extended JSON serialization.

The test comprehensively covers datetime, NaN, and infinity serialization, with proper type checking and value comparison. Good use of pytest.approx for floating-point comparison of datetime timestamps.

@DanielYang59 DanielYang59 changed the title Minor test cleanup: skip tests that require optional dependencies, migrate unittest skipif to pytest, minor import/typing clean up Minor test cleanup: skipif tests that require optional dependencies, migrate unittest skipif to pytest, minor import/typing clean up Jan 19, 2025
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.

[Bug]: 2 tests fail [Bug]: Tests fail to run: TypeError: Test file has to be YAML list, got <class 'dict'>
1 participant