Ejemplo n.º 1
0
    def test_module_utils_basic_load_platform_subclass(self):
        class LinuxTest:
            pass

        class Foo(LinuxTest):
            platform = "Linux"
            distribution = None

        class Bar(LinuxTest):
            platform = "Linux"
            distribution = "Bar"

        from ansible.module_utils.basic import load_platform_subclass

        # match just the platform class, not a specific distribution
        with patch('ansible.module_utils.basic.get_platform', return_value="Linux"):
            with patch('ansible.module_utils.basic.get_distribution', return_value=None):
                self.assertIs(type(load_platform_subclass(LinuxTest)), Foo)

        # match both the distribution and platform class
        with patch('ansible.module_utils.basic.get_platform', return_value="Linux"):
            with patch('ansible.module_utils.basic.get_distribution', return_value="Bar"):
                self.assertIs(type(load_platform_subclass(LinuxTest)), Bar)

        # if neither match, the fallback should be the top-level class
        with patch('ansible.module_utils.basic.get_platform', return_value="Foo"):
            with patch('ansible.module_utils.basic.get_distribution', return_value=None):
                self.assertIs(type(load_platform_subclass(LinuxTest)), LinuxTest)
Ejemplo n.º 2
0
    def test_module_utils_basic_load_platform_subclass(self):
        class LinuxTest:
            pass

        class Foo(LinuxTest):
            platform = "Linux"
            distribution = None

        class Bar(LinuxTest):
            platform = "Linux"
            distribution = "Bar"

        from ansible.module_utils.basic import load_platform_subclass

        # match just the platform class, not a specific distribution
        with patch('ansible.module_utils.basic.get_platform',
                   return_value="Linux"):
            with patch('ansible.module_utils.basic.get_distribution',
                       return_value=None):
                self.assertIs(type(load_platform_subclass(LinuxTest)), Foo)

        # match both the distribution and platform class
        with patch('ansible.module_utils.basic.get_platform',
                   return_value="Linux"):
            with patch('ansible.module_utils.basic.get_distribution',
                       return_value="Bar"):
                self.assertIs(type(load_platform_subclass(LinuxTest)), Bar)

        # if neither match, the fallback should be the top-level class
        with patch('ansible.module_utils.basic.get_platform',
                   return_value="Foo"):
            with patch('ansible.module_utils.basic.get_distribution',
                       return_value=None):
                self.assertIs(type(load_platform_subclass(LinuxTest)),
                              LinuxTest)
Ejemplo n.º 3
0
 def test_not_linux(self):
     # if neither match, the fallback should be the top-level class
     with patch('platform.system', return_value="Foo"):
         with patch('ansible.module_utils.common.sys_info.get_distribution',
                    return_value=None):
             assert isinstance(load_platform_subclass(self.LinuxTest),
                               self.LinuxTest)
Ejemplo n.º 4
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(Hostname, args, kwargs)
Ejemplo n.º 5
0
 def test_get_distribution_found(self):
     # match both the distribution and platform class
     with patch('ansible.module_utils.common.sys_info.get_distribution',
                return_value="Bar"):
         assert isinstance(load_platform_subclass(self.LinuxTest), self.Bar)
Ejemplo n.º 6
0
 def test_get_distribution_none(self):
     # match just the platform class, not a specific distribution
     with patch('ansible.module_utils.common.sys_info.get_distribution',
                return_value=None):
         assert isinstance(load_platform_subclass(self.LinuxTest), self.Foo)
Ejemplo n.º 7
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(TCPConnectionInfo, args, kwargs)
Ejemplo n.º 8
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(Group, args, kwargs)
Ejemplo n.º 9
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(TCPConnectionInfo, args, kwargs)
Ejemplo n.º 10
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(Hostname, args, kwargs)
Ejemplo n.º 11
0
 def __new__(cls, *args, **kwargs):
     return load_platform_subclass(Group, args, kwargs)