<commit_before>
# (c) 2018 <NAME> <<EMAIL>>
# Copyright (c) 2018 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#  or
# Apache License v2.0 (see http://www.apache.org/licenses/LICENSE-2.0)
#
# Dual licensed so any test cases could potentially be included by the upstream project
# that module_utils/distro.py is from (https://github.com/nir0s/distro)


# Note that nir0s/distro has many more tests in it's test suite. The tests here are
# primarily for testing the vendoring.

import pytest

from ansible.module_utils import distro


# Generic test case with minimal assertions about specific returned values.
class TestDistro():
    # should run on any platform without errors, even if non-linux without any
    # useful info to return
    def test_info(self):
        info = distro.info()
        assert isinstance(info, dict), \
            'distro.info() returned %s (%s) which is not a dist' % (info, type(info))

    def test_linux_distribution(self):
        linux_dist = distro.linux_distribution()
        assert isinstance(linux_dist, tuple), \
            'linux_distrution() returned %s (%s) which is not a tuple' % (linux_dist, type(linux_dist))<commit_msg>WIP: add tests to compare to platform.*dist<commit_after>
# (c) 2018 <NAME> <<EMAIL>>
# Copyright (c) 2018 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#  or
# Apache License v2.0 (see http://www.apache.org/licenses/LICENSE-2.0)
#
# Dual licensed so any test cases could potentially be included by the upstream project
# that module_utils/distro.py is from (https://github.com/nir0s/distro)


# Note that nir0s/distro has many more tests in it's test suite. The tests here are
# primarily for testing the vendoring.

import platform
import pytest

from ansible.module_utils import distro


# Generic test case with minimal assertions about specific returned values.
class TestDistro():
    # should run on any platform without errors, even if non-linux without any
    # useful info to return
    def test_info(self):
        info = distro.info()
        assert isinstance(info, dict), \
            'distro.info() returned %s (%s) which is not a dist' % (info, type(info))

    def test_linux_distribution(self):
        linux_dist = distro.linux_distribution()
        assert isinstance(linux_dist, tuple), \
            'linux_distrution() returned %s (%s) which is not a tuple' % (linux_dist, type(linux_dist))


# compare distro.py results with platform.linux_distribution() if we have it
# Depending on the platform, it is okay if these don't match exactly as long as the
# distro result is what we expect and special cased.
class TestDistroCompat():
    '''Verify that distro.linux_distribution matches plain platform.linux_distribution'''

    _platform_supported_dists = platform._supported_dists

    def test_linux_distribution(self):
        platform_linux_dist = platform.linux_distribution(supported_dists=self._platform_supported_dists)
        distro_linux_dist = distro.linux_distribution()

        assert isinstance(distro_linux_dist, type(platform_linux_dist)), \
            'linux_distrution() returned type (%s) which is different from platform.linux_distribution type (%s)' % \
            (type(distro_linux_dist), type(platform_linux_dist))

        # TODO: add the cases where we expect them to differ

        # The third item in the tuple is different.
        assert distro_linux_dist[0] == platform_linux_dist[0]
        assert distro_linux_dist[1] == platform_linux_dist[1]

        # FIXME: This fails on at least Fedora
        # platform returns the 'id', while distro returns the 'codename'
        assert distro_linux_dist[2] == platform_linux_dist[2]
{'fraction_non_alphanumeric': 0.0919661733615222, 'fraction_numerical': 0.011099365750528542, 'mean_word_length': 3.6728395061728394, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5381072', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1085, 'n_words': 384}