Skip to content

Commit a628c2a

Browse files
committed
Add test for MVR read-write round-trip
1 parent 9fd084d commit a628c2a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ devel/
99
*whl
1010
*.mvr
1111
uv.lock
12+
mvr-spec
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# MIT License
2+
#
3+
# Copyright (C) 2025 vanous
4+
#
5+
# This file is part of pymvr.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
import pytest
26+
import os
27+
from pathlib import Path
28+
29+
30+
def test_read_write_round_trip(request, pymvr_module):
31+
# tests a single file, reading and then exporting
32+
# does not pack resources, only the XML
33+
# uv run pytest --file-path=/path/to/file.mvr -s -x
34+
file_path = request.config.getoption("--file-path")
35+
36+
if file_path is None:
37+
pytest.skip("File path not provided")
38+
file_read_path = Path(file_path)
39+
if not file_read_path.is_file():
40+
pytest.skip("File does not exist")
41+
file_read_dir = file_read_path.parent
42+
file_read_name = file_read_path.stem
43+
file_write_path = Path(file_read_dir, f"{file_read_name}_exported.mvr")
44+
45+
with pymvr_module.GeneralSceneDescription(file_read_path) as mvr_read:
46+
mvr_writer = pymvr_module.GeneralSceneDescriptionWriter()
47+
48+
mvr_read.scene.to_xml(parent=mvr_writer.xml_root)
49+
mvr_read.user_data.to_xml(parent=mvr_writer.xml_root)
50+
51+
mvr_writer.write_mvr(file_write_path)

tests/test_with_files.py renamed to tests/test_reading_with_many_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pathlib import Path
2828

2929

30-
def test_with_file(request, pymvr_module):
30+
def test_reading_with_many_files(request, pymvr_module):
3131
# uv run pytest --file-path=../../gdtfs/ -s
3232
file_path = request.config.getoption("--file-path")
3333

0 commit comments

Comments
 (0)