Skip to content

Commit 28ed832

Browse files
fixes unit tests
Signed-off-by: Nishant Bansal <[email protected]>
1 parent ba0651c commit 28ed832

1 file changed

Lines changed: 41 additions & 18 deletions

File tree

raster/r.category/tests/r_category_test.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ def test_r_category_plain_output(simple_dataset):
2121
stdin=input_data,
2222
env=session.env,
2323
)
24-
result = gs.read_command("r.category", map="test", separator=",", env=session.env)
24+
25+
# Replacing '\r' because Windows uses '\r\n' for line endings, but we
26+
# want to remove the '\r' (carriage return) to standardize line endings.
27+
result = gs.read_command(
28+
"r.category", map="test", separator=",", env=session.env
29+
).replace("\r", "")
2530

2631
expected_output = "1,trees\n2,water\n"
2732
assert result == expected_output, f"Expected {expected_output}, but got {result}"
@@ -35,7 +40,11 @@ def test_r_category_default_separator(simple_dataset):
3540
gs.write_command(
3641
"r.category", map="test", rules="-", stdin=input_data, env=session.env
3742
)
38-
result = gs.read_command("r.category", map="test", separator="tab", env=session.env)
43+
44+
# remove the '\r' (carriage return) to standardize line endings.
45+
result = gs.read_command(
46+
"r.category", map="test", separator="tab", env=session.env
47+
).replace("\r", "")
3948

4049
expected_output = "1\ttrees\n2\twater\n"
4150
assert result == expected_output, f"Expected {expected_output}, but got {result}"
@@ -54,7 +63,11 @@ def test_r_category_with_range(simple_dataset):
5463
stdin=input_data,
5564
env=session.env,
5665
)
57-
result = gs.read_command("r.category", map="test_1", separator=" ", env=session.env)
66+
67+
# remove the '\r' (carriage return) to standardize line endings.
68+
result = gs.read_command(
69+
"r.category", map="test_1", separator=" ", env=session.env
70+
).replace("\r", "")
5871

5972
expected_output = "1 trees\n2 buildings\n3 buildings\n4 buildings\n"
6073
assert result == expected_output, f"Expected {expected_output}, but got {result}"
@@ -79,7 +92,9 @@ def test_r_category_float_map(simple_dataset):
7992
separator=" ",
8093
vals=[1, 1.1, 2.1, 4],
8194
env=session.env,
82-
)
95+
).replace(
96+
"\r", ""
97+
) # remove the '\r' (carriage return) to standardize line endings.
8398

8499
expected_output = "1 trees\n1.1 trees\n2.1 buildings\n4 \n"
85100
assert result == expected_output, f"Expected {expected_output}, but got {result}"
@@ -106,7 +121,9 @@ def test_r_category_separator_variants(simple_dataset):
106121
for sep, expected in zip(separators, expected_outputs):
107122
result = gs.read_command(
108123
"r.category", map="test", separator=sep, env=session.env
109-
)
124+
).replace(
125+
"\r", ""
126+
) # remove the '\r' (carriage return) to standardize line endings.
110127
assert (
111128
result == expected
112129
), f"Expected {expected}, but got {result} for separator '{sep}'"
@@ -142,7 +159,9 @@ def test_r_category_input_separators(simple_dataset):
142159
)
143160
result = gs.read_command(
144161
"r.category", map="test", separator=out_sep, env=session.env
145-
)
162+
).replace(
163+
"\r", ""
164+
) # remove the '\r' (carriage return) to standardize line endings.
146165
assert (
147166
result == expected
148167
), f"Expected {expected}, but got {result} for input separator '{inp_sep}'"
@@ -176,7 +195,9 @@ def test_r_category_multiword_input(simple_dataset):
176195
)
177196
result = gs.read_command(
178197
"r.category", map="test", separator=out_sep, env=session.env
179-
)
198+
).replace(
199+
"\r", ""
200+
) # remove the '\r' (carriage return) to standardize line endings.
180201
assert (
181202
result == expected
182203
), f"Expected {expected}, but got {result} for input '{data}'"
@@ -225,10 +246,9 @@ def test_r_category_json_output(simple_dataset):
225246
stdin=input_data,
226247
env=session.env,
227248
)
228-
result = gs.read_command(
229-
"r.category", map="test", output_format="json", env=session.env
249+
result = json.loads(
250+
gs.read_command("r.category", map="test", output_format="json", env=session.env)
230251
)
231-
result = json.loads(result)
232252

233253
expected = [
234254
{"category": 1, "description": "trees, very green"},
@@ -291,14 +311,15 @@ def test_r_category_with_json_output_color(simple_dataset):
291311
]
292312

293313
for color, expected in zip(colors, expected_outputs):
294-
result = gs.read_command(
295-
"r.category",
296-
map="test",
297-
output_format="json",
298-
color=color,
299-
env=session.env,
314+
result = json.loads(
315+
gs.read_command(
316+
"r.category",
317+
map="test",
318+
output_format="json",
319+
color=color,
320+
env=session.env,
321+
)
300322
)
301-
result = json.loads(result)
302323
assert result == expected, f"test failed: expected {expected} but got {result}"
303324

304325

@@ -331,5 +352,7 @@ def test_r_category_with_plain_output_color(simple_dataset):
331352
separator=" ",
332353
color=color,
333354
env=session.env,
334-
)
355+
).replace(
356+
"\r", ""
357+
) # remove the '\r' (carriage return) to standardize line endings.
335358
assert result == expected, f"test failed: expected {expected} but got {result}"

0 commit comments

Comments
 (0)