def gather_paths(self): for class_, callbacks in self.generator_registry.items(): for callback in callbacks: path = AttrPath(class_, callback.__observes__) self.callback_map[class_].append( Callback( func=callback, path=path, backref=None, fullpath=path ) ) for index in range(len(path)): i = index + 1 prop_class = path[index].property.mapper.class_ self.callback_map[prop_class].append( Callback( func=callback, path=path[i:], backref=~ (path[:i]), fullpath=path ) )
def test_getitem(self): path = AttrPath(self.SubSection, 'section.document') assert path[0] is self.SubSection.section assert path[1] is self.Section.document
def test_index(self): path = AttrPath(self.SubSection, 'section.document') assert path.index(self.Section.document) == 1 assert path.index(self.SubSection.section) == 0
def test_repr(self): path = AttrPath(self.SubSection, 'section.document') assert repr(path) == ("AttrPath(SubSection, 'section.document')")
def test_iter(self): path = AttrPath(self.SubSection, 'section.document') assert list(path) == [self.SubSection.section, self.Section.document]
def test_init(self): path = AttrPath(self.SubSection, 'section.document') assert path.class_ == self.SubSection assert path.path == Path('section.document')
def test_len(self): len(AttrPath(self.SubSection, 'section.document')) == 2
def test_index(self): path = AttrPath(self.SubSection, 'section.document') assert path.index(self.Section.document) == 1 assert path.index(self.SubSection.section) == 0
def test_direction(self, class_, path, direction): assert (AttrPath(getattr(self, class_), path).direction == direction)
def test_eq(self, SubSection): assert (AttrPath(SubSection, 'section.document') == AttrPath( SubSection, 'section.document')) assert not (AttrPath(SubSection, 'section') == AttrPath( SubSection, 'section.document'))
def test_getitem(self, Section, SubSection): path = AttrPath(SubSection, 'section.document') assert path[0] is SubSection.section assert path[1] is Section.document
def test_iter(self, Section, SubSection): path = AttrPath(SubSection, 'section.document') assert list(path) == [SubSection.section, Section.document]
def test_invert(self, Document, Section, SubSection): path = ~AttrPath(SubSection, 'section.document') assert path.parts == [Document.sections, Section.subsections] assert str(path.path) == 'sections.subsections'
def test_direction(self, SubSection): assert (AttrPath(SubSection, 'section').direction == symbol('MANYTOONE'))
def test_getitem_with_slice(self): path = AttrPath(self.SubSection, 'section.document') assert path[:] == AttrPath(self.SubSection, 'section.document') assert path[:-1] == AttrPath(self.SubSection, 'section') assert path[1:] == AttrPath(self.Section, 'document')
def test_ne(self): assert not (AttrPath(self.SubSection, 'section.document') != AttrPath( self.SubSection, 'section.document')) assert (AttrPath(self.SubSection, 'section') != AttrPath( self.SubSection, 'section.document'))
def test_invert(self): path = ~AttrPath(self.SubSection, 'section.document') assert path.parts == [self.Document.sections, self.Section.subsections] assert str(path.path) == 'sections.subsections'