|
import asyncio |
|
import os |
|
|
|
from loguru import logger |
|
|
|
from app import convert_to_obj, embedding_3d_object, parse_3d_file |
|
|
|
|
|
class ModuleTest: |
|
@staticmethod |
|
async def test_process_file(file_path: str, debug_mode: bool = False) -> dict: |
|
report = {} |
|
try: |
|
obj_path = convert_to_obj(file_path) |
|
report["CONV_TO_OBJ"] = "PASSED" |
|
if debug_mode: |
|
logger.info(f"Obj path: {obj_path}") |
|
except Exception: |
|
report["CONV_TO_OBJ"] = "FAILED" |
|
|
|
if report["CONV_TO_OBJ"] == "PASSED": |
|
obj_path = locals().get("obj_path", None) |
|
assert obj_path is not None, "Conversion to OBJ failed" |
|
assert os.path.exists(obj_path), "Converted OBJ file does not exist" |
|
|
|
try: |
|
embeddings = await embedding_3d_object(obj_path) |
|
report["EMBEDDING_3D_OBJ"] = "PASSED" |
|
if debug_mode: |
|
logger.info(f"Description: {embeddings['description']}") |
|
except Exception: |
|
report["EMBEDDING_3D_OBJ"] = "FAILED" |
|
else: |
|
report["EMBEDDING_3D_OBJ"] = "FAILED" |
|
|
|
try: |
|
metadata = parse_3d_file(file_path) |
|
report["PARSE_METADATA"] = "PASSED" |
|
if debug_mode: |
|
logger.info(f"Parsed metadata: {metadata}") |
|
except Exception: |
|
report["PARSE_METADATA"] = "FAILED" |
|
return report |
|
|
|
async def test(self, file_paths: list[str], debug_mode: bool = False) -> None: |
|
for file_path in file_paths: |
|
basename = os.path.basename(file_path) |
|
response = await self.test_process_file( |
|
file_path=file_path, debug_mode=debug_mode |
|
) |
|
for key, value in response.items(): |
|
if value == "FAILED": |
|
logger.error(f"Processed file `{basename}` failed {key}") |
|
else: |
|
logger.info(f"Processed file `{basename}` successfully {key}!") |
|
|
|
|
|
if __name__ == "__main__": |
|
asyncio.run( |
|
ModuleTest().test( |
|
file_paths=[ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
], |
|
debug_mode=True, |
|
) |
|
) |
|
|