Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
kritibirda26 and github-actions[bot] authored May 27, 2024
1 parent c8293c0 commit 819e55c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
60 changes: 40 additions & 20 deletions raster/r.info/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,12 @@ int main(int argc, char **argv)
}

if (gflag->answer) {
const char* data_type_f = (data_type == CELL_TYPE
? "CELL"
: (data_type == DCELL_TYPE
? "DCELL"
: (data_type == FCELL_TYPE ? "FCELL" : "??")));
const char *data_type_f =
(data_type == CELL_TYPE
? "CELL"
: (data_type == DCELL_TYPE
? "DCELL"
: (data_type == FCELL_TYPE ? "FCELL" : "??")));
grass_int64 total_cells = (grass_int64)cellhd.rows * cellhd.cols;

switch (format) {
Expand Down Expand Up @@ -514,7 +515,8 @@ int main(int argc, char **argv)
json_object_set_string(root_object, "datatype", data_type_f);
if (cats_ok) {
json_object_set_number(root_object, "ncats", cats.num);
} else {
}
else {
json_object_set_null(root_object, "ncats");
}
break;
Expand Down Expand Up @@ -591,7 +593,8 @@ int main(int argc, char **argv)
if (sflag->answer) {

if (!gflag->answer) {
grass_int64 total_cells = (grass_int64)cellhd.rows * cellhd.cols;
grass_int64 total_cells =
(grass_int64)cellhd.rows * cellhd.cols;
/* always report total number of cells */
switch (format) {
case PLAIN:
Expand All @@ -601,7 +604,6 @@ int main(int argc, char **argv)
json_object_set_number(root_object, "cells", total_cells);
break;
}

}

if (rstats.count > 0) {
Expand Down Expand Up @@ -756,24 +758,35 @@ int main(int argc, char **argv)
json_object_set_null(root_object, "vdatum");
}
if (semantic_label) {
json_object_set_string(root_object, "semantic_label", semantic_label);
} else {
json_object_set_string(root_object, "semantic_label",
semantic_label);
}
else {
json_object_set_null(root_object, "semantic_label");
}

if (hist_ok) {
json_object_set_string(root_object, "source1", Rast_get_history(&hist, HIST_DATSRC_1));
json_object_set_string(root_object, "source2", Rast_get_history(&hist, HIST_DATSRC_2));
json_object_set_string(root_object, "description", Rast_get_history(&hist, HIST_KEYWRD));
json_object_set_string(
root_object, "source1",
Rast_get_history(&hist, HIST_DATSRC_1));
json_object_set_string(
root_object, "source2",
Rast_get_history(&hist, HIST_DATSRC_2));
json_object_set_string(
root_object, "description",
Rast_get_history(&hist, HIST_KEYWRD));
JSON_Value *comments_value = json_value_init_array();
JSON_Array *comments = json_array(comments_value);
if (Rast_history_length(&hist)) {
for (i = 0; i < Rast_history_length(&hist); i++) {
json_array_append_string(comments, Rast_history_line(&hist, i));
json_array_append_string(
comments, Rast_history_line(&hist, i));
}
}
json_object_set_value(root_object, "comments", comments_value);
} else {
json_object_set_value(root_object, "comments",
comments_value);
}
else {
json_object_set_null(root_object, "source1");
json_object_set_null(root_object, "source2");
json_object_set_null(root_object, "description");
Expand Down Expand Up @@ -803,17 +816,24 @@ int main(int argc, char **argv)
}
break;
case JSON:
json_object_set_string(root_object, "source1", Rast_get_history(&hist, HIST_DATSRC_1));
json_object_set_string(root_object, "source2", Rast_get_history(&hist, HIST_DATSRC_2));
json_object_set_string(root_object, "description", Rast_get_history(&hist, HIST_KEYWRD));
json_object_set_string(
root_object, "source1",
Rast_get_history(&hist, HIST_DATSRC_1));
json_object_set_string(
root_object, "source2",
Rast_get_history(&hist, HIST_DATSRC_2));
json_object_set_string(
root_object, "description",
Rast_get_history(&hist, HIST_KEYWRD));
JSON_Value *comments_value = json_value_init_array();
JSON_Array *comments = json_array(comments_value);
if (Rast_history_length(&hist)) {
for (i = 0; i < Rast_history_length(&hist); i++) {
json_array_append_string(comments, Rast_history_line(&hist, i));
}
}
json_object_set_value(root_object, "comments", comments_value);
json_object_set_value(root_object, "comments",
comments_value);
break;
}
}
Expand Down
20 changes: 7 additions & 13 deletions raster/r.info/testsuite/test_r_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""

import json

from grass.gunittest.case import TestCase
Expand Down Expand Up @@ -81,7 +82,7 @@ def test_flagg_json(self):
"cols": 1500.0,
"cells": 2025000.0,
"datatype": "CELL",
"ncats": 43600.0
"ncats": 43600.0,
}
module = SimpleModule("r.info", map="lakes", flags="g", format="json")
self.runModule(module)
Expand All @@ -90,17 +91,14 @@ def test_flagg_json(self):

def test_flagr_json(self):
"""Testing flag r with map landcover_1m using simple module in json format"""
expected = {
"min": 34300.0,
"max": 43600.0
}
expected = {"min": 34300.0, "max": 43600.0}
module = SimpleModule("r.info", map="lakes", flags="r", format="json")
self.runModule(module)
result = json.loads(module.outputs.stdout)
self.assertDictEqual(expected, result)

def test_flage_json(self):
"""Testing flag e with map lsat7_2002_50 in json format """
"""Testing flag e with map lsat7_2002_50 in json format"""
expected = {
"map": "lakes",
"maptype": "raster",
Expand All @@ -117,9 +115,7 @@ def test_flage_json(self):
"source1": "",
"source2": "",
"description": "generated by r.mapcalc",
"comments": [
"1 * lakes_large"
]
"comments": ["1 * lakes_large"],
}

module = SimpleModule("r.info", map="lakes", flags="e", format="json")
Expand All @@ -132,14 +128,12 @@ def test_flage_json(self):
self.assertDictEqual(expected, result)

def test_flagh_json(self):
"""Testing flag h with map zipcodes in json format """
"""Testing flag h with map zipcodes in json format"""
expected = {
"source1": "",
"source2": "",
"description": "generated by r.mapcalc",
"comments": [
"1 * lakes_large"
]
"comments": ["1 * lakes_large"],
}
module = SimpleModule("r.info", map="lakes", flags="h", format="json")
self.runModule(module)
Expand Down

0 comments on commit 819e55c

Please sign in to comment.