Skip to content

Commit ee172af

Browse files
committed
Use tmp_path in tests
1 parent 1795f4b commit ee172af

File tree

4 files changed

+99
-12
lines changed

4 files changed

+99
-12
lines changed

conftest.py

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25+
import shutil
2526
from pathlib import Path
2627
import pytest
2728
import pymvr
@@ -32,12 +33,101 @@
3233

3334

3435
@pytest.fixture(scope="function")
35-
def mvr_scene(request):
36+
def mvr_scene(request, tmp_path):
37+
def _create_test_mvr(path: Path):
38+
"""Generate a minimal test.mvr matching existing assertions."""
39+
writer = pymvr.GeneralSceneDescriptionWriter()
40+
addresses = pymvr.Addresses(
41+
addresses=[pymvr.Address(dmx_break=1, address=1, universe=1)]
42+
)
43+
fixture = pymvr.Fixture(
44+
name="LED PAR 64 RGBW",
45+
gdtf_spec="LED PAR 64 RGBW.gdtf",
46+
gdtf_mode="Default",
47+
addresses=addresses,
48+
matrix=pymvr.Matrix(
49+
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [5.0, 5.0, 5.0, 0]]
50+
),
51+
)
52+
layer = pymvr.Layer(
53+
name="Test layer",
54+
child_list=pymvr.ChildList(fixtures=[fixture]),
55+
)
56+
scene = pymvr.Scene(layers=pymvr.Layers([layer]))
57+
writer.serialize_scene(scene)
58+
writer.write_mvr(path)
59+
60+
def _create_test_json_mvr(path: Path):
61+
"""Generate a minimal test_json.mvr matching existing assertions."""
62+
writer = pymvr.GeneralSceneDescriptionWriter()
63+
child_list = pymvr.ChildList()
64+
fixtures = [
65+
{
66+
"gdtf_mode": "Standard mode",
67+
"uuid": "0153f926-8766-442c-bc5f-57b9407c8e35",
68+
"addresses": [
69+
{"dmx_break": 1, "address": 1, "universe": 1},
70+
],
71+
"gdtf_spec": "BlenderDMX@Basic_LED_Bulb@ver2.gdtf",
72+
"fixture_id": 1,
73+
},
74+
{
75+
"gdtf_mode": "Standard mode",
76+
"uuid": "5321f77d-4647-48b6-8798-25ac9292cc2d",
77+
"addresses": [
78+
{"dmx_break": 1, "address": 10, "universe": 1},
79+
],
80+
"gdtf_spec": "BlenderDMX@Basic_LED_Bulb@ver2.gdtf",
81+
"fixture_id": 1,
82+
},
83+
]
84+
85+
for fixture_data in fixtures:
86+
new_addresses = [
87+
pymvr.Address(
88+
dmx_break=address["dmx_break"],
89+
address=address["address"],
90+
universe=address["universe"],
91+
)
92+
for address in fixture_data["addresses"]
93+
]
94+
95+
child_list.fixtures.append(
96+
pymvr.Fixture(
97+
name=fixture_data["gdtf_spec"],
98+
uuid=fixture_data["uuid"],
99+
gdtf_spec=fixture_data["gdtf_spec"],
100+
gdtf_mode=fixture_data["gdtf_mode"],
101+
fixture_id=fixture_data["fixture_id"],
102+
addresses=pymvr.Addresses(addresses=new_addresses),
103+
matrix=pymvr.Matrix(0),
104+
)
105+
)
106+
107+
layer = pymvr.Layer(
108+
name="Layer 1",
109+
uuid="1e4954b5-992c-4146-b71f-5b497834087f",
110+
child_list=child_list,
111+
)
112+
scene = pymvr.Scene(layers=pymvr.Layers([layer]))
113+
writer.serialize_scene(scene)
114+
writer.write_mvr(path)
115+
36116
file_name = request.param[0]
37117
test_mvr_scene_path = Path(
38118
Path(__file__).parents[0], "tests", file_name
39119
) # test file path is made from current directory, tests directory and a file name
40-
mvr_scene = pymvr.GeneralSceneDescription(test_mvr_scene_path)
120+
generated_path = tmp_path / file_name
121+
if test_mvr_scene_path.is_file():
122+
shutil.copy(test_mvr_scene_path, generated_path)
123+
elif file_name == "test.mvr":
124+
_create_test_mvr(generated_path)
125+
elif file_name == "test_json.mvr":
126+
_create_test_json_mvr(generated_path)
127+
else:
128+
pytest.skip(f"Test file {file_name} is not available")
129+
130+
mvr_scene = pymvr.GeneralSceneDescription(generated_path)
41131
yield mvr_scene
42132

43133

tests/test_mvr_01_write_ours.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
import pytest
26-
from pathlib import Path
2725
import pymvr
26+
import pytest
2827

2928

3029
def process_mvr_child_list(child_list, mvr_scene):
@@ -46,11 +45,11 @@ def process_mvr_child_list(child_list, mvr_scene):
4645

4746

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

55-
test_file_path = Path(Path(__file__).parent, "test.mvr")
54+
test_file_path = tmp_path / "test.mvr"
5655
mvr.write_mvr(test_file_path)

tests/test_mvr_03_write_ours_json.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
from pathlib import Path
2625
import pymvr
2726

2827

29-
def test_write_from_json():
28+
def test_write_from_json(tmp_path):
3029
# TODO: add some assertions
3130
data = [
3231
{
@@ -83,5 +82,5 @@ def test_write_from_json():
8382

8483
scene = pymvr.Scene(layers=layers)
8584
scene.to_xml(mvr.xml_root)
86-
test_file_path = Path(Path(__file__).parent, "test_json.mvr")
85+
test_file_path = tmp_path / "test_json.mvr"
8786
mvr.write_mvr(test_file_path)

tests/test_mvr_05_example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
from pathlib import Path
2625
import pymvr
2726

2827

29-
def test_write_example_mvr_file():
28+
def test_write_example_mvr_file(tmp_path):
3029
fixtures_list = []
3130
mvr = pymvr.GeneralSceneDescriptionWriter()
3231

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

4847
mvr.files_list = list(set(fixtures_list))
49-
test_file_path = Path(Path(__file__).parent, "example.mvr")
48+
test_file_path = tmp_path / "example.mvr"
5049
mvr.write_mvr(test_file_path)

0 commit comments

Comments
 (0)