<commit_before>#!/usr/bin/env python

"""Specification for how snake-guice handles inherited classes."""


from snakeguice import Injector, inject, Injected


class Data(object): pass
class OldData(object): pass
class NewData(object): pass


class Module(object):
    def configure(self, binder):
        binder.bind(Data, annotated_with='old', to=OldData)
        binder.bind(Data, annotated_with='new', to=NewData)


def describe_basic_attribute_inheritance():
    class Parent(object):
        parent_attr = inject(Data, annotation='old')

    class Child(Parent):
        child_attr = inject(Data, annotation='new')

    instance = Injector(Module()).get_instance(Child)

    def parent_attribute_should_be_set():
        assert isinstance(instance.parent_attr, OldData)

    def child_attribute_should_be_set():
        assert isinstance(instance.child_attr, NewData)


def describe_basic_method_inheritance():
    class Parent(object):
        @inject(value=Data, annotation='old')
        def set_parent_value(self, value):
            self.parent_value = value

    class Child(Parent):
        @inject(value=Data, annotation='new')
        def set_child_value(self, value):
            self.child_value = value

    instance = Injector(Module()).get_instance(Child)

    def parent_value_should_be_set():
        assert isinstance(instance.parent_value, OldData)

    def child_value_should_be_set():
        assert isinstance(instance.child_value, NewData)


def describe_inheriting_the_same_method():
    class Parent(object):
        @inject(value=Data, annotation='old')
        def set_value(self, value):
            self.value = value

    class Child(Parent):
        @inject(value=Data, annotation='new')
        def set_value(self, value):
            self.value = value

    instance = Injector(Module()).get_instance(Child)

    def value_should_be_set_by_child():
        assert isinstance(instance.value, NewData)<commit_msg>Renaming tests to make more sense.<commit_after>#!/usr/bin/env python

"""Specification for how snake-guice handles inherited classes."""


from snakeguice import Injector, inject, Injected


class Data(object): pass
class OldData(object): pass
class NewData(object): pass


class Module(object):
    def configure(self, binder):
        binder.bind(Data, annotated_with='old', to=OldData)
        binder.bind(Data, annotated_with='new', to=NewData)


def describe_inheriting_an_attribute():
    class Parent(object):
        parent_attr = inject(Data, annotation='old')

    class Child(Parent):
        child_attr = inject(Data, annotation='new')

    instance = Injector(Module()).get_instance(Child)

    def parent_attribute_should_be_set():
        assert isinstance(instance.parent_attr, OldData)

    def child_attribute_should_be_set():
        assert isinstance(instance.child_attr, NewData)


def describe_inheriting_a_method():
    class Parent(object):
        @inject(value=Data, annotation='old')
        def set_parent_value(self, value):
            self.parent_value = value

    class Child(Parent):
        @inject(value=Data, annotation='new')
        def set_child_value(self, value):
            self.child_value = value

    instance = Injector(Module()).get_instance(Child)

    def parent_value_should_be_set():
        assert isinstance(instance.parent_value, OldData)

    def child_value_should_be_set():
        assert isinstance(instance.child_value, NewData)


def describe_overriding_an_inherited_method():
    class Parent(object):
        @inject(value=Data, annotation='old')
        def set_value(self, value):
            self.value = value

    class Child(Parent):
        @inject(value=Data, annotation='new')
        def set_value(self, value):
            self.value = value

    instance = Injector(Module()).get_instance(Child)

    def value_should_be_set_by_child():
        assert isinstance(instance.value, NewData)

{'fraction_non_alphanumeric': 0.10656785075389727, 'fraction_numerical': 0.0, 'mean_word_length': 3.693045563549161, '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': '7188971', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1106, 'n_words': 240}