def test_build_abstract(): actual = qgis.build_layer_abstract(mock_layer_cfg) expected = """Example Dataset Example abstract Citation: NSIDC 2020 Citation URL: https://nsidc.org""" assert actual == expected
def test_build_abstract_with_description(): mock_cfg = copy.deepcopy(mock_layer_cfg) mock_cfg['description'] = 'Example layer description' actual = qgis.build_layer_abstract(mock_cfg) expected = """Example layer description === Original Data Source === Example Dataset Example abstract Citation: NSIDC 2020 Citation URL: https://nsidc.org""" assert actual == expected
def test__add_layer_metadata(): mock_raster_path = os.path.join(PACKAGE_DIR, 'test', 'data', 'example.tif') mock_raster_layer = qgis.create_raster_map_layer(mock_raster_path, mock_layer_cfg) qgis._add_layer_metadata(mock_raster_layer, mock_layer_cfg) # The abstract gets set with the value returned by `qgis.build_abstract`. assert mock_raster_layer.metadata().abstract() == \ qgis.build_layer_abstract(mock_layer_cfg) actual_title = mock_raster_layer.metadata().title() expected_title = mock_layer_cfg['title'] assert actual_title == expected_title # Sets the spatial extent based on the the layer extent. expected_extent = mock_raster_layer.extent() # extent metadata contains both spatial and temporal elements. These are # lists. We set one overall extent for the dataset, so take the first element. meta_extent = mock_raster_layer.metadata().extent().spatialExtents()[0] # The `expected_extent` is a QgsRectangle. assert expected_extent == meta_extent.bounds.toRectangle()