<commit_before># -*- coding: utf-8 -*-

import unittest
from unittest import TestCase
from mock import Mock
from mock import patch

from mockstar import p
from mockstar import DotDict
from mockstar import prefixed_p


def side_effect_one():
    pass


def side_effect_two():
    pass


def side_effect_three():
    val = side_effect_four()
    return val * 2


def side_effect_four():
    return 4


def side_effect_five(n):
    return n


class TestDotDict(TestCase):
    def test_should_setattr_getattr(self):
        d = DotDict()
        d['foo'] = 'something'

        # do
        result = d.foo

        self.assertEquals(result, 'something')


class TestPatch(TestCase):
    @p(__name__ + '.side_effect_one')
    @p(__name__ + '.side_effect_two')
    def test_should_mock_to_kw(self, se):
        self.assertIsInstance(se.side_effect_one, Mock)
        self.assertIsInstance(se.side_effect_two, Mock)

    @p(__name__ + '.side_effect_four')
    def test_should_mock_inner_call(self, se):
        se.side_effect_four.return_value = 1

        # do
        result = side_effect_three()

        self.assertEquals(result, 2)

    @p(__name__ + '.side_effect_five', autospec=True)
    @patch('mockstar.patch')
    def test_should_pass_mock_parameters(self, mockstar_patch_mock, se):
        se.side_effect_five(10)
        self.assertRaises(TypeError, lambda: se.side_effect_five())


ppatch = prefixed_p(__name__)


class TestPrefixedP(TestCase):
    @ppatch('side_effect_five', autospec=True)
    def test_should_prefix_patch_here(self, se):
        self.assertRaises(TypeError, lambda: se.side_effect_five())


if __name__ == '__main__':
    unittest.main()
<commit_msg>add 2 tests to test class-wide decorators<commit_after># -*- coding: utf-8 -*-

import unittest
from unittest import TestCase
from mock import Mock
from mock import patch

from mockstar import p
from mockstar import DotDict
from mockstar import prefixed_p


def side_effect_one():
    pass


def side_effect_two():
    pass


def side_effect_three():
    val = side_effect_four()
    return val * 2


def side_effect_four():
    return 4


def side_effect_five(n):
    return n


class TestDotDict(TestCase):
    def test_should_setattr_getattr(self):
        d = DotDict()
        d['foo'] = 'something'

        # do
        result = d.foo

        self.assertEquals(result, 'something')


class TestPatch(TestCase):
    @p(__name__ + '.side_effect_one')
    @p(__name__ + '.side_effect_two')
    def test_should_mock_to_kw(self, se):
        self.assertIsInstance(se.side_effect_one, Mock)
        self.assertIsInstance(se.side_effect_two, Mock)

    @p(__name__ + '.side_effect_four')
    def test_should_mock_inner_call(self, se):
        se.side_effect_four.return_value = 1

        # do
        result = side_effect_three()

        self.assertEquals(result, 2)

    @p(__name__ + '.side_effect_five', autospec=True)
    @patch('mockstar.patch')
    def test_should_pass_mock_parameters(self, mockstar_patch_mock, se):
        se.side_effect_five(10)
        self.assertRaises(TypeError, lambda: se.side_effect_five())


ppatch = prefixed_p(__name__)


class TestPrefixedP(TestCase):
    @ppatch('side_effect_five', autospec=True)
    def test_should_prefix_patch_here(self, se):
        self.assertRaises(TypeError, lambda: se.side_effect_five())


@ppatch('side_effect_one')
@ppatch('side_effect_two')
class TestPatchClass(TestCase):
    def test_should_get_se(self, se):
        self.assertIsInstance(se.side_effect_one, Mock)
        self.assertIsInstance(se.side_effect_two, Mock)

    def test_should_also_get_se(self, se):
        self.assertIsInstance(se.side_effect_one, Mock)
        self.assertIsInstance(se.side_effect_two, Mock)


if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.1027542372881356, 'fraction_numerical': 0.003972457627118644, 'mean_word_length': 3.6230110159118727, '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': '1019170', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1242, 'n_words': 256}