Skip to content

testing: add get_cloud function (SC-461)#1038

Merged
blackboxsw merged 3 commits into
canonical:mainfrom
TheRealFalcon:test-distros
Oct 16, 2021
Merged

testing: add get_cloud function (SC-461)#1038
blackboxsw merged 3 commits into
canonical:mainfrom
TheRealFalcon:test-distros

Conversation

@TheRealFalcon
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon commented Sep 28, 2021

Proposed Commit Message

testing: add get_cloud function

Also added supporting distro/datasource classes and updated tests
that have a `get_cloud` call.

Additional Context

The main change is util.py. Mostly everything else is updating call points.

Test Steps

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

return mock_writefile, mock_loadfile, mock_isfile, mock_shouldcfg
mycloud = get_cloud(distro)

with ExitStack() as stack:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The get_cloud call in these tests included a call to patchUtils, so updated this section to also mock out del_file. The rest is just syntactic sugar to not have so much nesting with the mocks.

@TheRealFalcon TheRealFalcon changed the title testing: add get_cloud function testing: add get_cloud function (SC-461) Sep 29, 2021
@holmanb
Copy link
Copy Markdown
Member

holmanb commented Oct 13, 2021

Looks good to me.

Comment thread tests/unittests/util.py
Comment on lines +28 to +33
def abstract_to_concrete(abclass):
"""Takes an abstract class and returns a concrete version of it."""
class concreteCls(abclass):
pass
concreteCls.__abstractmethods__ = frozenset()
return type('DummyConcrete' + abclass.__name__, (concreteCls,), {})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice; this works. I was a bit hesitant about using this approach as I wondered why TestingDistro couldn't be used in tests/unittests/test_distros/test_create_users.py but I get that create_users is trying to assert on the actual base abstract class. +1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants