-
Notifications
You must be signed in to change notification settings - Fork 1k
tests: pytestified test_cc_rsyslog.py #6622
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
tests: pytestified test_cc_rsyslog.py #6622
Conversation
|
@blackboxsw could you please verify this? |
blackboxsw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MoeSalah1999 please follow https://docs.cloud-init.io/en/latest/development/index.html which documents running tox-e format .
Also:
I don't think basecfg or bsdcfg need to be fixtures, it's also not good practice to share mutable fixtures when the individual tests modify that mutable structure as it'll lead to intermittent test failures when running tests in parallel. Since they are just plain dicts that do not require resource setup, how about just define them as class-level attributes which are manipulated via copy.deepcopy before updating.
|
|
||
|
|
||
| @pytest.fixture | ||
| def temp_dir(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest already has a tmpdir fixture, not need to define our own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clearing that up and for the guidance! I made all the changes you requested, please verify them at your convenience.
|
Additionally please format the proposed commit message suggestion to correctly represent conventional commits. And the footer of a commit message should not say |
| (os.path.join(temp_dir, "default.cfg"), "*.* foohost\n"), | ||
| (os.path.join(temp_dir, "my.cfg"), "abc\n"), | ||
| (os.path.join(temp_dir, "mydir/mycfg"), "filefoo-content\n"), | ||
| (os.path.join(tmpdir, "default.cfg"), "*.* foohost\n"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for this nit, tmpdir already provides a tmpdir.join method, so we don't need the extra os.path.join calls throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I was so eager to make that change, but I didn't wanna mess with anything other than what you instructed me to do. I'll get right on it.
blackboxsw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tmpdir.join where possible otherwise looks good to me. Thank you!
1e396a6 to
29282d5
Compare
| cfg = copy.deepcopy(self.BSDCFG) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.BSDCFG doesn't appear to be manipulated in this test. So you can just use it directly on line 98, no need to deepcopy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion, how about I construct a fresh dict literal in this test only, to avoid silently re-introducing shared mutable states, and to not lose protection against implementation changes in load_config().
| ): | ||
| cloud = get_cloud(distro="freebsd", metadata={}) | ||
| self.assertEqual(load_config({}, distro=cloud.distro), self.bsdcfg) | ||
| assert load_config({}, distro=cloud.distro) == cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| assert load_config({}, distro=cloud.distro) == cfg | |
| assert load_config({}, distro=cloud.distro) == self.BSDCFG |
| fname = os.path.join(self.tmp, "foo.cfg") | ||
| self.assertEqual([fname], changed) | ||
| self.assertEqual(util.load_text_file(fname), cfgline + "\n") | ||
| fname = tmpdir.join("foo.cfg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just str(....) up here insetad of at the two callsites using fname below
| fname = tmpdir.join("foo.cfg") | |
| fname = str(tmpdir.join("foo.cfg")) |
blackboxsw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @MoeSalah1999 again. two minor nits and we'll land this.
blackboxsw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it! Thanks again @MoeSalah1999
-made sure test case classes don't inherit from TestCase -used pytest fixtures instead of unittest setUp method -converted all self.assert to plain assert. Related GH-6427
Proposed Commit Message
Additional Context
Test Steps
Merge type