From ee172af81f0d645ed7cc0a18c7a1b7175d584fe0 Mon Sep 17 00:00:00 2001 From: vanous Date: Sun, 7 Dec 2025 11:13:37 +0100 Subject: [PATCH] Use tmp_path in tests --- conftest.py | 94 +++++++++++++++++++++++++++- tests/test_mvr_01_write_ours.py | 7 +-- tests/test_mvr_03_write_ours_json.py | 5 +- tests/test_mvr_05_example.py | 5 +- 4 files changed, 99 insertions(+), 12 deletions(-) diff --git a/conftest.py b/conftest.py index bdc8d03..1950d8a 100644 --- a/conftest.py +++ b/conftest.py @@ -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 @@ -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 diff --git a/tests/test_mvr_01_write_ours.py b/tests/test_mvr_01_write_ours.py index f46ccf5..53a8dd3 100644 --- a/tests/test_mvr_01_write_ours.py +++ b/tests/test_mvr_01_write_ours.py @@ -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): @@ -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) diff --git a/tests/test_mvr_03_write_ours_json.py b/tests/test_mvr_03_write_ours_json.py index c522115..7d9d144 100644 --- a/tests/test_mvr_03_write_ours_json.py +++ b/tests/test_mvr_03_write_ours_json.py @@ -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 = [ { @@ -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) diff --git a/tests/test_mvr_05_example.py b/tests/test_mvr_05_example.py index ffa5f7e..e26f1e0 100644 --- a/tests/test_mvr_05_example.py +++ b/tests/test_mvr_05_example.py @@ -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() @@ -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)