Skip to content

Commit

Permalink
feat: unit testing code -- make sure to add Vector3 for mesh position!
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Mar 7, 2024
1 parent 8f981a9 commit 71fe4a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions API/oursin/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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})

Expand Down
28 changes: 28 additions & 0 deletions API/tests/test_schemas.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 71fe4a7

Please sign in to comment.