-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3dutils - clean + get_scene_asset_paths * update compute_metadata for 3d: SceneMetadata * refactor get_scene_asset_paths to use fos.run to work in batches * get_scene_asset_paths test * SceneMetadata.build_for test * resolve relative asset paths before computing metadata, allowing e.g. "../blah.jpg" * coderabbit: remove unused import * coderabbit: improve warning log * fos.resolve after join for abs paths * resolve->join_resolve * Revert "resolve->join_resolve" This reverts commit 9b34206. * always resolve if we want abs paths * minor PR comments
- Loading branch information
Showing
5 changed files
with
322 additions
and
37 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
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,53 @@ | ||
""" | ||
FiftyOne metadata unit tests. | ||
| Copyright 2017-2024, Voxel51, Inc. | ||
| `voxel51.com <https://voxel51.com/>`_ | ||
| | ||
""" | ||
import json | ||
import os | ||
import tempfile | ||
import unittest | ||
|
||
import fiftyone.core.metadata as fom | ||
import fiftyone.core.threed as fo3d | ||
|
||
|
||
class SceneMetadataTests(unittest.TestCase): | ||
def test_build_for(self): | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
scene_path = os.path.join(temp_dir, "scene.fo3d") | ||
files = [("stl", 123), ("obj", 321), ("jpeg", 5151), ("mtl", 867)] | ||
for file, num_bytes in files: | ||
with open( | ||
os.path.join(temp_dir, f"{file}.{file}"), "wb" | ||
) as of: | ||
of.write(b"A" * num_bytes) | ||
|
||
scene = fo3d.Scene() | ||
scene.background = fo3d.SceneBackground(image="jpeg.jpeg") | ||
scene.add(fo3d.ObjMesh("blah-obj", "obj.obj", "mtl.mtl")) | ||
scene.add(fo3d.StlMesh("blah-stl", "stl.stl")) | ||
|
||
# Add same file again - should not add to size_bytes though, | ||
# even though this is abs and the other was relative | ||
scene.add( | ||
fo3d.ObjMesh("blah-obj2", os.path.join(temp_dir, "obj.obj")) | ||
) | ||
|
||
scene.write(scene_path) | ||
|
||
metadata = fom.SceneMetadata.build_for(scene_path) | ||
|
||
self.assertEqual(metadata.mime_type, "application/octet-stream") | ||
|
||
# Read the scene back again so we'll compare more accurately | ||
expected_size = len( | ||
json.dumps(fo3d.Scene.from_fo3d(scene_path).as_dict()) | ||
) + sum(t[1] for t in files) | ||
self.assertEqual(metadata.size_bytes, expected_size) | ||
self.assertDictEqual( | ||
metadata.asset_counts, | ||
{"obj": 2, "jpeg": 1, "stl": 1, "mtl": 1}, | ||
) |
Oops, something went wrong.