Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.coin: added tests for r.coin module #4755

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Shreshth-Malik
Copy link
Contributor

The test parses the tabular output of r.coin, extracts relevant data, and compares it against expected results to ensure accurate calculate of category coincidences.

@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python module labels Nov 25, 2024
@Shreshth-Malik
Copy link
Contributor Author

Are there any more tests that I can perform for this tool?

Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there is missing something. There is only one test, so testing with all flags and options might be hard to do in a unit test way.

Since you're using pytest, the their assert handling might be enough to not need having a string explaining when it doesn't match. But you don't need to change it, just to know in the future (unless the output wasn't clear enough when you tested it).

Usually, what I consider makes a good test, is tests that you have confidence in to catch your bugs and future bugs. Tests that you have seen fail before, and that passes after. That means you know that the test isn't always passing even if it's not right. I usually like to check that the conditions that make the module fail are tested to fail, so that if ever it passes for no reason, it would be flagged in tests.

You don't need to do the same kind of test for all options. For example, I see that there is an unit argument, you might want to know that the module correctly accepts them, and rejects others.

But if you feel that what you have is enough, we can go with this for now

@echoix
Copy link
Member

echoix commented Nov 26, 2024

For now, the test doesn't run yet in CI, because the file name doesn't match the pattern hardcoded in pyproject.toml. (It bothered me in another PR too).

Do you mind testing (locally maybe) if removing that line includes too much files?

python_files = "*/tests/*_test.py"

Otherwise, change it to match the pytest defaults like explained in
https://docs.pytest.org/en/latest/reference/reference.html#confval-python_files, but inside tests folder only since I think it would catch the gunittest files too (not ready to run with pytest yet)

By default, files matching test_*.py and *_test.py will be considered test modules.

@Shreshth-Malik
Copy link
Contributor Author

@echoix So removing the line is resulting is a lot tests failing and messing up the build. So I placed my test in the tests folder with the right nomenclature. It is being included in the tests now but I am getting an error on line run_command("g.region", n=3, s=0, e=3, w=0, res=1) saying:
grass.exceptions.CalledModuleError: Module run g.region n=3 s=0 e=3 w=0 res=1 ended with an error. The subprocess ended with a non-zero return code: 1.

I tried calling run_command with Grass script context like gs.run_command but doesn't seem to work as well. Maybe there is something I am missing as the tests are passing locally.

I am planning to add tests for different units and see if the output consistently updates with changing the units.

@echoix
Copy link
Member

echoix commented Nov 27, 2024

@wenzeslaus do you have some guidance here? Is it a question of missing a session in pytest, since it is not a Python module, but a C one?

@Shreshth-Malik
Is there any other tests that use a C module that runs with pytest that you could see how it gets called/set up?

@Shreshth-Malik Shreshth-Malik marked this pull request as draft November 28, 2024 17:08
@Shreshth-Malik
Copy link
Contributor Author

Shreshth-Malik commented Nov 28, 2024

Added config file to setup the environment like other tests I ran into. But I am triggering another error in my local system where the session is not passing onto the test file and in the line gs.setup.init(project, env=os.environ.copy()) is not taking 2 arguments hence i can't pass env variable. I checked https://grass.osgeo.org/grass85/manuals/libpython/_modules/script/setup.html which gives an idea how to setup but in those examples init is taking the project and env variables successfully.

I will keep looking into it and try to see where it is going wrong.

@echoix
Copy link
Member

echoix commented Dec 15, 2024

@Shreshth-Malik I think this is working now, since #4784 got merged. We can see with code coverage that the new test got correctly run, and there are no failures. Do you still have local errors to solve, or is it ready to go? Was there anything else left to do in this PR currently marked as a draft?

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants