forked from voxel51/fiftyone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add server group tests (voxel51#4257)
* add server group tests, lint * fix test * check for slices * use not any * lint docstring * slice is still needed * update tests
- Loading branch information
1 parent
78d4885
commit 35959eb
Showing
3 changed files
with
110 additions
and
33 deletions.
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
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,64 @@ | ||
""" | ||
FiftyOne Server group tests. | ||
| Copyright 2017-2024, Voxel51, Inc. | ||
| `voxel51.com <https://voxel51.com/>`_ | ||
| | ||
""" | ||
|
||
import unittest | ||
|
||
from bson import ObjectId | ||
|
||
import fiftyone as fo | ||
from fiftyone import ViewExpression as F | ||
from fiftyone.server.aggregations import GroupElementFilter | ||
import fiftyone.server.view as fosv | ||
|
||
from decorators import drop_datasets | ||
|
||
|
||
class ServerGroupTests(unittest.TestCase): | ||
@drop_datasets | ||
def test_manual_group_slice(self): | ||
dataset: fo.Dataset = fo.Dataset() | ||
group = fo.Group() | ||
image = fo.Sample( | ||
filepath="image.png", | ||
group=group.element("image"), | ||
label=fo.Classification(label="label"), | ||
) | ||
dataset.add_sample(image) | ||
expr = F("label") == "label" | ||
filtered = dataset.filter_labels("label", F("label") == "label") | ||
|
||
view = fosv.handle_group_filter( | ||
dataset, | ||
filtered, | ||
GroupElementFilter(slice="image", slices=["image"]), | ||
) | ||
self.assertEqual( | ||
view._all_stages, | ||
[ | ||
fo.SelectGroupSlices(_force_mixed=True), | ||
fo.FilterLabels("label", expr), | ||
fo.Match({"group.name": {"$in": ["image"]}}), | ||
], | ||
) | ||
|
||
view = fosv.handle_group_filter( | ||
dataset, | ||
filtered, | ||
GroupElementFilter( | ||
id=image.group.id, slice="image", slices=["image"] | ||
), | ||
) | ||
self.assertEqual( | ||
view._all_stages, | ||
[ | ||
fo.SelectGroupSlices(_force_mixed=True), | ||
fo.Match({"group._id": {"$in": [ObjectId(image.group.id)]}}), | ||
fo.FilterLabels("label", expr), | ||
fo.Match({"group.name": {"$in": ["image"]}}), | ||
], | ||
) |