<commit_before>import unittest

from pyrollout import Rollout
from pyrollout.feature import Feature
from pyrollout.storage.memory import MemoryUserStorage, MemoryFeatureStorage


class TestBasicFunctions(unittest.TestCase):
    def setUp(self):
        self.rollout = Rollout()
        self.rollout.add_feature(Feature('feature_for_all', groups=['ALL']))
        self.rollout.add_feature(Feature('feature_for_none', groups=['NONE']))
        self.rollout.add_feature(Feature('feature_for_some', groups=['some']))

    # noinspection PyDefaultArgument
    def _add_user(self, user_id=[1], groups=None):
        user_id[0] += 1
        self.assertIsInstance(self.rollout.user_storage, MemoryUserStorage)
        new_user = {
            'id': user_id[0],
            'name': 'TestUser {ID}'.format(ID=user_id[0])
        }
        if groups is not None:
            new_user['groups'] = groups
        return self.rollout.user_storage.add_user(new_user)

    def test_undefined_feature(self):
        user = self._add_user()
        self.assertTrue(self.rollout.can(user, 'undefined_feature'))
        self.rollout.default_undefined_feature = False

        self.assertFalse(self.rollout.can(user, 'undefined_feature_false'))

    def test_undefined_feature_default_false(self):
        user = self._add_user()
        self.rollout.default_undefined_feature = False
        self.assertFalse(self.rollout.can(user, 'undefined_feature_false'))

    def test_specify_storage(self):
        rollout = Rollout(feature_storage=MemoryFeatureStorage(), user_storage=MemoryUserStorage())
        rollout.add_feature(Feature('feature_for_all', groups=['ALL']))
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_all'), True)

    def test_repr(self):
        feature_repr = repr(Feature('ff1', groups=['a'], users=[1], percentage=1))
        self.assertIn("G:['a'] ", feature_repr)
        self.assertIn("U:[1] ", feature_repr)
        self.assertIn("P:1:False>", feature_repr)

    def test_all(self):
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_all'), True)

    def test_none(self):
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_none'), False)

    def test_some(self):<commit_msg>Fix broken test since I switched the default behavior.<commit_after>import unittest

from pyrollout import Rollout
from pyrollout.feature import Feature
from pyrollout.storage.memory import MemoryUserStorage, MemoryFeatureStorage


class TestBasicFunctions(unittest.TestCase):
    def setUp(self):
        self.rollout = Rollout()
        self.rollout.add_feature(Feature('feature_for_all', groups=['ALL']))
        self.rollout.add_feature(Feature('feature_for_none', groups=['NONE']))
        self.rollout.add_feature(Feature('feature_for_some', groups=['some']))

    # noinspection PyDefaultArgument
    def _add_user(self, user_id=[1], groups=None):
        user_id[0] += 1
        self.assertIsInstance(self.rollout.user_storage, MemoryUserStorage)
        new_user = {
            'id': user_id[0],
            'name': 'TestUser {ID}'.format(ID=user_id[0])
        }
        if groups is not None:
            new_user['groups'] = groups
        return self.rollout.user_storage.add_user(new_user)

    def test_undefined_feature(self):
        user = self._add_user()
        self.assertFalse(self.rollout.can(user, 'undefined_feature'))

    def test_undefined_feature_default_true(self):
        user = self._add_user()
        self.rollout.default_undefined_feature = True
        self.assertTrue(self.rollout.can(user, 'undefined_feature_true'))

    def test_specify_storage(self):
        rollout = Rollout(feature_storage=MemoryFeatureStorage(), user_storage=MemoryUserStorage())
        rollout.add_feature(Feature('feature_for_all', groups=['ALL']))
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_all'), True)

    def test_repr(self):
        feature_repr = repr(Feature('ff1', groups=['a'], users=[1], percentage=1))
        self.assertIn("G:['a'] ", feature_repr)
        self.assertIn("U:[1] ", feature_repr)
        self.assertIn("P:1:False>", feature_repr)

    def test_all(self):
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_all'), True)

    def test_none(self):
        user = self._add_user()
        self.assertIs(self.rollout.can(user, 'feature_for_none'), False)

    def test_some(self):
{'fraction_non_alphanumeric': 0.12777284826974267, 'fraction_numerical': 0.0044365572315882874, 'mean_word_length': 3.615148413510747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '876782', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1391, 'n_words': 225}