Datasets:
Download code/robohome/src/engine/tests/test_candidate_admission_v25.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 4.05 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_candidate_admission_v25.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/engine/tests/test_candidate_admission_v25.py
-
curl -L -o test_candidate_admission_v25.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_candidate_admission_v25.py
4.05 kB
| """Exercise the installed selector with real closed/open GLB source assets.""" | |
| import copy | |
| import hashlib | |
| from pathlib import Path | |
| import sys | |
| import tempfile | |
| import unittest | |
| from unittest.mock import patch | |
| ROOT = Path(__file__).resolve().parents[1] | |
| CODE = ROOT / 'source/scripts/internal/scene_generation/real_assets' | |
| sys.path.insert(0, str(CODE)) | |
| import numpy as np | |
| import trimesh | |
| from asset_collision_qualification import CollisionQualifier | |
| from eligible_candidate_request import select_domain | |
| class Reader: | |
| def consume(self, *args, **kwargs): | |
| return {}, None | |
| class CandidateAdmissionTests(unittest.TestCase): | |
| def setUp(self): | |
| self.folder = tempfile.TemporaryDirectory() | |
| self.addCleanup(self.folder.cleanup) | |
| self.root = Path(self.folder.name) | |
| self.qualifier = CollisionQualifier(self.root / 'cache') | |
| self.entity = {'entity_id': 'master__bed', 'room_id': 'master', 'role': 'bed'} | |
| def candidate(self, key, name, *, open_mesh=False, source_class='bed.n.01'): | |
| mesh = trimesh.creation.box(extents=[1., 2., .5]) | |
| if open_mesh: | |
| mesh.update_faces(np.arange(len(mesh.faces)-1)) | |
| path = self.root / (key + '.glb') | |
| mesh.export(path) | |
| sha = hashlib.sha256(path.read_bytes()).hexdigest() | |
| frame = {'canonical_front_axis': '+Y', 'units': 'm', 'up_axis': 'Z'} | |
| return dict(asset_id=key, pool_candidate_key=key, category='bed', | |
| normalized_category='bed', display_name=name, dimensions_m=[1., 2., .5], | |
| canonical_front_axis='+Y', units='m', up_axis='Z', | |
| source_geometry_probe_key='fixture', probe_implementation_sha256='0'*64, | |
| source_dependency_sha256={str(path): sha}, prepared_source_frame_contract=frame, | |
| provisional_geometry_dimensions=False, canonical_path=str(path), runtime_path=str(path), | |
| asset_sha256=sha, runtime_sha256=sha, canonical_transform=np.eye(4).reshape(-1).tolist(), | |
| source_semantic_evidence={'authored_source': {'source_name': name, | |
| 'wordnet_synset': source_class, 'source_category': 'bed'}}) | |
| def select(self, candidates, declared): | |
| rule = {'entity_id': self.entity['entity_id'], 'candidate_asset_ids': declared} | |
| with patch('eligible_candidate_request.source_semantic_evidence', | |
| side_effect=lambda reader, c: c.get('source_semantic_evidence', {})): | |
| return select_domain(self.entity, rule, {'mode': 'pool'}, | |
| {c['pool_candidate_key']: c for c in candidates}, [self.entity], {}, | |
| Reader(), self.qualifier) | |
| def test_wrong_beds_and_open_collision_asset_fall_back_to_real_closed_adult_bed(self): | |
| candidates = [self.candidate('01-lounger', 'Loris Outdoor Lounger', source_class='chaise_longue.n.01'), | |
| self.candidate('02-toddler', 'Toddler Bed'), | |
| self.candidate('03-open', 'Adult Bed', open_mesh=True), | |
| self.candidate('04-backup', 'Adult Bed')] | |
| before = copy.deepcopy(candidates) | |
| admitted, rejected = self.select(candidates, [c['asset_id'] for c in candidates[:3]]) | |
| self.assertEqual([c['asset_id'] for _, c in admitted], ['04-backup']) | |
| self.assertEqual(candidates, before) | |
| self.assertEqual(len(rejected), 3) | |
| self.assertTrue(any(r['reason'].startswith('collision_representation_unqualified:') for r in rejected)) | |
| self.assertEqual(admitted[0][1]['collision_qualification']['representation'], 'source_meshes') | |
| self.assertEqual(admitted[0][1]['dimensions_m'], [1., 2., .5]) | |
| def test_exhaustion_never_reinserts_a_known_wrong_or_unqualified_bed(self): | |
| candidates = [self.candidate('01-toddler', 'Toddler Bed'), | |
| self.candidate('02-open', 'Adult Bed', open_mesh=True)] | |
| admitted, rejected = self.select(candidates, [c['asset_id'] for c in candidates]) | |
| self.assertEqual(admitted, []) | |
| self.assertEqual(len(rejected), 2) | |
| if __name__ == '__main__': | |
| unittest.main(verbosity=2) | |