<commit_before># -*- coding: utf-8 -*-

# Import Python libs
from __future__ import absolute_import

# Import salt module
from salt.modules import mac_pkgutil
import salt.utils.mac_utils

# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch


mac_pkgutil.__salt__ = {}


@skipIf(NO_MOCK, NO_MOCK_REASON)
class MacPkgutilTestCase(TestCase):
    def test_list(self):
        # Given
        r_output = "com.apple.pkg.iTunes"

        # When
        mock_cmd = MagicMock(return_value=r_output)
        with patch.object(salt.utils.mac_utils,
                          'execute_return_result',
                          mock_cmd):
            output = mac_pkgutil.list_()

        # Then
        self.assertEqual(
            output,
            [r_output]
        )

        mock_cmd.assert_called_with(
            ['pkgutil', '--pkgs'],
            python_shell=False
        )

    def test_list_installed_output(self):
        # Given
        r_output = "com.apple.pkg.iTunes"

        # When
        mock_cmd = MagicMock(return_value=r_output)
        with patch.dict(mac_pkgutil.__salt__, {'cmd.run_stdout': mock_cmd}):
            output = mac_pkgutil.list_()

        # Then
        self.assertEqual(output, r_output)

    def test_is_installed(self):
        # Given
        r_output = "com.apple.pkg.iTunes"

        # When
        mock_cmd = MagicMock(return_value=r_output)
        with patch.dict(mac_pkgutil.__salt__, {'cmd.run_stdout': mock_cmd}):
            ret = mac_pkgutil.is_installed("com.apple.pkg.iTunes")

        # Then
        self.assertTrue(ret)

        # When
        with patch.dict(mac_pkgutil.__salt__, {'cmd.run_stdout': mock_cmd}):
            ret = mac_pkgutil.is_installed("com.apple.pkg.Safari")

        # Then
        self.assertFalse(ret)

    def test_install(self):
        # Given
        source = "/foo/bar/fubar.pkg"
        package_id = "com.foo.fubar.pkg"

        # When
        mock_cmd = MagicMock(return_value=True)
        with patch("salt.modules.mac_pkgutil.is_installed",
                   return_value=False) as is_installed:
            with patch("salt.modules.mac_pkgutil._install_from_path",
                       return_value=True) as _install_from_path:
                ret = mac_pkgutil.install(source, package_id)

        # Then
        _install_from_path.assert_called_with(source)

    def test_install_already_there(self):
        # Given
        source = "/foo/bar/fubar.pkg"
        package_id = "com.foo.fubar.pkg"

        # When
        mock_cmd = MagicMock(return_value=True)
        with patch("salt.modules.mac_pkgutil.is_installed",
                   return_value=True) as is_installed:
            with patch("salt.modules.mac_pkgutil._install_from_path",
                   return_value=True) as _install_from_path:
                ret = mac_pkgutil.install(source, package_id)

        # Then
        self.assertEqual(_install_from_path.called, 0)<commit_msg>Remove unit tests without logic<commit_after># -*- coding: utf-8 -*-

# Import Python libs
from __future__ import absolute_import

# Import salt module
from salt.modules import mac_pkgutil

# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch


mac_pkgutil.__salt__ = {}


@skipIf(NO_MOCK, NO_MOCK_REASON)
class MacPkgutilTestCase(TestCase):

    def test_install(self):
        # Given
        source = "/foo/bar/fubar.pkg"
        package_id = "com.foo.fubar.pkg"

        # When
        with patch("salt.modules.mac_pkgutil.is_installed",
                   return_value=False):
            with patch("salt.modules.mac_pkgutil._install_from_path",
                       return_value=True) as _install_from_path:
                mac_pkgutil.install(source, package_id)

        # Then
        _install_from_path.assert_called_with(source)

    def test_install_already_there(self):
        # Given
        source = "/foo/bar/fubar.pkg"
        package_id = "com.foo.fubar.pkg"

        # When
        with patch("salt.modules.mac_pkgutil.is_installed",
                   return_value=True):
            with patch("salt.modules.mac_pkgutil._install_from_path",
                       return_value=True) as _install_from_path:
                mac_pkgutil.install(source, package_id)

        # Then
        self.assertEqual(_install_from_path.called, 0)
{'fraction_non_alphanumeric': 0.09307019511101143, 'fraction_numerical': 0.0008970621215519175, 'mean_word_length': 2.260233918128655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5816746', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1357, 'n_words': 236}