<commit_before>"""
Tests for the singleton utility.
"""
from __future__ import division, print_function, with_statement

from orges.util.singleton import Singleton


def test_singleton():
    class ASingleton(Singleton):
        """Mocks a singleton class."""
        def __init__(self):
            pass

    class BSingleton(Singleton):
        """Mocks a singleton class."""
        def __init__(self):
            pass

    a_singleton, a2_singleton = ASingleton(), ASingleton()
    b_singleton, b2_singleton = BSingleton(), BSingleton()

    assert a_singleton is a2_singleton
    assert b_singleton is b2_singleton
    assert a_singleton is not b_singleton

if __name__ == '__main__':
    import nose<commit_msg>add some tests for relevant behavior to the singleton tests<commit_after>"""
Tests for the singleton utility.
"""
from __future__ import division, print_function, with_statement

from orges.util.singleton import Singleton


class SingletonA(Singleton):
    """Mocks a singleton class."""
    def __init__(self):
        pass


class SingletonB(Singleton):
    """Mocks a singleton class."""
    def __init__(self):
        pass


class SingletonC(Singleton):
    """Mocks a singleton class."""
    common_knowledge = None

    def __init__(self, common_knowledge):
        self.common_knowledge = common_knowledge

    def report(self):
        return self.common_knowledge


class SingletonD(Singleton):
    """Mocks a singleton class."""
    def __init__(self, own_knowledge):
        self.own_knowledge = own_knowledge


def test_is():
    a_singleton, a2_singleton = SingletonA(), SingletonA()
    b_singleton, b2_singleton = SingletonB(), SingletonB()

    assert a_singleton is a2_singleton
    assert b_singleton is b2_singleton
    assert a_singleton is not b_singleton


def test_identity():
    a_singleton, a2_singleton = SingletonA(), SingletonA()
    b_singleton, b2_singleton = SingletonB(), SingletonB()

    assert id(a_singleton) == id(a2_singleton)
    assert id(b_singleton) == id(b2_singleton)
    assert id(a_singleton) is not id(b_singleton)


def test_borg_pattern():
    borg_0, borg_1 = SingletonC(42), SingletonC(None)

    assert borg_0.report() == borg_1.report()


def test_instance_attribute():
    instance_0, instance_1 = SingletonD(42), SingletonD(None)

    assert instance_0.own_knowledge == 42
    assert instance_0.own_knowledge == instance_1.own_knowledge

if __name__ == '__main__':
    import nose
{'fraction_non_alphanumeric': 0.09327902240325865, 'fraction_numerical': 0.010997963340122199, 'mean_word_length': 3.8633663366336632, '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': '3505603', 'n_tokens_mistral': 797, 'n_tokens_neox': 753, 'n_words': 202}