From 456f02b099f9859857ad1de86b89c4c9b9f65a52 Mon Sep 17 00:00:00 2001 From: anikaweinmann Date: Wed, 5 Jun 2024 10:32:15 +0200 Subject: [PATCH 1/3] add check_number_of_grass_elements as tests-helper --- src/grass_gis_helpers/tests.py | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/grass_gis_helpers/tests.py diff --git a/src/grass_gis_helpers/tests.py b/src/grass_gis_helpers/tests.py new file mode 100644 index 0000000..ddc9ffb --- /dev/null +++ b/src/grass_gis_helpers/tests.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +############################################################################ +# +# MODULE: lib with test related helper functions for GRASS GIS +# +# AUTHOR(S): Anika Weinmann +# +# PURPOSE: lib with test related helper functions for GRASS GIS +# +# COPYRIGHT: (C) 2024 by mundialis and the GRASS Development Team +# +# This program is free software under the GNU General Public +# License (>=v2). Read the file COPYING that comes with GRASS +# for details. +# +############################################################################# + +import grass.script as grass + + +def get_number_of_grass_elements(): + """Get the number of grass elements like raster, vector and regions + + Returns: + num_rast (int): The number of raster maps in current mapset + num_vect (int): The number of vector maps in current mapset + num_gr (int): The number of groups in current mapset + num_reg (int): The number of regions in current mapset + num_mapsets (int): The number of mapsets in current location + """ + rast_list = grass.parse_command("g.list", type="raster") + vect_list = grass.parse_command("g.list", type="vector") + gr_list = grass.parse_command("g.list", type="group") + reg_list = grass.parse_command("g.list", type="region") + mapset_list = grass.parse_command("g.mapsets", flags="l", quiet=True) + num_rast = len(rast_list) + num_vect = len(vect_list) + num_gr = len(gr_list) + num_reg = len(reg_list) + num_mapsets = len(mapset_list) + return num_rast, num_vect, num_gr, num_reg, num_mapsets + + +def check_number_of_grass_elements( + ref_num_rast, ref_num_vect, ref_num_gr, ref_num_reg, ref_num_mapsets + ): + """Check the number of grass elements + + Args: + ref_num_rast (int): The reference number of raster maps + ref_num_vect (int): The reference number of vector maps + ref_num_gr (int): The reference number of groups + ref_num_reg (int): The reference number of regions + ref_num_mapsets (int): The reference number of mapsets + + """ + n_rast, n_vect, n_gr, n_reg, n_mapsets = get_number_of_grass_elements() + for num, ref, data_type in [ + (n_rast, ref_num_rast, "rasters"), + (n_vect, ref_num_vect, "vectors"), + (n_gr, ref_num_gr, "groups"), + (n_reg, ref_num_reg, "regions"), + (n_mapsets, ref_num_mapsets, "mapsets"), + ]: + assert num == ref, f"The number of {data_type} is {num} but should be {ref}" From 696285a7db2cd96c1d39c0e54e33df1e2a65d232 Mon Sep 17 00:00:00 2001 From: anikaweinmann Date: Wed, 5 Jun 2024 10:52:01 +0200 Subject: [PATCH 2/3] linting --- src/grass_gis_helpers/tests.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/grass_gis_helpers/tests.py b/src/grass_gis_helpers/tests.py index ddc9ffb..365ac25 100644 --- a/src/grass_gis_helpers/tests.py +++ b/src/grass_gis_helpers/tests.py @@ -43,8 +43,8 @@ def get_number_of_grass_elements(): def check_number_of_grass_elements( - ref_num_rast, ref_num_vect, ref_num_gr, ref_num_reg, ref_num_mapsets - ): + ref_num_rast, ref_num_vect, ref_num_gr, ref_num_reg, ref_num_mapsets +): """Check the number of grass elements Args: @@ -63,4 +63,6 @@ def check_number_of_grass_elements( (n_reg, ref_num_reg, "regions"), (n_mapsets, ref_num_mapsets, "mapsets"), ]: - assert num == ref, f"The number of {data_type} is {num} but should be {ref}" + assert ( + num == ref + ), f"The number of {data_type} is {num} but should be {ref}" From 749ba8168b737ec737000987433bf0ac0d7b8ac2 Mon Sep 17 00:00:00 2001 From: anikaweinmann Date: Wed, 5 Jun 2024 10:42:30 +0200 Subject: [PATCH 3/3] adjust linting to version 1.2.0 --- .github/workflows/linting.yml | 2 +- RELEASE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 39eb1ac..6e67f2d 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -4,4 +4,4 @@ on: [push] jobs: lint: - uses: mundialis/github-workflows/.github/workflows/linting.yml@main + uses: mundialis/github-workflows/.github/workflows/linting.yml@1.2.0 diff --git a/RELEASE.md b/RELEASE.md index f85e3b1..c75cdd4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -17,4 +17,4 @@ Steps when releasing: - At the bottom of the release, add "generated with `gh api repos/$REPO_NAME/releases/generate-notes -f tag_name="$ESTIMATED_VERSION" -f target_commitish=main -q .body`" and replace `$REPO_NAME` and `$ESTIMATED_VERSION` with the actual version. - Make sure that the checkbox for "Set as the latest release" is checked so that this version appears on the main github repo page -- Now you can save the release \ No newline at end of file +- Now you can save the release