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

fix TestClass name, make module level variable all capital and other code cleanup #702

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

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Jul 26, 2024

Summary

  • Rename TestClass to ClassForTest to avoid PytestCollectionWarning
  /Users/yang/developer/monty/tests/test_design_patterns.py:55: 
PytestCollectionWarning: cannot collect test class 'TestClass' because 
it has a __init__ constructor (from: developer/monty/tests/test_design_patterns.py
  • Other clean up in tests

Tag added for future PR:

Summary by CodeRabbit

  • Tests
    • Enhanced test cases for serialization and deserialization processes, ensuring robust validation.
    • Updated assertions in test_pint_quantity and test_jsanitize to cover additional scenarios.
    • Renamed directory reference from test_dir to TEST_DIR in file operations for consistency.
    • Improved error reporting in test_command with detailed debug messages for failed assertions.
  • Chores
    • Adjusted pre-commit configuration to update exclusion patterns for file processing.

Copy link

coderabbitai bot commented Jul 26, 2024

Walkthrough

The recent changes involve modifications to the tests/test_json.py file, focusing on enhancing test cases for serialization and deserialization of various classes and data types. Key updates include the addition of assertions in the test_pint_quantity method to verify output types and expanded test scenarios for the jsanitize method, ensuring comprehensive coverage of edge cases. Additionally, the .pre-commit-config.yaml file has been updated to change the exclusion pattern for certain directories, affecting which files are processed by pre-commit hooks. The overall structure of the test classes remains unchanged.

Changes

Files Change Summary
tests/test_json.py Updated test_pint_quantity and test_jsanitize methods to include additional assertions for output types and various scenarios.
.pre-commit-config.yaml Updated exclusion pattern from `^(docs
tests/test_shutil.py Renamed variable test_dir to TEST_DIR for consistency across test methods.
tests/test_subprocess.py Enhanced error reporting in test_command function with a detailed debug message for assertion failures.

Poem

🐇 In the land of tests, we dance and play,
With assertions anew, we brighten the day!
Pint quantities checked, jsanitize too,
Our code's now more sturdy, thanks to the crew!
Hoppity hop, let the tests now run free,
For each little change brings joy, can't you see? 🌟


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 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.

@DanielYang59 DanielYang59 changed the title Fix inconsistent ruff bebavior in CI and pre-commit Fix inconsistent pre-commit behaviour locally and from bot Jul 26, 2024
@DanielYang59 DanielYang59 changed the title Fix inconsistent pre-commit behaviour locally and from bot Fix inconsistent pre-commit behaviour locally and in CI Jul 26, 2024
@@ -8,8 +8,8 @@ def test_command():
sleep05 = Command("sleep 0.5")

sleep05.run(timeout=1)
print(sleep05)
assert sleep05.retcode == 0
Copy link
Contributor Author

@DanielYang59 DanielYang59 Jul 26, 2024

Choose a reason for hiding this comment

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

This unit test seems to fail intermittently (seemingly in Windows only), I guess that's probably the reason the print exists.

First time failure: https://github.com/materialsvirtuallab/monty/actions/runs/10104741275/job/27944181978

Second time: https://github.com/materialsvirtuallab/monty/actions/runs/10104606892/job/27943837091

But still need to recreate this issue in the first place

Copy link

codecov bot commented Jul 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.80%. Comparing base (1798d59) to head (bfe9431).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #702      +/-   ##
==========================================
+ Coverage   82.57%   82.80%   +0.22%     
==========================================
  Files          27       27              
  Lines        1584     1576       -8     
  Branches      284      284              
==========================================
- Hits         1308     1305       -3     
+ Misses        215      210       -5     
  Partials       61       61              

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

@DanielYang59 DanielYang59 marked this pull request as ready for review July 29, 2024 10:59
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bec8915 and a45b3b4.

Files selected for processing (14)
  • .github/workflows/lint.yml (2 hunks)
  • .pre-commit-config.yaml (3 hunks)
  • pyproject.toml (1 hunks)
  • src/monty/io.py (1 hunks)
  • src/monty/json.py (1 hunks)
  • src/monty/serialization.py (1 hunks)
  • src/monty/subprocess.py (2 hunks)
  • src/monty/termcolor.py (2 hunks)
  • tests/test_design_patterns.py (2 hunks)
  • tests/test_dev.py (3 hunks)
  • tests/test_json.py (5 hunks)
  • tests/test_pprint.py (1 hunks)
  • tests/test_serialization.py (1 hunks)
  • tests/test_subprocess.py (1 hunks)
Files skipped from review due to trivial changes (8)
  • .pre-commit-config.yaml
  • src/monty/io.py
  • src/monty/json.py
  • src/monty/serialization.py
  • src/monty/subprocess.py
  • tests/test_design_patterns.py
  • tests/test_dev.py
  • tests/test_serialization.py
Additional comments not posted (10)
tests/test_subprocess.py (1)

12-13: Enhance debugging with detailed assertion messages.

The updated assertion provides more context in case of failure, which is especially useful for intermittent issues.

.github/workflows/lint.yml (1)

12-12: Upgrade setup-python action to v5.

The upgrade to setup-python@v5 ensures the latest features and improvements are utilized.

tests/test_pprint.py (1)

37-37: Improve test robustness with assertions.

Replacing the print statement with an assertion ensures that the output of draw_tree(root) is validated, enhancing the test's robustness.

pyproject.toml (2)

42-42: Addition of ipython dependency is approved.

The inclusion of ipython enhances the interactive computing capabilities, which can be beneficial for debugging and testing.


43-43: Addition of pydantic dependency is approved.

The inclusion of pydantic enhances data validation and settings management, which is beneficial for testing and development.

src/monty/termcolor.py (2)

160-160: Verify the usage of the flush argument.

The removal of the error handling for TypeError simplifies the function but may lead to unhandled exceptions if the flush argument is passed in unsupported environments.

Verification successful

Verification successful. No issues found.

The flush argument is not used in the codebase, so the removal of the error handling for TypeError in the cprint_map function will not cause any unhandled exceptions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `flush` argument in the codebase.

# Test: Search for the usage of the `cprint_map` function with the `flush` argument.
rg --type python -A 5 $'cprint_map'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the usage of the `flush` argument in the codebase.

# Test: Search for the usage of the `cprint_map` function.
rg -A 5 'cprint_map'

# Test: Search for the usage of the `flush` argument.
rg -A 5 'flush'

Length of output: 1272


131-131: Verify the usage of the flush argument.

The removal of the error handling for TypeError simplifies the function but may lead to unhandled exceptions if the flush argument is passed in unsupported environments.

Verification successful

Verify the usage of the flush argument.

The removal of the error handling for TypeError simplifies the function but may lead to unhandled exceptions if the flush argument is passed in unsupported environments. Currently, the flush argument is not used in the codebase, but it is recommended to verify its usage if introduced in the future.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `flush` argument in the codebase.

# Test: Search for the usage of the `cprint` function with the `flush` argument.
rg --type python -A 5 $'cprint'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the usage of the `flush` argument in the codebase.

# Test: Search for the usage of the `cprint` function with the `flush` argument.
rg -t py -A 5 $'cprint'

Length of output: 4682

tests/test_json.py (3)

11-19: Import reorganization is approved.

The reorganization of import statements improves readability and maintainability.


21-21: Variable renaming is approved.

The renaming of tests_version to TESTS_VERSION enhances consistency in naming conventions across the test suite.


323-323: Adjustment in assertion is approved.

The modification to check that the output is of type dict enhances the robustness of the test.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a45b3b4 and b78e6da.

Files ignored due to path filters (1)
  • tests/test_files/3000_lines_gz.txt.gz is excluded by !**/*.gz
Files selected for processing (2)
  • tests/test_io.py (1 hunks)
  • tests/test_tempfile.py (2 hunks)
Files skipped from review due to trivial changes (2)
  • tests/test_io.py
  • tests/test_tempfile.py

@DanielYang59 DanielYang59 marked this pull request as draft July 29, 2024 11:09
@DanielYang59 DanielYang59 marked this pull request as ready for review July 29, 2024 11:12
@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Jul 29, 2024

@shyuep Please review this, thanks!

Meanwhile I cannot reliably recreate (I even wrote a script to run it 10000 times in my local windows machine, but no failure) the random issue for test_command of test_subprocess https://github.com/materialsvirtuallab/monty/pull/702/files#r1692442685, so I decide to leave it for now (with an enriched error message so that we could hopefully find out the reason for failure should it happen next time).

@DanielYang59
Copy link
Contributor Author

@shyuep Can you please review this? Thanks!

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

Outside diff range, codebase verification and nitpick comments (1)
pyproject.toml (1)

42-43: Re-evaluate the inclusion of ipython in CI dependencies

The usage of pydantic in both test and source files justifies its inclusion in the CI dependencies. However, ipython does not appear to be actively used in the codebase, suggesting it may not be necessary. Consider whether ipython is required for interactive testing or other purposes not evident in the current codebase.

  • pydantic: Used in tests/test_json.py and src/monty/json.py
  • ipython: Only mentioned in a comment in src/monty/collections.py
Analysis chain

Addition of ipython and pydantic to CI dependencies is approved.

The inclusion of ipython and pydantic in the ci dependencies seems justified based on the PR summary, which mentions their necessity for specific tests. Ensure these dependencies are indeed required and do not introduce conflicts with existing packages.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the necessity of `ipython` and `pydantic` in the CI environment.

# Test: Search for the usage of `ipython` and `pydantic` in the codebase. Expect: Usage in test files or CI scripts.
rg --type py 'ipython|pydantic'

Length of output: 1713

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b78e6da and fa96b7d.

Files selected for processing (1)
  • pyproject.toml (1 hunks)

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fa96b7d and 0fcc9ca.

Files selected for processing (13)
  • .pre-commit-config.yaml (3 hunks)
  • tasks.py (1 hunks)
  • tests/test_collections.py (1 hunks)
  • tests/test_design_patterns.py (3 hunks)
  • tests/test_dev.py (4 hunks)
  • tests/test_fractions.py (1 hunks)
  • tests/test_functools.py (1 hunks)
  • tests/test_io.py (1 hunks)
  • tests/test_json.py (5 hunks)
  • tests/test_os.py (1 hunks)
  • tests/test_serialization.py (1 hunks)
  • tests/test_shutil.py (1 hunks)
  • tests/test_tempfile.py (1 hunks)
Files skipped from review due to trivial changes (11)
  • tasks.py
  • tests/test_collections.py
  • tests/test_design_patterns.py
  • tests/test_dev.py
  • tests/test_fractions.py
  • tests/test_functools.py
  • tests/test_io.py
  • tests/test_os.py
  • tests/test_serialization.py
  • tests/test_shutil.py
  • tests/test_tempfile.py
Additional comments not posted (7)
.pre-commit-config.yaml (3)

11-11: Version update approved for ruff-pre-commit.

The version update to v0.6.1 is approved. Ensure compatibility with your project's requirements.


27-27: Version update approved for mirrors-mypy.

The version update to v1.11.1 is approved. Ensure compatibility with your project's requirements.


1-1: Verify the new exclusion pattern.

The exclusion pattern has been updated. Ensure that the directory structure for test files has been modified accordingly.

Run the following script to verify the existence of the tests/test_files directory:

Verification successful

Verification successful: Updated exclusion pattern is valid.

The tests/test_files directory exists, confirming that the exclusion pattern update in .pre-commit-config.yaml aligns with the current directory structure. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the `tests/test_files` directory.

# Test: Check if the directory exists. Expect: Directory should exist.
fd --type d --exact-depth 1 --glob 'tests/test_files'

Length of output: 423


Script:

#!/bin/bash
# Description: Verify the existence of the `tests/test_files` directory using the correct `fd` command.

# Test: Check if the directory exists. Expect: Directory should exist.
fd --type d --full-path 'tests/test_files'

Length of output: 60

tests/test_json.py (4)

11-12: Import reorganization approved.

The pytest import has been moved to a more logical position, improving code organization.


22-22: Variable renaming approved.

Renaming tests_version to TESTS_VERSION enhances readability and maintains consistency.


686-686: Assertion modification approved.

Replacing a print statement with an assertion enhances test validation.


877-877: Skip condition modification approved.

The change to "numpy or bson not present" ensures tests are skipped if either dependency is missing.

@DanielYang59
Copy link
Contributor Author

@shyuep Can you review this please?

DanielYang59 added a commit to DanielYang59/monty that referenced this pull request Oct 20, 2024
DanielYang59 added a commit to DanielYang59/monty that referenced this pull request Oct 20, 2024
@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Oct 20, 2024

mark this as draft, dependencies tweaking should migrate to #714

@DanielYang59 DanielYang59 marked this pull request as draft October 20, 2024 06:09
@DanielYang59 DanielYang59 changed the title Fix inconsistent pre-commit behaviour locally and in CI Minor code cleanup Oct 20, 2024
@DanielYang59 DanielYang59 marked this pull request as ready for review October 21, 2024 05:15
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 242f2de and aa8e796.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml (1 hunks)
🧰 Additional context used

.pre-commit-config.yaml Show resolved Hide resolved
@DanielYang59 DanielYang59 changed the title Minor code cleanup fix TestClass name, make module level variable all capital and other code cleanup Oct 23, 2024
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: 1

🧹 Outside diff range and nitpick comments (1)
tests/test_shutil.py (1)

Line range hint 23-219: Consider organizing tests by functionality.

While the current organization is functional, consider grouping related tests more tightly:

  • File operations (copy, remove)
  • Compression operations (gzip, compress)
  • Symlink operations

This would improve maintainability and make it easier to add new tests in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between aa8e796 and bfe9431.

📒 Files selected for processing (2)
  • tests/test_shutil.py (8 hunks)
  • tests/test_subprocess.py (1 hunks)
🔇 Additional comments (9)
tests/test_subprocess.py (1)

11-11: LGTM: Good practice to document known issues.

The comment clearly documents the intermittent Windows CI issue and references PR702 for tracking.

tests/test_shutil.py (8)

23-23: LGTM! Good naming convention update.

The change from test_dir to TEST_DIR follows Python's PEP 8 naming convention for module-level constants.


28-37: LGTM! Consistent path handling.

The path construction using os.path.join with TEST_DIR is correct and platform-independent. The symlink creation is properly guarded for non-Windows systems.


41-52: LGTM! Well-structured test flow.

The test method has a clear progression of operations with appropriate assertions at each step. Path handling is consistent and correct.


57-57: LGTM! Good Path object testing.

Testing with pathlib.Path objects alongside string paths ensures compatibility with both interfaces.


69-69: LGTM! Proper test setup and cleanup.

Path construction is consistent, and the test methods maintain proper test isolation.

Also applies to: 73-73, 96-97


125-126: LGTM! Comprehensive test coverage.

The test cases properly cover various scenarios including coexisting files, subdirectories, and metadata preservation.

Also applies to: 129-129, 132-133, 145-145, 167-167


188-188: LGTM! Proper platform-specific handling.

The test methods are correctly skipped on Windows and include proper cleanup of temporary files.

Also applies to: 196-196


202-202: LGTM! Thorough symlink testing.

The symlink tests properly cover both following and non-following behaviors. Consider verifying symlink behavior across different file systems.

Also applies to: 205-206, 215-215, 218-219

tests/test_subprocess.py Show resolved Hide resolved
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