<commit_before># -*- coding: utf-8 -*-
'''
    :codeauthor: :email:`<NAME> <<EMAIL>>`
'''

# Import python libs
from __future__ import absolute_import
import os

# Import Salt Testing libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
    NO_MOCK,
    NO_MOCK_REASON,
    MagicMock,
    patch
)

# Import Salt Libs
import salt.states.archive as archive
from salt.ext.six.moves import zip  # pylint: disable=import-error,redefined-builtin
import salt.utils


def _isfile_side_effect(path):
    '''
    MagicMock side_effect for os.path.isfile(). We don't want to use dict.get
    here because we want the test to fail if there's a path we haven't
    accounted for, so that we can add it.

    NOTE: This may fall over on some platforms if /usr/bin/tar does not exist.
    If so, just add an entry in the dictionary for the path being used for tar.
    '''
    return {
        '/tmp/foo.tar.gz': True,
        'c:\\tmp\\foo.tar.gz': True,
        '/tmp/out': False,
        '\\tmp\\out': False,
        '/usr/bin/tar': True,
        '/bin/tar': True,
        '/tmp/test_extracted_tar': False,
        'c:\\tmp\\test_extracted_tar': False,
    }[path]


@skipIf(NO_MOCK, NO_MOCK_REASON)
class ArchiveTestCase(TestCase, LoaderModuleMockMixin):

    def setup_loader_modules(self):
        return {
            archive: {
                '__grains__': {'os': 'FooOS!'},
                '__opts__': {'cachedir': '/tmp',
                             'test': False,
                             'hash_type': 'sha256'},
                '__env__': 'test'
            }
        }

    def test_extracted_tar(self):
        '''
        archive.extracted tar options
        '''

        if salt.utils.is_windows():
            source = 'c:\\tmp\\foo.tar.gz'
            tmp_dir = 'c:\\tmp\\test_extracted_tar'
        else:
            source = '/tmp/foo.tar.gz'
            tmp_dir = '/tmp/test_extracted_tar'
        test_tar_opts = [
            '--no-anchored foo',
            'v -p --opt',
            '-v -p',
            '--long-opt -z',
            'z -v -weird-long-opt arg',<commit_msg>fix test_archive test for mac on 2017.7 branch<commit_after># -*- coding: utf-8 -*-
'''
    :codeauthor: :email:`<NAME> <<EMAIL>>`
'''

# Import python libs
from __future__ import absolute_import
import os

# Import Salt Testing libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
    NO_MOCK,
    NO_MOCK_REASON,
    MagicMock,
    patch
)

# Import Salt Libs
import salt.states.archive as archive
from salt.ext.six.moves import zip  # pylint: disable=import-error,redefined-builtin
import salt.utils


def _isfile_side_effect(path):
    '''
    MagicMock side_effect for os.path.isfile(). We don't want to use dict.get
    here because we want the test to fail if there's a path we haven't
    accounted for, so that we can add it.

    NOTE: This may fall over on some platforms if /usr/bin/tar does not exist.
    If so, just add an entry in the dictionary for the path being used for tar.
    '''
    return {
        '/tmp/foo.tar.gz': True,
        'c:\\tmp\\foo.tar.gz': True,
        '/private/tmp/foo.tar.gz': True,
        '/tmp/out': False,
        '\\tmp\\out': False,
        '/usr/bin/tar': True,
        '/bin/tar': True,
        '/tmp/test_extracted_tar': False,
        'c:\\tmp\\test_extracted_tar': False,
        '/private/tmp/test_extracted_tar': False,
    }[path]


@skipIf(NO_MOCK, NO_MOCK_REASON)
class ArchiveTestCase(TestCase, LoaderModuleMockMixin):

    def setup_loader_modules(self):
        return {
            archive: {
                '__grains__': {'os': 'FooOS!'},
                '__opts__': {'cachedir': '/tmp',
                             'test': False,
                             'hash_type': 'sha256'},
                '__env__': 'test'
            }
        }

    def test_extracted_tar(self):
        '''
        archive.extracted tar options
        '''

        if salt.utils.is_windows():
            source = 'c:\\tmp\\foo.tar.gz'
            tmp_dir = 'c:\\tmp\\test_extracted_tar'
        elif salt.utils.is_darwin():
            source = '/private/tmp/foo.tar.gz'
            tmp_dir = '/private/tmp/test_extracted_tar'
        else:
            source = '/tmp/foo.tar.gz'
            tmp_dir = '/tmp/test_extracted_tar'
        test_tar_opts = [
            '--no-anchored foo',
            'v -p --opt',
            '-v -p',
            '--long-opt -z',
            'z -v -weird-long-opt arg',
{'fraction_non_alphanumeric': 0.1303594629709831, 'fraction_numerical': 0.00281507145950628, 'mean_word_length': 1.9476707083599234, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4020608', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1461, 'n_words': 380}