Skip to content

v.colors: Added test cases #6105

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

v.colors: Added test cases #6105

wants to merge 15 commits into from

Conversation

dvrohan
Copy link
Contributor

@dvrohan dvrohan commented Jul 23, 2025

No description provided.

@github-actions github-actions bot added vector Related to vector data processing Python Related code is in Python module tests Related to Test Suite labels Jul 23, 2025
@echoix
Copy link
Member

echoix commented Jul 24, 2025

Since the test file wasn’t collected and executed, I directly renamed the folder so we can see if they pass

Comment on lines 176 to 178
assert "255:0:0" in out
assert "0:255:0" in out
assert "0:0:255" in out
Copy link
Member

Choose a reason for hiding this comment

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

Is the order inside a rule file important? For example, if a parsed rule file has its output order shuffled, does it matter?

Copy link
Contributor Author

@dvrohan dvrohan Jul 24, 2025

Choose a reason for hiding this comment

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

No the order is not important. The test case should work even when the order is shuffled. These lines are just checking the presence of Solid R, G and B values in the output.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, according to this, the test using "in" for an assert makes sense

Copy link
Member

Choose a reason for hiding this comment

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

The order in output is important. It does matter which features has the color assigned. Just like in the other cases, use JSON to get a easy to process format.

Copy link
Contributor Author

@dvrohan dvrohan Jul 28, 2025

Choose a reason for hiding this comment

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

The json output for "v.db.select" is as follows:
------------------------------------------------ Captured stdout call ------------------------------------------------
{'info': {'columns': [{'name': 'GRASSRGB', 'sql_type': 'CHARACTER', 'is_number': False}]}, 'records': [{'GRASSRGB': '255:0:0'}, {'GRASSRGB': '0:255:0'}, {'GRASSRGB': '0:0:255'}]}

How do I consider the order in this case? Do you mean the value of R should be before G and G should be before B everytime?

Copy link
Member

Choose a reason for hiding this comment

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

I mean that the first color is for the first point, the second color for the second one, e.g. point 1 is light yellow, point 2 bright red...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I have fixed that in the latest commit.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

This has a good spread of features it is testing (just seeing the test file, I didn't compare to the actual doc).

However, it requires more testing of the results. The existing and newly added JSON outputs will help with that and will also simplify the code.

In the meantime, #2923 is merged. It would be helpful to use it and test it that way. Using grass.tool will simplify the test code by replacing env=session.env for each tool call by session=session for each test function. It makes the code using file inputs simpler by providing a straightforward way for using stdin. Finally, it will make the JSON outputs easy to use.

Comment on lines 273 to 277
out = gs.read_command(
"v.db.select", map=mapname, columns="GRASSRGB", env=session.env
)
lines = out.strip().splitlines()[1:]
assert lines
Copy link
Member

Choose a reason for hiding this comment

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

This does not test much and really under-uses the output from v.db.select. Use the JSON output format of v.db.select (format="json").

Given that #2923 is merged, you can use (more to try it out rather than grass.tools being necessary here):

tools = Tools(session=session)
data = tools.v_db_select(map=mapname, columns="GRASSRGB")
# now assert different things about *data*

In any case, you can test more that way without any custom parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have used grass.tools as suggested.

Comment on lines 176 to 178
assert "255:0:0" in out
assert "0:255:0" in out
assert "0:0:255" in out
Copy link
Member

Choose a reason for hiding this comment

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

The order in output is important. It does matter which features has the color assigned. Just like in the other cases, use JSON to get a easy to process format.

result = tools.v_colors_out(map=mapname, format="json")
rules = json.loads(result.stdout)

values = [str(rule["value"]) for rule in rules]
Copy link
Member

Choose a reason for hiding this comment

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

Why the conversion to str?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was for checking a numeric value later on. But I have changed the function to isinstance now.

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 tests Related to Test Suite vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants