Skip to content

Commit

Permalink
test algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Jan 14, 2024
1 parent 7d58522 commit 58e8caf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/scripts/test_field_names.rsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##test long fieldnames=name
##my group=group
##Layer=vector
##fieldname=output string
fieldname <- fieldnames[length(fieldnames)]
22 changes: 22 additions & 0 deletions tests/test_algorithm_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,25 @@ def test_crs():
# invalid CRS
script = alg.build_import_commands({"in_crs": QgsCoordinateReferenceSystem("user:4326")}, context, feedback)
assert "in_crs <- NULL" in script


def test_convert_memory_layer_to_gpkg():
"""
Test reading vector inputs
"""
alg = RAlgorithm(description_file=script_path("test_field_names.rsx"))
alg.initAlgorithm()

context = QgsProcessingContext()
feedback = QgsProcessingFeedback()

uri = "point?crs=epsg:4326&field=very_long_fieldname_not_suitable_for_SHP:integer"
layer = QgsVectorLayer(uri, "layer", "memory")

script = alg.build_import_commands({"Layer": layer}, context, feedback)

first_line = script[0]

# test that default format is GPKG saved in tmp directory
assert first_line.startswith('Layer <- st_read("/tmp')
assert first_line.endswith('Layer.gpkg", quiet = TRUE, stringsAsFactors = FALSE)')

0 comments on commit 58e8caf

Please sign in to comment.