Ejemplo n.º 1
0
    def test_circular_dependency_error_is_working_properly(self):
        """testing if CircularDependencyError is working properly
        """
        from stalker.exceptions import CircularDependencyError
        test_message = 'testing CircularDependencyError'
        with pytest.raises(CircularDependencyError) as cm:
            raise CircularDependencyError(test_message)

        assert str(cm.value) == test_message
Ejemplo n.º 2
0
def check_circular_dependency(entity, other_entity, attr_name):
    """Checks the circular dependency in entity if it has other_entity in its
    dependency attr which is specified with attr_name
    """
    for e in walk_hierarchy(entity, attr_name):
        if e is other_entity:
            raise CircularDependencyError(
                '%(entity_name)s (%(entity_class)s) and '
                '%(other_entity_name)s (%(other_entity_class)s) creates a '
                'circular dependency in their "%(attr_name)s" attribute' % {
                    'entity_name': entity,
                    'entity_class': entity.__class__.__name__,
                    'other_entity_name': other_entity,
                    'other_entity_class': other_entity.__class__.__name__,
                    'attr_name': attr_name
                })