-
Notifications
You must be signed in to change notification settings - Fork 3k
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
stop using datumaro.util.test_utils #8259
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9c92e07
stop using datumaro.util.test_utils
Eldies f40a8ca
typing and switching on linters for new files
Eldies 698db28
Merge branch 'refs/heads/develop' into dl/stop-using-test-utils
Eldies 9360841
switching off linters for the new file
Eldies dcba810
adding new file to format_python_code.sh
Eldies 35b34f6
Merge branch 'refs/heads/develop' into dl/stop-using-test-utils
Eldies f1d107c
Merge branch 'refs/heads/develop' into dl/stop-using-test-utils
Eldies 5bc739f
Merge branch 'refs/heads/develop' into dl/stop-using-test-utils
Eldies c2010bd
Merge branch 'refs/heads/develop' into dl/stop-using-test-utils
Eldies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (C) 2024 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
from typing import Optional | ||
|
||
from datumaro import IDataset | ||
from datumaro.components.operations import ExactComparator | ||
from datumaro.util.os_util import rmfile, rmtree | ||
|
||
from cvat.apps.dataset_manager.util import current_function_name | ||
|
||
|
||
class FileRemover: | ||
def __init__(self, path, is_dir=False): | ||
self.path = path | ||
self.is_dir = is_dir | ||
|
||
def __enter__(self): | ||
return self.path | ||
|
||
def __exit__(self, exc_type=None, exc_value=None, traceback=None): | ||
if self.is_dir: | ||
try: | ||
rmtree(self.path) | ||
except unittest.SkipTest: | ||
# Suppress skip test errors from git.util.rmtree | ||
if not exc_type: | ||
raise | ||
else: | ||
rmfile(self.path) | ||
|
||
|
||
class TestDir(FileRemover): | ||
""" | ||
Creates a temporary directory for a test. Uses the name of | ||
the test function to name the directory. | ||
|
||
Usage: | ||
|
||
.. code-block:: | ||
|
||
with TestDir() as test_dir: | ||
... | ||
""" | ||
|
||
def __init__(self, path: Optional[str] = None, frame_id: int = 2): | ||
if not path: | ||
prefix = f"temp_{current_function_name(frame_id)}-" | ||
else: | ||
prefix = None | ||
self._prefix = prefix | ||
|
||
super().__init__(path, is_dir=True) | ||
|
||
def __enter__(self) -> str: | ||
""" | ||
Creates a test directory. | ||
|
||
Returns: path to the directory | ||
""" | ||
|
||
path = self.path | ||
|
||
if path is None: | ||
path = tempfile.mkdtemp(dir=os.getcwd(), prefix=self._prefix) | ||
self.path = path | ||
else: | ||
os.makedirs(path, exist_ok=False) | ||
|
||
return path | ||
|
||
|
||
def compare_datasets(expected: IDataset, actual: IDataset): | ||
zhiltsov-max marked this conversation as resolved.
Show resolved
Hide resolved
|
||
comparator = ExactComparator() | ||
_, unmatched, expected_extra, actual_extra, errors = comparator.compare_datasets( | ||
expected, actual | ||
) | ||
assert not unmatched, f"Datasets have unmatched items: {unmatched}" | ||
assert not actual_extra, f"Actual has following extra items: {actual_extra}" | ||
assert not expected_extra, f"Expected has following extra items: {expected_extra}" | ||
assert not errors, f"There were following errors while comparing datasets: {errors}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add type annotations in the updated code and enable code formatting for the new files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added annotations and enabled black and isort for the new file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: I can not enable black and isort on CI for the new file alone, because the linters are run on folders, not individual files. Disabled them back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still makes sense to add this file into
dev/format_python_code.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it there