<commit_before># -*- coding: utf-8 -*-
'''
Unit tests for the Snapper module

:codeauthor:    <NAME>. <<EMAIL>>
:codeauthor:    <NAME> <<EMAIL>>
'''

# Import Python libs
from __future__ import absolute_import
import sys

# 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,
    mock_open,
)

# Import Salt libs
import salt.ext.six as six
from salt.exceptions import CommandExecutionError
import salt.modules.snapper as snapper

DBUS_RET = {
    'ListSnapshots': [
        [42, 1, 0, 1457006571,
         0, 'Some description', '',
         {'userdata1': 'userval1', 'salt_jid': '20160607130930720112'}],
        [43, 2, 42, 1457006572,
         0, 'Blah Blah', '',
         {'userdata2': 'userval2', 'salt_jid': '20160607130930720112'}]
    ],
    'ListConfigs': [
        [u'root', u'/', {
            u'SUBVOLUME': u'/', u'NUMBER_MIN_AGE': u'1800',
            u'TIMELINE_LIMIT_YEARLY': u'4-10', u'NUMBER_LIMIT_IMPORTANT': u'10',
            u'FSTYPE': u'btrfs', u'TIMELINE_LIMIT_MONTHLY': u'4-10',
            u'ALLOW_GROUPS': u'', u'EMPTY_PRE_POST_MIN_AGE': u'1800',
            u'EMPTY_PRE_POST_CLEANUP': u'yes', u'BACKGROUND_COMPARISON': u'yes',
            u'TIMELINE_LIMIT_HOURLY': u'4-10', u'ALLOW_USERS': u'',
            u'TIMELINE_LIMIT_WEEKLY': u'0', u'TIMELINE_CREATE': u'no',
            u'NUMBER_CLEANUP': u'yes', u'TIMELINE_CLEANUP': u'yes',
            u'SPACE_LIMIT': u'0.5', u'NUMBER_LIMIT': u'10',
            u'TIMELINE_MIN_AGE': u'1800', u'TIMELINE_LIMIT_DAILY': u'4-10',
            u'SYNC_ACL': u'no', u'QGROUP': u'1/0'}
        ]
    ],
    'GetFiles': [
        ['/root/.viminfo', 8],
        ['/tmp/foo', 52],
        ['/tmp/foo2', 1],
        ['/tmp/foo3', 2],
        ['/var/log/snapper.log', 8],
        ['/var/cache/salt/minion/extmods/modules/snapper.py', 8],
        ['/var/cache/salt/minion/extmods/modules/snapper.pyc', 8],
    ],
}

FILE_CONTENT = {
    '/tmp/foo': {
        "pre": "dummy text",
        "post": "another foobar"
    },
    '/tmp/foo2': {
        "post": "another foobar"
    }
}

MODULE_RET = {
    'SNAPSHOTS': [
        {
            'userdata': {'userdata1': 'userval1', 'salt_jid': '20160607130930720112'},
            'description': 'Some description', 'timestamp': 1457006571,
            'cleanup': '', 'user': 'root', 'type': 'pre', 'id': 42
        },
        {
            'pre': 42,
            'userdata': {'userdata2': 'userval2', 'salt_jid': '20160607130930720112'},
            'description': 'Blah Blah', 'timestamp': 1457006572,
            'cleanup': '', 'user': 'root', 'type': 'post', 'id': 43
        }
    ],
    'LISTCONFIGS': {
        u'root': {
            u'SUBVOLUME': u'/', u'NUMBER_MIN_AGE': u'1800',
            u'TIMELINE_LIMIT_YEARLY': u'4-10', u'NUMBER_LIMIT_IMPORTANT': u'10',
            u'FSTYPE': u'btrfs', u'TIMELINE_LIMIT_MONTHLY': u'4-10',
            u'ALLOW_GROUPS': u'', u'EMPTY_PRE_POST_MIN_AGE': u'1800',
            u'EMPTY_PRE_POST_CLEANUP': u'yes', u'BACKGROUND_COMPARISON': u'yes',
            u'TIMELINE_LIMIT_HOURLY': u'4-10', u'ALLOW_USERS': u'',
            u'TIMELINE_LIMIT_WEEKLY': u'0', u'TIMELINE_CREATE': u'no',
            u'NUMBER_CLEANUP': u'yes', u'TIMELINE_CLEANUP': u'yes',
            u'SPACE_LIMIT': u'0.5', u'NUMBER_LIMIT': u'10',
            u'TIMELINE_MIN_AGE': u'1800', u'TIMELINE_LIMIT_DAILY': u'4-10',
            u'SYNC_ACL': u'no', u'QGROUP': u'1/0'
        }
    },
    'GETFILES': {
        '/root/.viminfo': {'status': ['modified']},
        '/tmp/foo': {'status': ['type changed', 'permission changed', 'owner changed']},
        '/tmp/foo2': {'status': ['created']},
        '/tmp/foo3': {'status': ['deleted']},
        '/var/log/snapper.log': {'status': ['modified']},
        '/var/cache/salt/minion/extmods/modules/snapper.py': {'status': ['modified']},
        '/var/cache/salt/minion/extmods/modules/snapper.pyc': {'status': ['modified']},
    },
    'DIFF': {
        '/tmp/foo': {
            'comment': 'text file changed',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo\n"
                    "+++ /tmp/foo\n"
                    "@@ -1 +1 @@\n"
                    "-dummy text"
                    "+another foobar"
        },
        '/tmp/foo2': {
            'comment': 'text file created',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo2\n"
                    "+++ /tmp/foo2\n"
                    "@@ -0,0 +1 @@\n"
                    "+another foobar",
        },
        '/tmp/foo26': {
            'comment': 'text file created',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo2 \n"
                    "+++ /tmp/foo2 \n"
                    "@@ -1,0 +1,1 @@\n"
                    "+another foobar",
        },
        '/tmp/foo3': {
            'comment': 'binary file changed',
            'old_sha256_digest': 'e61f8b762d83f3b4aeb3689564b0ffbe54fa731a69a1e208dc9440ce0f69d19b',
            'new_sha256_digest': 'f18f971f1517449208a66589085ddd3723f7f6cefb56c141e3d97ae49e1d87fa',
        }
    }
}


@skipIf(NO_MOCK, NO_MOCK_REASON)
class SnapperTestCase(TestCase, LoaderModuleMockMixin):
<commit_msg>Skip snapper tests on Windows<commit_after># -*- coding: utf-8 -*-
'''
Unit tests for the Snapper module

:codeauthor:    <NAME>. <<EMAIL>>
:codeauthor:    <NAME> <<EMAIL>>
'''

# Import Python libs
from __future__ import absolute_import
import sys

# 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,
    mock_open,
)

# Import Salt libs
import salt.ext.six as six
from salt.exceptions import CommandExecutionError
import salt.modules.snapper as snapper

DBUS_RET = {
    'ListSnapshots': [
        [42, 1, 0, 1457006571,
         0, 'Some description', '',
         {'userdata1': 'userval1', 'salt_jid': '20160607130930720112'}],
        [43, 2, 42, 1457006572,
         0, 'Blah Blah', '',
         {'userdata2': 'userval2', 'salt_jid': '20160607130930720112'}]
    ],
    'ListConfigs': [
        [u'root', u'/', {
            u'SUBVOLUME': u'/', u'NUMBER_MIN_AGE': u'1800',
            u'TIMELINE_LIMIT_YEARLY': u'4-10', u'NUMBER_LIMIT_IMPORTANT': u'10',
            u'FSTYPE': u'btrfs', u'TIMELINE_LIMIT_MONTHLY': u'4-10',
            u'ALLOW_GROUPS': u'', u'EMPTY_PRE_POST_MIN_AGE': u'1800',
            u'EMPTY_PRE_POST_CLEANUP': u'yes', u'BACKGROUND_COMPARISON': u'yes',
            u'TIMELINE_LIMIT_HOURLY': u'4-10', u'ALLOW_USERS': u'',
            u'TIMELINE_LIMIT_WEEKLY': u'0', u'TIMELINE_CREATE': u'no',
            u'NUMBER_CLEANUP': u'yes', u'TIMELINE_CLEANUP': u'yes',
            u'SPACE_LIMIT': u'0.5', u'NUMBER_LIMIT': u'10',
            u'TIMELINE_MIN_AGE': u'1800', u'TIMELINE_LIMIT_DAILY': u'4-10',
            u'SYNC_ACL': u'no', u'QGROUP': u'1/0'}
        ]
    ],
    'GetFiles': [
        ['/root/.viminfo', 8],
        ['/tmp/foo', 52],
        ['/tmp/foo2', 1],
        ['/tmp/foo3', 2],
        ['/var/log/snapper.log', 8],
        ['/var/cache/salt/minion/extmods/modules/snapper.py', 8],
        ['/var/cache/salt/minion/extmods/modules/snapper.pyc', 8],
    ],
}

FILE_CONTENT = {
    '/tmp/foo': {
        "pre": "dummy text",
        "post": "another foobar"
    },
    '/tmp/foo2': {
        "post": "another foobar"
    }
}

MODULE_RET = {
    'SNAPSHOTS': [
        {
            'userdata': {'userdata1': 'userval1', 'salt_jid': '20160607130930720112'},
            'description': 'Some description', 'timestamp': 1457006571,
            'cleanup': '', 'user': 'root', 'type': 'pre', 'id': 42
        },
        {
            'pre': 42,
            'userdata': {'userdata2': 'userval2', 'salt_jid': '20160607130930720112'},
            'description': 'Blah Blah', 'timestamp': 1457006572,
            'cleanup': '', 'user': 'root', 'type': 'post', 'id': 43
        }
    ],
    'LISTCONFIGS': {
        u'root': {
            u'SUBVOLUME': u'/', u'NUMBER_MIN_AGE': u'1800',
            u'TIMELINE_LIMIT_YEARLY': u'4-10', u'NUMBER_LIMIT_IMPORTANT': u'10',
            u'FSTYPE': u'btrfs', u'TIMELINE_LIMIT_MONTHLY': u'4-10',
            u'ALLOW_GROUPS': u'', u'EMPTY_PRE_POST_MIN_AGE': u'1800',
            u'EMPTY_PRE_POST_CLEANUP': u'yes', u'BACKGROUND_COMPARISON': u'yes',
            u'TIMELINE_LIMIT_HOURLY': u'4-10', u'ALLOW_USERS': u'',
            u'TIMELINE_LIMIT_WEEKLY': u'0', u'TIMELINE_CREATE': u'no',
            u'NUMBER_CLEANUP': u'yes', u'TIMELINE_CLEANUP': u'yes',
            u'SPACE_LIMIT': u'0.5', u'NUMBER_LIMIT': u'10',
            u'TIMELINE_MIN_AGE': u'1800', u'TIMELINE_LIMIT_DAILY': u'4-10',
            u'SYNC_ACL': u'no', u'QGROUP': u'1/0'
        }
    },
    'GETFILES': {
        '/root/.viminfo': {'status': ['modified']},
        '/tmp/foo': {'status': ['type changed', 'permission changed', 'owner changed']},
        '/tmp/foo2': {'status': ['created']},
        '/tmp/foo3': {'status': ['deleted']},
        '/var/log/snapper.log': {'status': ['modified']},
        '/var/cache/salt/minion/extmods/modules/snapper.py': {'status': ['modified']},
        '/var/cache/salt/minion/extmods/modules/snapper.pyc': {'status': ['modified']},
    },
    'DIFF': {
        '/tmp/foo': {
            'comment': 'text file changed',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo\n"
                    "+++ /tmp/foo\n"
                    "@@ -1 +1 @@\n"
                    "-dummy text"
                    "+another foobar"
        },
        '/tmp/foo2': {
            'comment': 'text file created',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo2\n"
                    "+++ /tmp/foo2\n"
                    "@@ -0,0 +1 @@\n"
                    "+another foobar",
        },
        '/tmp/foo26': {
            'comment': 'text file created',
            'diff': "--- /.snapshots/55/snapshot/tmp/foo2 \n"
                    "+++ /tmp/foo2 \n"
                    "@@ -1,0 +1,1 @@\n"
                    "+another foobar",
        },
        '/tmp/foo3': {
            'comment': 'binary file changed',
            'old_sha256_digest': 'e61f8b762d83f3b4aeb3689564b0ffbe54fa731a69a1e208dc9440ce0f69d19b',
            'new_sha256_digest': 'f18f971f1517449208a66589085ddd3723f7f6cefb56c141e3d97ae49e1d87fa',
        }
    }
}


@skipIf(sys.platform.startswith('win'), 'Snapper not available on Windows')
@skipIf(NO_MOCK, NO_MOCK_REASON)
class SnapperTestCase(TestCase, LoaderModuleMockMixin):

{'fraction_non_alphanumeric': 0.18454288407163053, 'fraction_numerical': 0.06295947219604148, 'mean_word_length': 2.263918794217164, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 15, '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': '651257', 'n_tokens_mistral': 4330, 'n_tokens_neox': 3992, 'n_words': 664}