From 71fe4a7cbec2b6366e1d1b89b890cce13e80e65f Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Thu, 7 Mar 2024 14:56:05 -0800 Subject: [PATCH] feat: unit testing code -- make sure to add Vector3 for mesh position! --- API/oursin/meshes.py | 5 ++--- API/tests/test_schemas.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 API/tests/test_schemas.py diff --git a/API/oursin/meshes.py b/API/oursin/meshes.py index 41749fb7..c2ce6067 100644 --- a/API/oursin/meshes.py +++ b/API/oursin/meshes.py @@ -33,8 +33,7 @@ def __init__(self,position= [0.0,0.0,0.0], scale= [1,1,1], color= '#FFFFFF', mat by default 'default' """ self.create() - - + position = utils.sanitize_vector3(position) self.position = position client.sio.emit('SetPosition', {self.id: position}) @@ -120,7 +119,7 @@ def set_scale(self, scale): if self.in_unity == False: raise Exception("Object does not exist in Unity, call create method first.") - scale = utils.sanitize_vector3(scale) + scale = utils.formatted_vector3(utils.sanitize_vector3(scale)) self.scale = scale client.sio.emit('SetScale', {self.id: scale}) diff --git a/API/tests/test_schemas.py b/API/tests/test_schemas.py new file mode 100644 index 00000000..e1c10b60 --- /dev/null +++ b/API/tests/test_schemas.py @@ -0,0 +1,28 @@ +import oursin as urchin +import pytest +import jsonschema +import json +import requests + +from unittest.mock import patch + +vector3data_url = "https://raw.githubusercontent.com/VirtualBrainLab/vbl-json-schema/pydantic/src/vbl_json_schema/schemas/vector3.json" +response = requests.get(vector3data_url) +vector3data_schema = json.loads(response.text) + +def test_mesh(): + with patch.object(urchin.client.sio, 'emit') as mock_emit: + mesh = urchin.meshes.Mesh() + + mesh.set_scale([1,1,1]) + + call = mock_emit.call_args + + msg = call.args[0] + data = call.args[1] + print(data) + + try: + jsonschema.validate(data, vector3data_schema) + except jsonschema.exceptions.ValidationError as e: + pytest.fail() \ No newline at end of file