<commit_before>import unittest

from sixpack.models import Alternative

class TestAlternativeModel(unittest.TestCase):

    unit = True

    def test_key(self):
        alt = Alternative('yes', 'show-something')
        key = alt.key()
        self.assertEqual(key, 'sixpack:show-something:yes')

    def test_is_valid(self):
        not_valid = Alternative.is_valid(1)
        self.assertFalse(not_valid)

        valid = Alternative.is_valid('1')
        self.assertTrue(valid)

        unicode_valid = Alternative.is_valid(u'valid')
        self.assertTrue(unicode_valid)

    def test_increment_completion(self):
        self.assertTrue(True)<commit_msg>tests: alternative model tests<commit_after>
import unittest
from numbers import Number
from mock import MagicMock
from sixpack.db import REDIS

from sixpack.models import Alternative

class TestAlternativeModel(unittest.TestCase):

    unit = True

    def setUp(self):
        self.redis = MagicMock(REDIS)

    def test_key(self):
        alt = Alternative('yes', 'show-something', self.redis)
        key = alt.key()
        self.assertEqual(key, 'sixpack:show-something:yes')

    def test_is_valid(self):
        not_valid = Alternative.is_valid(1)
        self.assertFalse(not_valid)

        valid = Alternative.is_valid('1')
        self.assertTrue(valid)

        unicode_valid = Alternative.is_valid(u'valid')
        self.assertTrue(unicode_valid)

    def test_reset(self):
        alt = Alternative('yes', 'show-something', self.redis)
        alt.reset()
        self.redis.hset.assert_any_call(alt.key(), 'participant_count', 0)
        self.redis.hset.assert_any_call(alt.key(), 'completed_count', 0)

    def test_delete(self):
        alt = Alternative('yes', 'show-something', self.redis)
        alt.delete()
        self.redis.delete.assert_called_once_with(alt.key())

    def test_is_control(self):
        pass

    def test_experiment(self):
        pass

    def test_participant_count(self):
        self.redis.hget.return_value = 1

        alt = Alternative('yes', 'show-something', self.redis)
        count = alt.participant_count()

        self.redis.hget.assert_called_once_with(alt.key(), 'participant_count')
        self.assertTrue(isinstance(count, Number))

        self.redis.reset_mock()

    def test_completion_count(self):
        self.redis.hget.return_value = 1

        alt = Alternative('yes', 'show-something', self.redis)
        count = alt.completed_count()

        self.redis.hget.assert_called_once_with(alt.key(), 'completed_count')
        self.assertTrue(isinstance(count, Number))

        self.redis.reset_mock()

    def test_increment_participation(self):
        alt = Alternative('yes', 'show-something', self.redis)
        alt.increment_participation()
        self.redis.hincrby.assert_called_once_with(alt.key(), 'participant_count', 1)

    def test_increment_completion(self):
        alt = Alternative('yes', 'show-something', self.redis)
        alt.increment_completion()
        self.redis.hincrby.assert_called_once_with(alt.key(), 'completed_count', 1)
{'fraction_non_alphanumeric': 0.11564625850340136, 'fraction_numerical': 0.003239390994493035, 'mean_word_length': 3.178619756427605, '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': '807727', 'n_tokens_mistral': 1003, 'n_tokens_neox': 938, 'n_words': 160}