commit 391fbd3caccf007d15614c1fb6de7f76716c474e
parent ceefff40dade5965c9d48cc8e43a8cdec1702b87
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sun, 10 May 2026 00:13:38 +0200
test(qgis): cover GeoPackage load invariants
Diffstat:
| M | test/test_core.py | | | 98 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 98 insertions(+), 0 deletions(-)
diff --git a/test/test_core.py b/test/test_core.py
@@ -823,3 +823,101 @@ class PluginTests(unittest.TestCase):
[layer.name for layer in project.root.groups[0].layers],
["points", "layers"],
)
+
+ def test_load_xyz_uses_source_crs_and_loads_styles(self):
+ module, _, _ = self._import_plugin_module()
+ points = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": 3.0,
+ "Geometry": "POINT Z (1 2 3)",
+ }
+ ]
+ doi_points = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": -4.0,
+ "DOI": 7.0,
+ "Geometry": "POINT Z (1 2 -4)",
+ }
+ ]
+ layers = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": 3.0,
+ "Layer": 1,
+ "Geometry": "LINESTRING Z (1 2 3, 1 2 2)",
+ }
+ ]
+ module.core.process_xyz = Mock(return_value=(points, doi_points, layers))
+ module.core.detect_source_epsg = Mock(return_value="EPSG:25832")
+ plugin = module.TEMLoaderPlugin(Mock())
+
+ plugin._load_xyz(Path("/tmp/styled.xyz"))
+
+ self.assertEqual(
+ [call["crs"].authid() for call in module.QgsVectorFileWriter.calls],
+ ["EPSG:25832", "EPSG:25832", "EPSG:25832"],
+ )
+ self.assertEqual(
+ {
+ layer.name: [Path(style).name for style in layer.styles]
+ for layer in module.QgsVectorLayer.created
+ },
+ {
+ "layers": ["layers.qml"],
+ "doi": ["doi.qml"],
+ "points": ["points.qml"],
+ },
+ )
+
+ def test_load_xyz_warns_about_failed_geopackage_layer_load(self):
+ module, _, message_box = self._import_plugin_module()
+ points = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": 3.0,
+ "Geometry": "POINT Z (1 2 3)",
+ }
+ ]
+ doi_points = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": -4.0,
+ "DOI": 7.0,
+ "Geometry": "POINT Z (1 2 -4)",
+ }
+ ]
+ layers = [
+ {
+ "X": 1.0,
+ "Y": 2.0,
+ "Z": 3.0,
+ "Layer": 1,
+ "Geometry": "LINESTRING Z (1 2 3, 1 2 2)",
+ }
+ ]
+ module.core.process_xyz = Mock(return_value=(points, doi_points, layers))
+ module.core.detect_source_epsg = Mock(return_value=None)
+ module.QgsVectorLayer.valid_by_name = {"doi": False}
+ iface = Mock()
+ iface.mainWindow.return_value = object()
+ plugin = module.TEMLoaderPlugin(iface)
+
+ plugin._load_xyz(Path("/tmp/model.xyz"))
+
+ project = module.QgsProject.instance()
+ self.assertEqual(
+ [layer.name for layer in project.root.groups[0].layers],
+ ["points", "layers"],
+ )
+ self.assertEqual(len(message_box.warnings), 1)
+ self.assertIn(
+ "model.xyz: failed to load layers: doi",
+ message_box.warnings[0][2],
+ )