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

Regression test for missing frames after exporting a CVAT dataset #8827

Merged
merged 12 commits into from
Dec 19, 2024

Conversation

archibald1418
Copy link
Contributor

@archibald1418 archibald1418 commented Dec 13, 2024

This pull request provides test coverage for changes made in #8662 which helped resolve the issue GH-8483

Motivation and context

  • This addresses lack of frames when exporting a dataset in CVAT format with a non-default frame step (i.e not 1)
  • The PR adds tests for 'Export dataset' feature to avoid regressions in the future releases
  • Also, server REST API tests debug configuration from .vscode/launch.json is patched with extra pytest options for easier debugging

How has this been tested?

The test checks that the exported dataset:

  • contains the same number of frames that were originally present in the source data
  • contains the correct frames given the frame step

This testing mainly focuses on export in CVAT for video format but also confirms the correct behaviour when the format is different (COCO and Datumaro were checked)

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

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.

Summary by CodeRabbit

  • New Features

    • Added a new test for exporting tasks with non-default frame steps, enhancing validation of export functionality.
    • Improved handling of annotations during import/export processes.
  • Bug Fixes

    • Updated test suite to ensure compatibility with new functionality and handle edge cases.
  • Chores

    • Added a comment in the requirements file to indicate a future update for pytest and pytest-timeout.
  • Configuration Updates

    • Enhanced debugging configuration for REST API tests with additional arguments for improved output.

Copy link
Contributor

coderabbitai bot commented Dec 13, 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 changes involve updates to three files: .vscode/launch.json, tests/python/requirements.txt, and tests/python/rest_api/test_tasks.py. The .vscode/launch.json file has been modified to enhance debugging configurations for the REST API tests by adding --verbose and --no-cov arguments. The requirements.txt file now includes a comment about a future update for the pytest and pytest-timeout packages. Lastly, the test suite for the REST API has been expanded with a new test method for validating export functionality and includes updates to existing tests to accommodate new features.

Changes

File Change Summary
.vscode/launch.json Updated server: REST API tests configuration with added arguments --verbose and --no-cov.
tests/python/requirements.txt Added comment: # TODO: update pytest to 7.0.0 and pytest-timeout to 2.3.1 (better debug in vscode).
tests/python/rest_api/test_tasks.py Added method test_export_with_non_default_frame_step for testing export functionality with parameters. Updated existing tests for compatibility with new features.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Debugger
    participant Server
    participant TestSuite

    User->>Debugger: Start Debugging
    Debugger->>Server: Launch REST API tests with `--verbose` and `--no-cov`
    Server->>TestSuite: Run tests
    TestSuite-->>Server: Return test results
    Debugger-->>User: Display results
Loading

🐰 "In the garden of code, we hop with glee,
New tests and tweaks, oh what a spree!
With verbose whispers and tasks in tow,
Our rabbit hearts leap, watch our progress grow!
So here's to the changes, both big and small,
In our coding burrow, we celebrate all!" 🐇


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.

@archibald1418 archibald1418 changed the title Regression test for missing frames after exporting a CVAT dataset #8662 Regression test for missing frames after exporting a CVAT dataset Dec 13, 2024
Copy link
Contributor

@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: 2

🧹 Outside diff range and nitpick comments (1)
tests/python/rest_api/test_tasks.py (1)

1043-1043: Use professional and descriptive label names

The label name "goofy ahh car" may not be appropriate for a professional codebase. Consider using a more descriptive and formal label name to maintain code quality and readability.

Apply this diff to update the label name:

 "labels": [{"name": "goofy ahh car"}]
+"labels": [{"name": "car"}]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c729f18 and 1862551.

📒 Files selected for processing (3)
  • .vscode/launch.json (1 hunks)
  • tests/python/requirements.txt (1 hunks)
  • tests/python/rest_api/test_tasks.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/python/requirements.txt

Comment on lines 1061 to 1069
def get_png_index(zinfo: zipfile.ZipInfo) -> int:
name = PurePosixPath(zinfo.filename)
if name.suffix.lower() != '.png':
return -1
name = os.path.basename(name).removesuffix(name.suffix)
idx = name[name.rfind('_') + 1:]
assert idx.isnumeric()
return int(idx)

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve robustness of get_png_index function to handle filenames without underscores

Currently, the get_png_index function assumes that filenames have an underscore separating the base name and the index. If a filename does not contain an underscore, name.rfind('_') returns -1, and idx becomes the entire name, which may not be numeric, causing an assertion error. To improve robustness, consider handling filenames without underscores and providing appropriate error handling.

Apply this diff to improve the function:

 def get_png_index(zinfo: zipfile.ZipInfo) -> int:
     name = PurePosixPath(zinfo.filename)
     if name.suffix.lower() != '.png':
         return -1
-    name = os.path.basename(name).removesuffix(name.suffix)
-    idx = name[name.rfind('_') + 1:]
-    assert idx.isnumeric()
-    return int(idx)
+    name_stem = name.stem
+    idx_parts = name_stem.split('_')
+    idx = idx_parts[-1] if len(idx_parts) > 1 else ''
+    if idx.isnumeric():
+        return int(idx)
+    else:
+        return -1

This change ensures that filenames without underscores or with non-numeric endings are handled gracefully.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def get_png_index(zinfo: zipfile.ZipInfo) -> int:
name = PurePosixPath(zinfo.filename)
if name.suffix.lower() != '.png':
return -1
name = os.path.basename(name).removesuffix(name.suffix)
idx = name[name.rfind('_') + 1:]
assert idx.isnumeric()
return int(idx)
def get_png_index(zinfo: zipfile.ZipInfo) -> int:
name = PurePosixPath(zinfo.filename)
if name.suffix.lower() != '.png':
return -1
name_stem = name.stem
idx_parts = name_stem.split('_')
idx = idx_parts[-1] if len(idx_parts) > 1 else ''
if idx.isnumeric():
return int(idx)
else:
return -1

@@ -444,6 +444,8 @@
"python": "${command:python.interpreterPath}",
"module": "pytest",
"args": [
"--verbose",
"--no-cov", // vscode debugger might not work otherwise
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove inline comment in JSON to maintain valid syntax

JSON does not support comments, so including an inline comment // vscode debugger might not work otherwise in the args array will cause a syntax error. Please remove the comment to ensure the launch.json remains valid.

Apply this diff to remove the inline comment:

     "args": [
         "--verbose",
-        "--no-cov", // vscode debugger might not work otherwise
+        "--no-cov",
         "tests/python/rest_api/"
     ],

Consider documenting the reason for including --no-cov in an external README or documentation file if necessary.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"--no-cov", // vscode debugger might not work otherwise
"--no-cov",

@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.90%. Comparing base (289ad43) to head (4998837).
Report is 25 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8827      +/-   ##
===========================================
- Coverage    73.93%   73.90%   -0.03%     
===========================================
  Files          409      409              
  Lines        43930    43932       +2     
  Branches      3986     3986              
===========================================
- Hits         32478    32469       -9     
- Misses       11452    11463      +11     
Components Coverage Δ
cvat-ui 78.37% <ø> (+0.03%) ⬆️
cvat-server 70.08% <80.00%> (-0.08%) ⬇️

Co-authored-by: Maxim Zhiltsov <zhiltsov.max35@gmail.com>
@archibald1418 archibald1418 merged commit df230a4 into develop Dec 19, 2024
35 checks passed
@Marishka17
Copy link
Contributor

@archibald1418, could you please next time merge PRs with squash to make the develop branch history more clear?

@archibald1418 archibald1418 deleted the ov/regression_export_cvat_dataset branch December 19, 2024 13:55
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.

4 participants