|
| 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) |
0 commit comments