Skip to content

Commit eeff3fc

Browse files
r.what.color: add test file
Signed-off-by: Nishant Bansal <[email protected]>
1 parent ee8307b commit eeff3fc

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from grass.gunittest.case import TestCase
2+
from grass.gunittest.gmodules import SimpleModule
3+
4+
5+
class TestRWhatColor(TestCase):
6+
input = "elevation"
7+
value = "50\n100\n116.029\n135\n156\nbogus"
8+
9+
@classmethod
10+
def setUpClass(cls):
11+
cls.use_temp_region()
12+
cls.runModule("g.region", raster=cls.input, flags="p")
13+
14+
@classmethod
15+
def tearDownClass(cls):
16+
cls.del_temp_region()
17+
18+
def test_r_what_color_plain(self):
19+
"""Test r.what.color command for plain output format."""
20+
module = SimpleModule(
21+
"r.what.color", input=self.input, flags="i", stdin=self.value
22+
)
23+
self.assertModule(module)
24+
result = module.outputs.stdout
25+
expected = [
26+
"50: *",
27+
"100: 255:229:0",
28+
"116.029: 255:128:0",
29+
"135: 195:127:59",
30+
"156: 23:22:21",
31+
"*: *",
32+
]
33+
34+
result_lines = [line for line in result.split("\n") if line.strip() != ""]
35+
36+
self.assertListEqual(
37+
result_lines, expected, "Mismatch in printed output (plain)"
38+
)
39+
40+
def test_r_what_color_plain_with_format_option(self):
41+
"""Test the r.what.color command with the format option for plain text output."""
42+
module = SimpleModule(
43+
"r.what.color",
44+
input=self.input,
45+
flags="i",
46+
stdin=self.value,
47+
format="#%02X%02X%02X",
48+
)
49+
self.assertModule(module)
50+
result = module.outputs.stdout
51+
expected = [
52+
"50: *",
53+
"100: #FFE500",
54+
"116.029: #FF8000",
55+
"135: #C37F3B",
56+
"156: #171615",
57+
"*: *",
58+
]
59+
60+
result_lines = [line for line in result.split("\n") if line.strip() != ""]
61+
62+
self.assertListEqual(
63+
result_lines,
64+
expected,
65+
"Mismatch in printed output (plain) with the format option",
66+
)
67+
68+
69+
if __name__ == "__main__":
70+
from grass.gunittest.main import test
71+
72+
test()

0 commit comments

Comments
 (0)