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

Add unit tests for the ToolGroup class #2832

Merged

Conversation

riya-17
Copy link
Member

@riya-17 riya-17 commented May 12, 2022

PBENCH-666

Adding Unit Tests for ToolGroup. Part of PbenchAgent Test Coverage

@riya-17 riya-17 requested review from dbutenhof and webbnh May 12, 2022 12:23
@riya-17 riya-17 self-assigned this May 12, 2022
@portante portante added this to the v0.72 milestone May 12, 2022
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
@dbutenhof
Copy link
Member

Well this is new: black is blowing up with a stack trace because:

PermissionError: [Errno 13] Permission denied: 'agent/bench-scripts/test-bin/ansible'

I'm seeing this in multiple PRs now...

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

My apologies for not posting these last night -- I only got part-way through the review and then got totally sidetracked by the Jenkins problem.

So, here are my comments so far...more to come

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

This is great stuff, Riya! It just needs a little touching up and some enhancement.

  • The tests should not be relying on assumptions about the environment. E.g., if they expect an environment variable to be undefined, they should remove it; and, if they expect a file or directory to not exist, they should be using mocks for the Path functions instead of assuming that "funny names" won't exist in the file system.
  • I think you're missing a test case for a successful call to ToolGroup.verify_tool_group(). (Yes, the tests of the ToolGroup constructor would imply that it's working, but we should not necessarily be including verify_tool_group() within that "unit".)
  • I recommend a different approach to testing the ToolGroup constructor. I think there are several scenarios that we should test, four of which would be very simple and one which would be fairly comprehensive, and I think we should integrate testing get_labels() and get_tools() into those scenarios rather than testing them separately (and, we should be testing the rest of the ToolGroup interface (i.e., specific object attributes) as well. (Also, for testing the ToolGroup constructor, I would recommend mocking verify_tool_group() -- I think that will simplify things as well as giving you better control.)

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
@riya-17 riya-17 force-pushed the tool_group_unit_test branch from 936604e to d4829c1 Compare May 26, 2022 11:02
@riya-17 riya-17 requested review from dbutenhof, webbnh and portante May 26, 2022 14:32
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

Riya, this is coming along nicely! Most of my comments are bits of polishing around docstrings. However, I found one pair of assertions which look broken, and so I think you should consider a different mock for listdir() for the trigger file tests. Also, I wrote up a sample for how you might do the complex test scenario.

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
webbnh
webbnh previously approved these changes May 27, 2022
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

This is looking good. Just one small point. (And, I'm still hoping that you'll try for a more comprehensive "last test". 🙂)

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
@riya-17
Copy link
Member Author

riya-17 commented May 31, 2022

This is looking good. Just one small point. (And, I'm still hoping that you'll try for a more comprehensive "last test". slightly_smiling_face)

Yes, I was working on that, I just updated the last test in last commit

webbnh
webbnh previously approved these changes May 31, 2022
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

This looks really nice, Riya -- thanks for all of your effort on this!

If no one else has anything for you to change, we can skip my comments below (unless there's something there that you want to fix 😉) -- they are just polish, at this point -- you've got all the important stuff covered!

lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/agent/test_tool_group.py Outdated Show resolved Hide resolved
@riya-17 riya-17 force-pushed the tool_group_unit_test branch from 239b883 to 42b9062 Compare June 1, 2022 11:52
@riya-17 riya-17 requested a review from webbnh June 1, 2022 11:52
webbnh
webbnh previously approved these changes Jun 1, 2022
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

Ship it!

dbutenhof
dbutenhof previously approved these changes Jun 1, 2022
Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

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

Looks good!

For future reference, it's best to have a TITLE and then the Jira reference in the git log message, because the Jira reference isn't as useful to a reader in figuring out what you're doing. And it'll be easier if we have a common standard format. E.g.,

TITLE

PBENCH-666

DESCRIPTION

But (assuming that the Jira integration has been jump-started and is working again 😦 ), Jira should see your reference in the title so this ought to work.

PBENCH-666

Adding Unit Tests for ToolGroup, Part of PbenchAgent Test Coverage.
@riya-17 riya-17 dismissed stale reviews from dbutenhof and webbnh via a35af8c June 13, 2022 09:42
@riya-17 riya-17 force-pushed the tool_group_unit_test branch from 42b9062 to a35af8c Compare June 13, 2022 09:42
@riya-17 riya-17 requested review from webbnh and dbutenhof June 13, 2022 09:43
Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

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

FYI, Cobertura reports 96% of lines in tool_group.py are covered, and 93% of conditionals. That's pretty good... but analysis of the coverage map might gives you some ideas for another simple test case or two to improve that even more? (Unfortunately, the cobertura report in the PR's Jenkins artifacts complains that it "can't find the source" and won't show that detail.)

Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

This was just a rebase, right? (GitHub is claiming that there is only one commit and that the entire file is new.... 😞)

I'm assuming that you didn't actually change the code after the previous review.

@portante portante merged commit 0151038 into distributed-system-analysis:main Jun 13, 2022
@portante portante changed the title Adding Unit Tests for ToolGroup Add unit tests for the ToolGroup class Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants