<commit_before># Copyright Hybrid Logic Ltd.  See LICENSE file for details.

"""
Functional tests for ZFS filesystem implementation.

Further coverage is provided in
:module:`flocker.test.test_filesystems_zfs`.
"""

import os
import tempfile
import subprocess
import uuid
from twisted.internet import reactor

from ..test.filesystemtests import makeIFilesystemSnapshotsTests
from ..filesystems.zfs import ZFSSnapshots, Filesystem


def createZFSPool(testCase):
    """
    Create a new ZFS pool, then delete it after the test is over.

    :param testCase: A ``unittest.TestCase``.

    :return: A :class:`Filesystem` instance.
    """
    poolName = "testpool_%s" % (uuid.uuid4(),)
    poolPath = tempfile.mktemp()
    mountPath = tempfile.mktemp()
    subprocess.check_call([b"dd", b"if=/dev/zero", b"of=%s" % (poolPath),
                           b"count=200000"])
    testCase.addCleanup(os.remove, poolPath)
    subprocess.check_call([b"zpool", b"create", b"-m", mountPath, poolName,
                           poolPath])
    testCase.addCleanup(subprocess.check_call, [b"zpool", b"destroy", poolName])
    return Filesystem(poolName)



IFilesystemSnapshotsTests = makeIFilesystemSnapshotsTests(
    lambda testCase: ZFSSnapshots(reactor, createZFSPool(testCase)))<commit_msg>Skip functional tests if not root.<commit_after># Copyright Hybrid Logic Ltd.  See LICENSE file for details.

"""
Functional tests for ZFS filesystem implementation.

Further coverage is provided in
:module:`flocker.test.test_filesystems_zfs`.
"""

import os
import tempfile
import subprocess
import uuid

from twisted.internet import reactor
from twisted.trial.unittest import SkipTest

from ..test.filesystemtests import makeIFilesystemSnapshotsTests
from ..filesystems.zfs import ZFSSnapshots, Filesystem


def createZFSPool(testCase):
    """
    Create a new ZFS pool, then delete it after the test is over.

    :param testCase: A ``unittest.TestCase``.

    :return: A :class:`Filesystem` instance.
    """
    if os.getuid() != 0:
        raise SkipTest("Functional tests must run as root.")

    poolName = "testpool_%s" % (uuid.uuid4(),)
    poolPath = tempfile.mktemp()
    mountPath = tempfile.mktemp()
    subprocess.check_call([b"dd", b"if=/dev/zero", b"of=%s" % (poolPath),
                           b"count=200000"])
    testCase.addCleanup(os.remove, poolPath)
    subprocess.check_call([b"zpool", b"create", b"-m", mountPath, poolName,
                           poolPath])
    testCase.addCleanup(subprocess.check_call, [b"zpool", b"destroy", poolName])
    return Filesystem(poolName)



IFilesystemSnapshotsTests = makeIFilesystemSnapshotsTests(
    lambda testCase: ZFSSnapshots(reactor, createZFSPool(testCase)))
{'fraction_non_alphanumeric': 0.11107024641412284, 'fraction_numerical': 0.005516734093416698, 'mean_word_length': 3.8920863309352516, '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': '965439', 'n_tokens_mistral': 888, 'n_tokens_neox': 840, 'n_words': 214}