<commit_before>import six
import unittest

import gi
gi.require_version("BlockDev", "2.0")

from gi.repository import BlockDev as blockdev

try:
    from unittest.mock import patch, Mock
except ImportError:
    from mock import patch, Mock

import blivet

from blivet.errors import BTRFSValueError
from blivet.errors import DeviceError

from blivet.devices import BTRFSSnapShotDevice
from blivet.devices import BTRFSSubVolumeDevice
from blivet.devices import BTRFSVolumeDevice
from blivet.devices import DiskDevice
from blivet.devices import MDBiosRaidArrayDevice
from blivet.devices import MDContainerDevice
from blivet.devices import MDRaidArrayDevice
from blivet.devices import OpticalDevice
from blivet.devices import StorageDevice
from blivet.devices import ParentList
from blivet.devices import LVMVolumeGroupDevice, LVMLogicalVolumeDevice
from blivet.devices.lvm import LVMCacheRequest, LVMCache
from blivet.devicelibs import btrfs
from blivet.devicelibs import mdraid
from blivet.size import Size

from blivet.formats import get_format

BTRFS_MIN_MEMBER_SIZE = get_format("btrfs").min_size

# pylint: disable=unnecessary-lambda


def xform(func):
    """ Simple wrapper function that transforms a function that takes
        a precalculated value and a message to a function that takes
        a device and an attribute name, evaluates the attribute, and
        passes the value and the attribute name as the message to the
        original function.

        :param func: The function to be transformed.
        :type func: (object * str) -> None
        :returns: a function that gets the attribute and passes it to func
        :rtype: (object * str) -> None
    """
    return lambda d, a: func(getattr(d, a), a)


class DeviceStateTestCase(unittest.TestCase):

    """A class which implements a simple method of checking the state
       of a device object.
    """

    def __init__(self, methodName='run_test'):
        self._state_functions = {
            "current_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "direct": xform(self.assertTrue),
            "exists": xform(self.assertFalse),
            "format": xform(self.assertIsNotNone),
            "format_args": xform(lambda x, m: self.assertEqual(x, [], m)),
            "is_disk": xform(self.assertFalse),
            "isleaf": xform(self.assertTrue),
            "major": xform(lambda x, m: self.assertEqual(x, 0, m)),
            "max_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "media_present": xform(self.assertTrue),
            "minor": xform(lambda x, m: self.assertEqual(x, 0, m)),
            "parents": xform(lambda x, m: self.assertEqual(len(x), 0, m) and
                             self.assertIsInstance(x, ParentList, m)),
            "partitionable": xform(self.assertFalse),
            "path": xform(lambda x, m: six.assertRegex(self, x, "^/dev", m)),
            "raw_device": xform(self.assertIsNotNone),
            "resizable": xform(self.assertFalse),
            "size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "status": xform(self.assertFalse),
            "sysfs_path": xform(lambda x, m: self.assertEqual(x, "", m)),
            "target_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "type": xform(lambda x, m: self.assertEqual(x, "mdarray", m)),
            "uuid": xform(self.assertIsNone)
        }
        super(DeviceStateTestCase, self).__init__(methodName=methodName)

    def state_check(self, device, **kwargs):
        """Checks the current state of a device by means of its
           fields or properties.

           Every kwarg should be a key which is a field or property
           of a Device and a value which is a function of
           two parameters and should call the appropriate assert* functions.
           These values override those in the state_functions dict.

           If the value is None, then the test starts the debugger instead.
        """
        self.longMessage = True
        for k, v in self._state_functions.items():
            if k in kwargs:
                test_func = kwargs[k]
                if test_func is None:
                    import pdb
                    pdb.set_trace()
                    getattr(device, k)
                else:<commit_msg>pylint: Remove pdb breakpoint in device_properties_test<commit_after>import six
import unittest

import gi
gi.require_version("BlockDev", "2.0")

from gi.repository import BlockDev as blockdev

try:
    from unittest.mock import patch, Mock
except ImportError:
    from mock import patch, Mock

import blivet

from blivet.errors import BTRFSValueError
from blivet.errors import DeviceError

from blivet.devices import BTRFSSnapShotDevice
from blivet.devices import BTRFSSubVolumeDevice
from blivet.devices import BTRFSVolumeDevice
from blivet.devices import DiskDevice
from blivet.devices import MDBiosRaidArrayDevice
from blivet.devices import MDContainerDevice
from blivet.devices import MDRaidArrayDevice
from blivet.devices import OpticalDevice
from blivet.devices import StorageDevice
from blivet.devices import ParentList
from blivet.devices import LVMVolumeGroupDevice, LVMLogicalVolumeDevice
from blivet.devices.lvm import LVMCacheRequest, LVMCache
from blivet.devicelibs import btrfs
from blivet.devicelibs import mdraid
from blivet.size import Size

from blivet.formats import get_format

BTRFS_MIN_MEMBER_SIZE = get_format("btrfs").min_size

# pylint: disable=unnecessary-lambda


def xform(func):
    """ Simple wrapper function that transforms a function that takes
        a precalculated value and a message to a function that takes
        a device and an attribute name, evaluates the attribute, and
        passes the value and the attribute name as the message to the
        original function.

        :param func: The function to be transformed.
        :type func: (object * str) -> None
        :returns: a function that gets the attribute and passes it to func
        :rtype: (object * str) -> None
    """
    return lambda d, a: func(getattr(d, a), a)


class DeviceStateTestCase(unittest.TestCase):

    """A class which implements a simple method of checking the state
       of a device object.
    """

    def __init__(self, methodName='run_test'):
        self._state_functions = {
            "current_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "direct": xform(self.assertTrue),
            "exists": xform(self.assertFalse),
            "format": xform(self.assertIsNotNone),
            "format_args": xform(lambda x, m: self.assertEqual(x, [], m)),
            "is_disk": xform(self.assertFalse),
            "isleaf": xform(self.assertTrue),
            "major": xform(lambda x, m: self.assertEqual(x, 0, m)),
            "max_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "media_present": xform(self.assertTrue),
            "minor": xform(lambda x, m: self.assertEqual(x, 0, m)),
            "parents": xform(lambda x, m: self.assertEqual(len(x), 0, m) and
                             self.assertIsInstance(x, ParentList, m)),
            "partitionable": xform(self.assertFalse),
            "path": xform(lambda x, m: six.assertRegex(self, x, "^/dev", m)),
            "raw_device": xform(self.assertIsNotNone),
            "resizable": xform(self.assertFalse),
            "size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "status": xform(self.assertFalse),
            "sysfs_path": xform(lambda x, m: self.assertEqual(x, "", m)),
            "target_size": xform(lambda x, m: self.assertEqual(x, Size(0), m)),
            "type": xform(lambda x, m: self.assertEqual(x, "mdarray", m)),
            "uuid": xform(self.assertIsNone)
        }
        super(DeviceStateTestCase, self).__init__(methodName=methodName)

    def state_check(self, device, **kwargs):
        """Checks the current state of a device by means of its
           fields or properties.

           Every kwarg should be a key which is a field or property
           of a Device and a value which is a function of
           two parameters and should call the appropriate assert* functions.
           These values override those in the state_functions dict.

           If the value is None, then the test starts the debugger instead.
        """
        self.longMessage = True
        for k, v in self._state_functions.items():
            if k in kwargs:
                test_func = kwargs[k]
                if test_func is None:
                    getattr(device, k)
                else:
{'fraction_non_alphanumeric': 0.09299081715680577, 'fraction_numerical': 0.00209229338602813, 'mean_word_length': 2.8104517271922056, 'pattern_counts': {'":': 44, '<': 3, '<?xml version=': 0, '>': 7, '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': '6878934', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2438, 'n_words': 813}