-
Notifications
You must be signed in to change notification settings - Fork 40
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
[PY-606][external] Added tests for CSV tag uploads #727
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13363e9
Added support for foldre structures when importing CSV tags
JBWilkie 8c70fa4
Merge branch 'master' into py-605
JBWilkie b4c18f6
Merge branch 'py-605' into py-606
JBWilkie d5f7032
Added tests for CSV tags
JBWilkie c504304
Fixed failing test
JBWilkie df5c66a
Merge branch 'master' into py-606
JBWilkie 31abed4
Update csv_tags_video.py
JBWilkie 2d6c772
Fixed compatibility issues with Windows filepaths
JBWilkie 7a30aa5
Merge branch 'py-606' of https://github.com/v7labs/darwin-py into py-606
JBWilkie File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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,52 @@ | ||
import csv | ||
from pathlib import Path | ||
from typing import List, Optional | ||
|
||
import pytest | ||
|
||
from darwin.datatypes import AnnotationFile | ||
from darwin.importer.formats.csv_tags import parse_path | ||
|
||
|
||
class TestParsePath: | ||
@pytest.fixture | ||
def file_path(self, tmp_path: Path): | ||
path = tmp_path / "annotation.csv" | ||
yield path | ||
path.unlink() | ||
|
||
def test_it_returns_none_if_file_extension_is_not_csv(self): | ||
path = Path("path/to/file.xml") | ||
assert parse_path(path) is None | ||
|
||
def test_it_parses_csv_file_correctly(self, file_path: Path): | ||
with file_path.open("w", newline="") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(["image1.jpg", "tag1", "tag2"]) | ||
writer.writerow(["image2.jpg", "tag3", "tag4"]) | ||
|
||
annotation_files: Optional[List[AnnotationFile]] = parse_path(file_path) | ||
assert annotation_files is not None | ||
|
||
assert len(annotation_files) == 2 | ||
assert annotation_files[0].filename == "image1.jpg" | ||
assert len(annotation_files[0].annotations) == 2 | ||
assert annotation_files[1].filename == "image2.jpg" | ||
assert len(annotation_files[1].annotations) == 2 | ||
|
||
def test_folders_paths_are_parsed_correctly(self, file_path: Path): | ||
with file_path.open("w", newline="") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(["folder1/folder2/image1.jpg", "tag1", "tag2"]) | ||
writer.writerow(["folder/image2.jpg", "tag3", "tag4"]) | ||
|
||
annotation_files: Optional[List[AnnotationFile]] = parse_path(file_path) | ||
assert annotation_files is not None | ||
|
||
assert len(annotation_files) == 2 | ||
assert annotation_files[0].filename == "image1.jpg" | ||
assert annotation_files[0].remote_path == "/folder1/folder2" | ||
assert len(annotation_files[0].annotations) == 2 | ||
assert annotation_files[1].filename == "image2.jpg" | ||
assert annotation_files[1].remote_path == "/folder" | ||
assert len(annotation_files[1].annotations) == 2 |
70 changes: 70 additions & 0 deletions
70
tests/darwin/importer/formats/import_csv_tags_video_test.py
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,70 @@ | ||
import csv | ||
from pathlib import Path | ||
from typing import List, Optional | ||
|
||
import pytest | ||
|
||
import darwin.datatypes as dt | ||
from darwin.importer.formats.csv_tags_video import parse_path | ||
|
||
|
||
class TestParsePathVideo: | ||
@pytest.fixture | ||
def file_path(self, tmp_path: Path): | ||
path = tmp_path / "annotation_video.csv" | ||
yield path | ||
path.unlink() | ||
|
||
def test_it_returns_none_if_file_extension_is_not_csv(self): | ||
path = Path("path/to/file.xml") | ||
assert parse_path(path) is None | ||
|
||
def test_it_parses_csv_file_correctly(self, file_path: Path): | ||
with file_path.open("w", newline="") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(["video1.mp4", "tag1", "1", "10"]) | ||
writer.writerow(["video2.mp4", "tag2", "5", "15"]) | ||
|
||
annotation_files: Optional[List[dt.AnnotationFile]] = parse_path(file_path) | ||
assert annotation_files is not None | ||
|
||
assert len(annotation_files) == 2 | ||
assert annotation_files[0].filename == "video1.mp4" | ||
assert len(annotation_files[0].annotations) == 1 | ||
assert annotation_files[1].filename == "video2.mp4" | ||
assert len(annotation_files[1].annotations) == 1 | ||
|
||
def test_folders_paths_are_parsed_correctly(self, file_path: Path): | ||
with file_path.open("w", newline="") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(["folder1/folder2/video1.mp4", "tag1", "1", "10"]) | ||
writer.writerow(["folder/video2.mp4", "tag2", "5", "15"]) | ||
|
||
annotation_files: Optional[List[dt.AnnotationFile]] = parse_path(file_path) | ||
assert annotation_files is not None | ||
|
||
assert len(annotation_files) == 2 | ||
assert annotation_files[0].filename == "video1.mp4" | ||
assert annotation_files[0].remote_path == "/folder1/folder2" | ||
assert len(annotation_files[0].annotations) == 1 | ||
assert annotation_files[1].filename == "video2.mp4" | ||
assert annotation_files[1].remote_path == "/folder" | ||
assert len(annotation_files[1].annotations) == 1 | ||
|
||
def test_keyframes_are_recorded_correctly(self, file_path: Path): | ||
with file_path.open("w", newline="") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(["video1.mp4", "tag1", "1", "10"]) | ||
|
||
annotation_files: Optional[List[dt.AnnotationFile]] = parse_path(file_path) | ||
assert annotation_files is not None | ||
|
||
assert len(annotation_files) == 1 | ||
assert annotation_files[0].filename == "video1.mp4" | ||
assert len(annotation_files[0].annotations) == 1 | ||
|
||
video_annotation = annotation_files[0].annotations[0] | ||
assert isinstance(video_annotation, dt.VideoAnnotation) | ||
|
||
# Check that the keyframes are recorded correctly | ||
assert video_annotation.keyframes == {i: i == 1 for i in range(1, 11)} |
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.
this logic will break on windows because they treat paths with forward slashes will it not? Shouldn't something like pathlib be used