# Path: chamber/utils/decorators.py
# class classproperty(property):
# 
#     def __get__(self, cls, owner):
#         return self.fget.__get__(None, owner)()
# 
# def singleton(klass):
#     """
#     Create singleton from class
#     """
#     instances = {}
# 
#     def getinstance(*args, **kwargs):
#         if klass not in instances:
#             instances[klass] = klass(*args, **kwargs)
#         return instances[klass]
#     return wraps(klass)(getinstance)
# 
# def translation_activate_block(function=None, language=None):
#     """
#     Activate language only for one method or function
#     """
# 
#     def _translation_activate_block(function):
#         def _decorator(*args, **kwargs):
#             tmp_language = translation.get_language()
#             try:
#                 translation.activate(language or settings.LANGUAGE_CODE)
#                 return function(*args, **kwargs)
#             finally:
#                 translation.activate(tmp_language)
#         return wraps(function)(_decorator)
# 
#     if function:
#         return _translation_activate_block(function)
#     else:
#         return _translation_activate_block
# 
# Path: chamber/utils/transaction.py
# def smart_atomic(using=None, savepoint=True, ignore_errors=None, reversion=True, reversion_using=None):
#     """
#     Decorator and context manager that overrides django atomic decorator and automatically adds create revision.
#     The _atomic closure is required to achieve save ContextDecorator that nest more inner context decorator.
#     More here https://stackoverflow.com/questions/45589718/combine-two-context-managers-into-one
#     """
# 
#     ignore_errors = () if ignore_errors is None else ignore_errors
# 
#     @contextmanager
#     def _atomic(using=None, savepoint=True, reversion=True, reversion_using=None):
#         try:
#             from reversion.revisions import create_revision
#         except ImportError:
#             reversion = False
# 
#         if not reversion:
#             @contextmanager  # noqa: F811
#             def create_revision(*args, **kwargs):  # noqa: F811
#                 yield
# 
#         error = None
#         with transaction.atomic(using, savepoint), create_revision(using=reversion_using):
#             try:
#                 yield
#             except ignore_errors as ex:
#                 error = ex
# 
#         if error:
#             raise error  # pylint: disable=E0702
# 
#     if callable(using):
#         return _atomic(DEFAULT_DB_ALIAS, savepoint, reversion, reversion_using)(using)
#     else:
#         return _atomic(using, savepoint, reversion, reversion_using)


from django.test import TestCase
from django.utils.translation import get_language
from chamber.utils.decorators import classproperty, singleton, translation_activate_block
from chamber.utils.transaction import smart_atomic
from germanium.tools import assert_equal, assert_raises, assert_false  # pylint: disable=E0401
from test_chamber.models import CSVRecord
        self.num_singletons += 1
        super(self.__class__, self).__init__()

    def get_count_singletons(self):
        return self.num_singletons


class DecoratorsTestCase(TestCase):

    def test_class_property(self):
        assert_equal(ObjectWithClassProperty.class_method_property, 1)
        assert_equal(ObjectWithClassProperty().class_method_property, 1)

    def test_singleton(self):
        singleton = SingletonObject()
        assert_equal(singleton.num_singletons, 1)
        singleton = SingletonObject()
        assert_equal(singleton.num_singletons, 1)

    def test_translation_activate_block(self):

        @translation_activate_block(language='en')
        def en_block():
            assert_equal(get_language(), 'en')

        assert_equal(get_language(), 'cs')
        en_block()
        assert_equal(get_language(), 'cs')

    def test_smat_atomic_should_be_to_use_as_a_decorator(self):

# Path: chamber/utils/decorators.py
# class classproperty(property):
# 
#     def __get__(self, cls, owner):
#         return self.fget.__get__(None, owner)()
# 
# def singleton(klass):
#     """
#     Create singleton from class
#     """
#     instances = {}
# 
#     def getinstance(*args, **kwargs):
#         if klass not in instances:
#             instances[klass] = klass(*args, **kwargs)
#         return instances[klass]
#     return wraps(klass)(getinstance)
# 
# def translation_activate_block(function=None, language=None):
#     """
#     Activate language only for one method or function
#     """
# 
#     def _translation_activate_block(function):
#         def _decorator(*args, **kwargs):
#             tmp_language = translation.get_language()
#             try:
#                 translation.activate(language or settings.LANGUAGE_CODE)
#                 return function(*args, **kwargs)
#             finally:
#                 translation.activate(tmp_language)
#         return wraps(function)(_decorator)
# 
#     if function:
#         return _translation_activate_block(function)
#     else:
#         return _translation_activate_block
# 
# Path: chamber/utils/transaction.py
# def smart_atomic(using=None, savepoint=True, ignore_errors=None, reversion=True, reversion_using=None):
#     """
#     Decorator and context manager that overrides django atomic decorator and automatically adds create revision.
#     The _atomic closure is required to achieve save ContextDecorator that nest more inner context decorator.
#     More here https://stackoverflow.com/questions/45589718/combine-two-context-managers-into-one
#     """
# 
#     ignore_errors = () if ignore_errors is None else ignore_errors
# 
#     @contextmanager
#     def _atomic(using=None, savepoint=True, reversion=True, reversion_using=None):
#         try:
#             from reversion.revisions import create_revision
#         except ImportError:
#             reversion = False
# 
#         if not reversion:
#             @contextmanager  # noqa: F811
#             def create_revision(*args, **kwargs):  # noqa: F811
#                 yield
# 
#         error = None
#         with transaction.atomic(using, savepoint), create_revision(using=reversion_using):
#             try:
#                 yield
#             except ignore_errors as ex:
#                 error = ex
# 
#         if error:
#             raise error  # pylint: disable=E0702
# 
#     if callable(using):
#         return _atomic(DEFAULT_DB_ALIAS, savepoint, reversion, reversion_using)(using)
#     else:
#         return _atomic(using, savepoint, reversion, reversion_using)


# Path: example/dj/apps/test_chamber/tests/utils/decorators.py
from django.test import TestCase
from django.utils.translation import get_language
from chamber.utils.decorators import classproperty, singleton, translation_activate_block
from chamber.utils.transaction import smart_atomic
from germanium.tools import assert_equal, assert_raises, assert_false  # pylint: disable=E0401
from test_chamber.models import CSVRecord

        self.num_singletons += 1
        super(self.__class__, self).__init__()

    def get_count_singletons(self):
        return self.num_singletons


class DecoratorsTestCase(TestCase):

    def test_class_property(self):
        assert_equal(ObjectWithClassProperty.class_method_property, 1)
        assert_equal(ObjectWithClassProperty().class_method_property, 1)

    def test_singleton(self):
        singleton = SingletonObject()
        assert_equal(singleton.num_singletons, 1)
        singleton = SingletonObject()
        assert_equal(singleton.num_singletons, 1)

    def test_translation_activate_block(self):

        @translation_activate_block(language='en')
        def en_block():
            assert_equal(get_language(), 'en')

        assert_equal(get_language(), 'cs')
        en_block()
        assert_equal(get_language(), 'cs')

    def test_smat_atomic_should_be_to_use_as_a_decorator(self):

        @smart_atomic