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

Move test utils #52

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Move test utils #52

wants to merge 3 commits into from

Conversation

Eldies
Copy link

@Eldies Eldies commented Jul 30, 2024

Summary

moving most of test_utils.py from datumaro/util to tests/utils (as in upstream)

depends on cvat-ai/cvat#8259

How to test

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2022 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT

Summary by CodeRabbit

  • New Features

    • Enhanced rectangle validation logic to ensure both opposite sides and adjacent sides conform to geometric properties.
    • Added new test case for handling invalid parallelogram shapes in YOLO format.
  • Bug Fixes

    • Improved error reporting for invalid shapes with new test validation.
  • Refactor

    • Reorganized utility imports across multiple test files for better clarity and structure.
    • Streamlined dataset comparison functions and added flexibility for 2D/3D comparisons.
  • Documentation

    • Improved clarity in utility function names and organization to aid developers in understanding functionality.

Copy link

coderabbitai bot commented Jul 30, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates enhance the validation and testing framework within the codebase. Key improvements include stricter geometric checks for rectangle annotations, the removal of redundant dataset comparison functions, and a restructured import system for test utilities. Additionally, new dataset comparison functionalities have been introduced, particularly for handling 3D datasets. These changes aim to improve code maintainability and clarity, ensuring robust testing processes while simplifying the overall structure.

Changes

File Changes Summary
datumaro/plugins/yolo_format/extractor.py, datumaro/util/test_utils.py: Improved validation for rectangle annotations; removed several dataset comparison functions and streamlined imports.
tests/cli/*.py, tests/unit/data_formats/test_yolo_format.py: Adjusted import paths for utility functions to a new module structure for better organization. Added tests for invalid shapes.
tests/utils/test_utils.py: Introduced new dataset comparison functionality, including Dimensions enum and enhanced comparison methods for 2D and 3D datasets.

Poem

🐇 In the code’s lush garden, bright and fair,
Changes bloom, with the softest care.
Rectangles checked, no angles amiss,
Tests now more clear, a programmer’s bliss!
With paths reorganized, like a rabbit’s hop,
We leap through the code, never wanting to stop!
🌼✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@Eldies Eldies mentioned this pull request Jul 30, 2024
7 tasks
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 c7bc106 and e2d40f0.

Files selected for processing (43)
  • datumaro/plugins/yolo_format/extractor.py (1 hunks)
  • datumaro/util/test_utils.py (2 hunks)
  • tests/cli/test_describe_downloads.py (1 hunks)
  • tests/cli/test_detect_format.py (1 hunks)
  • tests/cli/test_diff.py (1 hunks)
  • tests/cli/test_download.py (1 hunks)
  • tests/cli/test_filter.py (1 hunks)
  • tests/cli/test_generator.py (1 hunks)
  • tests/cli/test_image_zip_format.py (1 hunks)
  • tests/cli/test_info.py (1 hunks)
  • tests/cli/test_kitti_raw_format.py (1 hunks)
  • tests/cli/test_merge.py (1 hunks)
  • tests/cli/test_patch.py (1 hunks)
  • tests/cli/test_project.py (1 hunks)
  • tests/cli/test_sly_point_cloud_format.py (1 hunks)
  • tests/cli/test_transform.py (1 hunks)
  • tests/cli/test_utils.py (1 hunks)
  • tests/cli/test_video.py (1 hunks)
  • tests/cli/test_voc_format.py (1 hunks)
  • tests/cli/test_yolo_format.py (7 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_camvid_format.py (1 hunks)
  • tests/test_cityscapes_format.py (1 hunks)
  • tests/test_coco_format.py (1 hunks)
  • tests/test_cvat_format.py (1 hunks)
  • tests/test_dataset.py (1 hunks)
  • tests/test_datumaro_format.py (1 hunks)
  • tests/test_extractor_tfds.py (1 hunks)
  • tests/test_icdar_format.py (1 hunks)
  • tests/test_image_dir_format.py (1 hunks)
  • tests/test_imagenet_format.py (1 hunks)
  • tests/test_kitti_format.py (1 hunks)
  • tests/test_kitti_raw_format.py (1 hunks)
  • tests/test_labelme_format.py (1 hunks)
  • tests/test_mot_format.py (1 hunks)
  • tests/test_mots_format.py (1 hunks)
  • tests/test_project.py (1 hunks)
  • tests/test_sampler.py (1 hunks)
  • tests/test_sly_pointcloud_format.py (1 hunks)
  • tests/test_tfrecord_format.py (1 hunks)
  • tests/test_voc_format.py (1 hunks)
  • tests/unit/data_formats/test_yolo_format.py (2 hunks)
  • tests/utils/test_utils.py (1 hunks)
Files skipped from review due to trivial changes (36)
  • tests/cli/test_describe_downloads.py
  • tests/cli/test_detect_format.py
  • tests/cli/test_diff.py
  • tests/cli/test_download.py
  • tests/cli/test_filter.py
  • tests/cli/test_generator.py
  • tests/cli/test_image_zip_format.py
  • tests/cli/test_info.py
  • tests/cli/test_kitti_raw_format.py
  • tests/cli/test_merge.py
  • tests/cli/test_patch.py
  • tests/cli/test_project.py
  • tests/cli/test_sly_point_cloud_format.py
  • tests/cli/test_transform.py
  • tests/cli/test_utils.py
  • tests/cli/test_video.py
  • tests/cli/test_voc_format.py
  • tests/conftest.py
  • tests/test_camvid_format.py
  • tests/test_cityscapes_format.py
  • tests/test_coco_format.py
  • tests/test_cvat_format.py
  • tests/test_datumaro_format.py
  • tests/test_extractor_tfds.py
  • tests/test_icdar_format.py
  • tests/test_image_dir_format.py
  • tests/test_imagenet_format.py
  • tests/test_kitti_format.py
  • tests/test_kitti_raw_format.py
  • tests/test_labelme_format.py
  • tests/test_mots_format.py
  • tests/test_project.py
  • tests/test_sampler.py
  • tests/test_sly_pointcloud_format.py
  • tests/test_tfrecord_format.py
  • tests/test_voc_format.py
Additional comments not posted (22)
datumaro/util/test_utils.py (5)

11-11: LGTM! Imports streamlined.

The removal of unused imports enhances code clarity and reduces potential confusion.


14-15: LGTM! Function implementation is correct.

The function correctly retrieves the name of the current function.


Line range hint 18-33:
LGTM! Class implementation is correct.

The class correctly implements a context manager for removing files or directories.


Line range hint 36-72:
LGTM! Class implementation is correct.

The class correctly implements a context manager for creating a temporary directory for a test.


Line range hint 75-91:
LGTM! Function implementation is correct.

The function correctly compares the categories of two datasets.

tests/cli/test_yolo_format.py (3)

15-16: LGTM! Imports updated correctly.

The inclusion of run_datum from tests/utils/test_utils is appropriate.


19-20: LGTM! Class attributes added correctly.

The addition of ASSET_PATH and FORMAT_NAME improves the flexibility and maintainability of the tests.


224-226: LGTM! New class implemented correctly.

The new class YOLOv8IntegrationScenarios is correctly implemented and improves code reuse.

tests/utils/test_utils.py (8)

4-16: LGTM! Imports updated correctly.

The inclusion of necessary modules and removal of unused ones is appropriate.


27-29: LGTM! New class implemented correctly.

The class Dimensions is correctly implemented to categorize datasets as either 2D or 3D.


32-47: LGTM! Function implemented correctly.

The function compare_datasets_strict is correctly implemented to compare datasets for strong equality.


49-93: LGTM! Function implemented correctly.

The function compare_datasets_3d is correctly implemented to compare 3D datasets, allowing for optional parameters to ignore specific attributes.


96-121: LGTM! Function updated correctly.

The function check_save_and_load is correctly updated to incorporate the new comparison logic.


124-141: LGTM! Function implemented correctly.

The function compare_dirs is correctly implemented to facilitate the comparison of directory structures and file contents.


144-152: LGTM! Function updated correctly.

The function run_datum is correctly adjusted to accommodate the new testing framework.


155-192: LGTM! Function implemented correctly.

The function mock_tfds_data is correctly implemented to mock TensorFlow datasets for testing purposes.

tests/test_mot_format.py (2)

17-17: Import statement updated correctly.

The import statement has been updated to reflect the new location of check_save_and_load, aligning with the PR objective.


15-18: Function usage updated correctly.

The function _test_save_and_load now uses check_save_and_load from the new location, aligning with the updated import statement.

datumaro/plugins/yolo_format/extractor.py (1)

441-444: Enhanced rectangle validation logic.

The additional validation step to check if adjacent sides are orthogonal ensures the robustness of the rectangle validation.

tests/unit/data_formats/test_yolo_format.py (2)

68-68: Import statement updated correctly.

The import statement has been updated to reflect the new location of compare_datasets_strict, aligning with the PR objective.


1165-1175: New test function added correctly.

The new test function test_can_report_invalid_shape_parallelogram ensures that the system correctly identifies and reports errors for invalid shapes, specifically parallelograms.

tests/test_dataset.py (1)

59-60: Verify the new import path for compare_datasets_strict.

Ensure that compare_datasets_strict is correctly located in tests/utils/test_utils.py and that it is used correctly in the test cases.

Verification successful

The import path for compare_datasets_strict is correct and it is used appropriately in tests/test_dataset.py.

  • The function compare_datasets_strict is defined in tests/utils/test_utils.py.
  • The function is imported and used correctly in tests/test_dataset.py.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new import path for `compare_datasets_strict`.

# Test: Check if the function exists in the new path.
rg --type python --files-with-matches --glob 'tests/utils/test_utils.py' 'def compare_datasets_strict'

Length of output: 133


Script:

#!/bin/bash
# Description: Verify the new import path for `compare_datasets_strict`.

# Test: Check if the function exists in the new path.
rg 'def compare_datasets_strict' -g 'tests/utils/test_utils.py'

Length of output: 162


Script:

#!/bin/bash
# Description: Verify the usage of `compare_datasets_strict` in `tests/test_dataset.py`.

# Test: Check where the function is used in the test file.
rg 'compare_datasets_strict' -g 'tests/test_dataset.py'

Length of output: 210

with pytest.raises(AnnotationImportError) as capture:
Dataset.import_from(test_dir, self.IMPORTER.NAME).init_cache()
assert isinstance(capture.value.__cause__, InvalidAnnotationError)
assert "adjacent sides are not orthogonal" in str(capture.value.__cause__)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider checking this by the match parameter in raises().

@Eldies Eldies marked this pull request as draft August 1, 2024 11:51
Copy link

sonarcloud bot commented Aug 5, 2024

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.

2 participants