Skip to content

Commit

Permalink
Fix typechecker errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Aug 29, 2023
1 parent 63a37ae commit 65ba019
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 93 deletions.
6 changes: 2 additions & 4 deletions qgreenland/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"id": "example_online",
"title": "Example online",
"description": "Example layer description.",
"tags": ["foo", "bar", "baz"],
"in_package": True,
"packaging_tags": ["foo", "bar"],
"input": {
"dataset": {
"id": "baz",
Expand All @@ -48,8 +47,7 @@
"id": "example_raster",
"title": "Example raster",
"description": "Example layer description.",
"tags": ["foo", "bar", "baz"],
"in_package": True,
"packaging_tags": ["bar", "baz"],
"input": {
"dataset": {
"id": "example_dataset",
Expand Down
87 changes: 3 additions & 84 deletions qgreenland/test/util/config/test_config_export.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,10 @@
import csv
import json
import tempfile
from pathlib import Path
from unittest.mock import patch

from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR, MOCK_RELEASE_LAYERS_DIR
from qgreenland.util.config.export import export_config_csv, export_config_manifest


@patch(
"qgreenland.util.layer.RELEASE_LAYERS_DIR",
new=MOCK_RELEASE_LAYERS_DIR,
)
def test_export_config_manifest(full_cfg):
common = {
"description": "Example layer description.",
# TODO: Generate this with imported function? This should be tested
# by itself elsewhere, so there's no need to test the expected output
# here too.
"layer_details": """Example layer description.
=== Original Data Source ===
Example Dataset
Example abstract.
Citation:
NSIDC 2020
Citation URL:
https://nsidc.org""",
"tags": ["foo", "bar", "baz"],
"hierarchy": ["Group", "Subgroup"],
}
with tempfile.NamedTemporaryFile("r") as tf:
export_config_manifest(
full_cfg,
output_path=Path(tf.name),
)

actual = json.load(tf)

assert type(actual["qgr_version"]) is str
assert len(actual["qgr_version"]) >= 6
del actual["qgr_version"]

# For now, do not include online layers in the layer manifest. The
# `QGreenland Custom` QGIS Plugin does not currently support online
# layers. Once online layers are supported in the plugin, this commented out
# `online_asset` can be re-added:
# online_asset = {
# 'type': 'online',
# **full_cfg.layers['example_online'].input.asset.dict(
# include={'provider', 'url'},
# ),
# }
expected = {
"version": "v0.1.0",
"layers": [
# {
# 'id': 'example_online',
# 'title': 'Example online',
# 'assets': [online_asset],
# **common,
# },
{
"id": "example_raster",
"title": "Example raster",
"assets": [
{
"checksum": "a9a103f208179726038fa7178747a0a1",
"file": "example.tif",
"size_bytes": 287,
"type": "data",
},
{
"checksum": "22b427acc6e4ebf57052115fdd5ac450",
"file": "example.tif.aux.xml",
"size_bytes": 332,
"type": "ancillary",
},
],
**common,
},
],
}

assert actual == expected
from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR
from qgreenland.util.config.export import export_config_csv


@patch(
Expand All @@ -109,6 +27,7 @@ def test_export_config_csv(full_cfg):
export_config_csv(
full_cfg,
output_path=Path(tf.name),
package_name="bar",
)

actual = list(csv.DictReader(tf))
Expand Down
23 changes: 18 additions & 5 deletions qgreenland/test/util/test_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import qgreenland.util.qgis.project as prj
from qgreenland.test.constants import MOCK_COMPILE_PACKAGE_DIR

mock_package_name = "bar"


@pytest.mark.usefixtures("setup_teardown_qgis_app")
class TestQgisApp:
def test_make_map_layer_online(self, online_layer_node):
result = qgl.make_map_layer(online_layer_node)
result = qgl.make_map_layer(online_layer_node, package_name=mock_package_name)

assert "https://demo.mapserver.org" in result.source()
assert result.dataProvider().name() == "wms"
Expand All @@ -24,7 +26,7 @@ def test_make_map_layer_online(self, online_layer_node):
new=MOCK_COMPILE_PACKAGE_DIR,
)
def test_make_map_layer_raster(self, raster_layer_node):
result = qgl.make_map_layer(raster_layer_node)
result = qgl.make_map_layer(raster_layer_node, package_name=mock_package_name)

# The result is a a raster layer
assert isinstance(result, qgc.QgsRasterLayer)
Expand Down Expand Up @@ -52,7 +54,10 @@ def test_make_map_layer_raster(self, raster_layer_node):
new=MOCK_COMPILE_PACKAGE_DIR,
)
def test_add_layer_metadata(self, raster_layer_node):
mock_raster_layer = qgl.make_map_layer(raster_layer_node)
mock_raster_layer = qgl.make_map_layer(
raster_layer_node,
package_name=mock_package_name,
)

qgl.add_layer_metadata(mock_raster_layer, raster_layer_node.layer_cfg)

Expand Down Expand Up @@ -80,7 +85,11 @@ def test_add_layer_metadata(self, raster_layer_node):
def test__add_layers_and_groups(self, raster_layer_node):
# Test that _add_layers_and_groups works without error
project = qgc.QgsProject.instance()
prj._add_layers_and_groups(project, raster_layer_node.root)
prj._add_layers_and_groups(
project,
raster_layer_node.root,
package_name=mock_package_name,
)
added_layers = list(project.mapLayers().values())
assert len(added_layers) == 1
assert added_layers[0].name() == "Example raster"
Expand All @@ -91,5 +100,9 @@ def test__add_layers_and_groups(self, raster_layer_node):
# Test that an exception is raised when parent groups of a layer are not
# created first
with pytest.raises(exc.QgrQgsLayerTreeGroupError):
prj._add_layers_and_groups(project, raster_layer_node)
prj._add_layers_and_groups(
project,
raster_layer_node,
package_name=mock_package_name,
)
project.clear()

0 comments on commit 65ba019

Please sign in to comment.