mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-05 00:31:37 -07:00
Cleanups to the common.sys_info API
* Move get_all_subclasses out of sys_info as it is unrelated to system information. * get_all_subclasses now returns a set() instead of a list. * Don't port get_platform to sys_info as it is deprecated. Code using the common API should just use platform.system() directly. * Rename load_platform_subclass() to get_platform_subclass and do not instantiate the rturned class. * Test the compat shims in module_utils/basic.py separately from the new API in module_utils/common/sys_info.py and module_utils/common/_utils.py
This commit is contained in:
parent
79dc9a75c3
commit
5844c8c7f0
7 changed files with 284 additions and 47 deletions
46
test/units/module_utils/common/test_utils.py
Normal file
46
test/units/module_utils/common/test_utils.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (c) 2018 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.common.sys_info import get_all_subclasses
|
||||
|
||||
|
||||
#
|
||||
# Tests for get_all_subclasses
|
||||
#
|
||||
|
||||
class TestGetAllSubclasses:
|
||||
class Base:
|
||||
pass
|
||||
|
||||
class BranchI(Base):
|
||||
pass
|
||||
|
||||
class BranchII(Base):
|
||||
pass
|
||||
|
||||
class BranchIA(BranchI):
|
||||
pass
|
||||
|
||||
class BranchIB(BranchI):
|
||||
pass
|
||||
|
||||
class BranchIIA(BranchII):
|
||||
pass
|
||||
|
||||
class BranchIIB(BranchII):
|
||||
pass
|
||||
|
||||
def test_bottom_level(self):
|
||||
assert get_all_subclasses(self.BranchIIB) == set()
|
||||
|
||||
def test_one_inheritance(self):
|
||||
assert set(get_all_subclasses(self.BranchII)) == set([self.BranchIIA, self.BranchIIB])
|
||||
|
||||
def test_toplevel(self):
|
||||
assert set(get_all_subclasses(self.Base)) == set([self.BranchI, self.BranchII,
|
||||
self.BranchIA, self.BranchIB,
|
||||
self.BranchIIA, self.BranchIIB])
|
Loading…
Add table
Add a link
Reference in a new issue