Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 92 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import shutil
from pathlib import Path
import pytest
import pymvr
Expand All @@ -32,12 +33,101 @@


@pytest.fixture(scope="function")
def mvr_scene(request):
def mvr_scene(request, tmp_path):
def _create_test_mvr(path: Path):
"""Generate a minimal test.mvr matching existing assertions."""
writer = pymvr.GeneralSceneDescriptionWriter()
addresses = pymvr.Addresses(
addresses=[pymvr.Address(dmx_break=1, address=1, universe=1)]
)
fixture = pymvr.Fixture(
name="LED PAR 64 RGBW",
gdtf_spec="LED PAR 64 RGBW.gdtf",
gdtf_mode="Default",
addresses=addresses,
matrix=pymvr.Matrix(
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [5.0, 5.0, 5.0, 0]]
),
)
layer = pymvr.Layer(
name="Test layer",
child_list=pymvr.ChildList(fixtures=[fixture]),
)
scene = pymvr.Scene(layers=pymvr.Layers([layer]))
writer.serialize_scene(scene)
writer.write_mvr(path)

def _create_test_json_mvr(path: Path):
"""Generate a minimal test_json.mvr matching existing assertions."""
writer = pymvr.GeneralSceneDescriptionWriter()
child_list = pymvr.ChildList()
fixtures = [
{
"gdtf_mode": "Standard mode",
"uuid": "0153f926-8766-442c-bc5f-57b9407c8e35",
"addresses": [
{"dmx_break": 1, "address": 1, "universe": 1},
],
"gdtf_spec": "BlenderDMX@Basic_LED_Bulb@ver2.gdtf",
"fixture_id": 1,
},
{
"gdtf_mode": "Standard mode",
"uuid": "5321f77d-4647-48b6-8798-25ac9292cc2d",
"addresses": [
{"dmx_break": 1, "address": 10, "universe": 1},
],
"gdtf_spec": "BlenderDMX@Basic_LED_Bulb@ver2.gdtf",
"fixture_id": 1,
},
]

for fixture_data in fixtures:
new_addresses = [
pymvr.Address(
dmx_break=address["dmx_break"],
address=address["address"],
universe=address["universe"],
)
for address in fixture_data["addresses"]
]

child_list.fixtures.append(
pymvr.Fixture(
name=fixture_data["gdtf_spec"],
uuid=fixture_data["uuid"],
gdtf_spec=fixture_data["gdtf_spec"],
gdtf_mode=fixture_data["gdtf_mode"],
fixture_id=fixture_data["fixture_id"],
addresses=pymvr.Addresses(addresses=new_addresses),
matrix=pymvr.Matrix(0),
)
)

layer = pymvr.Layer(
name="Layer 1",
uuid="1e4954b5-992c-4146-b71f-5b497834087f",
child_list=child_list,
)
scene = pymvr.Scene(layers=pymvr.Layers([layer]))
writer.serialize_scene(scene)
writer.write_mvr(path)

file_name = request.param[0]
test_mvr_scene_path = Path(
Path(__file__).parents[0], "tests", file_name
) # test file path is made from current directory, tests directory and a file name
mvr_scene = pymvr.GeneralSceneDescription(test_mvr_scene_path)
generated_path = tmp_path / file_name
if test_mvr_scene_path.is_file():
shutil.copy(test_mvr_scene_path, generated_path)
elif file_name == "test.mvr":
_create_test_mvr(generated_path)
elif file_name == "test_json.mvr":
_create_test_json_mvr(generated_path)
else:
pytest.skip(f"Test file {file_name} is not available")

mvr_scene = pymvr.GeneralSceneDescription(generated_path)
yield mvr_scene


Expand Down
7 changes: 3 additions & 4 deletions tests/test_mvr_01_write_ours.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import pytest
from pathlib import Path
import pymvr
import pytest


def process_mvr_child_list(child_list, mvr_scene):
Expand All @@ -46,11 +45,11 @@ def process_mvr_child_list(child_list, mvr_scene):


@pytest.mark.parametrize("mvr_scene", [("basic_fixture.mvr",)], indirect=True)
def test_write_mvr_file(mvr_scene):
def test_write_mvr_file(mvr_scene, tmp_path):
mvr = pymvr.GeneralSceneDescriptionWriter()
mvr_scene.scene.to_xml(mvr.xml_root)
mvr_scene.user_data.to_xml(mvr.xml_root)
# TODO: add back file iteration to include gdtf files in the zip file

test_file_path = Path(Path(__file__).parent, "test.mvr")
test_file_path = tmp_path / "test.mvr"
mvr.write_mvr(test_file_path)
5 changes: 2 additions & 3 deletions tests/test_mvr_03_write_ours_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pathlib import Path
import pymvr


def test_write_from_json():
def test_write_from_json(tmp_path):
# TODO: add some assertions
data = [
{
Expand Down Expand Up @@ -83,5 +82,5 @@ def test_write_from_json():

scene = pymvr.Scene(layers=layers)
scene.to_xml(mvr.xml_root)
test_file_path = Path(Path(__file__).parent, "test_json.mvr")
test_file_path = tmp_path / "test_json.mvr"
mvr.write_mvr(test_file_path)
5 changes: 2 additions & 3 deletions tests/test_mvr_05_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pathlib import Path
import pymvr


def test_write_example_mvr_file():
def test_write_example_mvr_file(tmp_path):
fixtures_list = []
mvr = pymvr.GeneralSceneDescriptionWriter()

Expand All @@ -46,5 +45,5 @@ def test_write_example_mvr_file():
scene.to_xml(parent=mvr.xml_root)

mvr.files_list = list(set(fixtures_list))
test_file_path = Path(Path(__file__).parent, "example.mvr")
test_file_path = tmp_path / "example.mvr"
mvr.write_mvr(test_file_path)