Skip to content

tests: Un-shadow duplicated test method names in r.random and t.rast.gapfill - #7911

Merged
echoix merged 1 commit into
OSGeo:mainfrom
Anai-Guo:tests-unshadow-duplicate-test-names
Sep 18, 2026
Merged

echoix merged 1 commit into
OSGeo:mainfrom
Anai-Guo:tests-unshadow-duplicate-test-names

Conversation

@Anai-Guo

Copy link
Copy Markdown
Contributor

Two gunittest classes define the same test method name twice. Python binds the
second def over the first while executing the class body, so the earlier test
is gone before unittest ever looks at the class — it is never collected and
never run.

raster/r.random/testsuite/test_r_random.py

test_random_raster_flag_z (line 86) and test_vector_random_flag_z (line 101)
are redefined at lines 154 and 169.

The shadowed pair is the one that writes the _null outputs and is documented as
# check if random raster ( with NULL values ) was created. Those are exactly
the maps tearDownClass already cleans up:

name=(
    cls.raster,
    cls.raster + "_null",           # <- nothing creates this today
    cls.raster + "_without_topology",
    cls.raster + "_3D",
    ...

-z is "Generate vector points as 3D points" and is already covered by the
surviving pair (which writes _3D). The NULL behaviour is -n,
"Generate points also for NULL cells" (raster/r.random/main.c, flag.zero).
So the shadowed pair is renamed to test_random_raster_flag_n /
test_vector_random_flag_n and passes flags="n".

temporal/t.rast.gapfill/testsuite/test_gapfill.py

test_simple_gran (line 256) is redefined at line 301. The second copy passes
suffix="time" and asserts the test_2001_02_01T00_00_00 naming, so it is
renamed test_simple_gran_time_suffix — matching the convention in
t.rast.neighbors and t.rast.accumulate. That restores the default (gran)
suffix test, which asserts the test_2001_02 naming.

setUp / tearDown recreate and drop the A strds per test, so the two now run
independently.

Effect

Importing each module with grass.* stubbed and counting the collected
test_* attributes:

raster/r.random/testsuite/test_r_random.py  [TestRasterTile]
   BEFORE:  8 test methods
   AFTER : 10 test methods   (+ test_random_raster_flag_n, test_vector_random_flag_n)

temporal/t.rast.gapfill/testsuite/test_gapfill.py  [TestRasterToVector]
   BEFORE: 5 test methods
   AFTER : 6 test methods    (+ test_simple_gran_time_suffix)

I do not have a GRASS build here, so the newly collected tests have not been
executed locally — the Ubuntu gunittest job is the real check on this PR.

One pre-existing nit left alone: test_random_raster_flag_n, _flag_b and
_flag_z all assert assertRasterExists(self.raster) while their msg= names
the suffixed map. Tightening those three is a separate cleanup; say the word and
I will fold it in.


AI-assisted (the shadowing was surfaced by an AST sweep; the -n vs -z
reasoning and the diff are mine after reading main.c and the teardown list).

🤖 Generated with Claude Code

Two gunittest classes define the same test method name twice, so the
earlier definition is overwritten at class-body execution time and never
collected.

raster/r.random: test_random_raster_flag_z and test_vector_random_flag_z
are each defined twice. The first pair writes the "_null" outputs that
tearDownClass already cleans up and is documented as "( with NULL values
)", so it belongs to the -n flag ("Generate points also for NULL cells"),
not -z. Rename it to *_flag_n and pass flags="n". 8 -> 10 collected tests.

temporal/t.rast.gapfill: test_simple_gran is defined twice; the second
passes suffix="time", so name it test_simple_gran_time_suffix, matching
the convention used by t.rast.neighbors and t.rast.accumulate. This
restores the default-suffix test. 5 -> 6 collected tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added raster Related to raster data processing temporal Related to temporal data processing Python Related code is in Python module tests Related to Test Suite labels Sep 11, 2026
@echoix

echoix commented Sep 11, 2026

Copy link
Copy Markdown
Member

Claude is able and can build grass to run these checks, everything is already in the Claude docs, it works for me. Just insist.

@Anai-Guo

This comment has been minimized.

@echoix
echoix merged commit 08f30e8 into OSGeo:main Sep 18, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python raster Related to raster data processing temporal Related to temporal data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants