示例#1
0
    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
                        )
                    )
示例#2
0
 def test_getitem(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert path[0] is self.SubSection.section
     assert path[1] is self.Section.document
示例#3
0
 def test_index(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert path.index(self.Section.document) == 1
     assert path.index(self.SubSection.section) == 0
示例#4
0
 def test_repr(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert repr(path) == ("AttrPath(SubSection, 'section.document')")
示例#5
0
 def test_iter(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert list(path) == [self.SubSection.section, self.Section.document]
示例#6
0
 def test_init(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert path.class_ == self.SubSection
     assert path.path == Path('section.document')
示例#7
0
 def test_len(self):
     len(AttrPath(self.SubSection, 'section.document')) == 2
示例#8
0
 def test_index(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert path.index(self.Section.document) == 1
     assert path.index(self.SubSection.section) == 0
示例#9
0
 def test_direction(self, class_, path, direction):
     assert (AttrPath(getattr(self, class_), path).direction == direction)
示例#10
0
 def test_eq(self, SubSection):
     assert (AttrPath(SubSection, 'section.document') == AttrPath(
         SubSection, 'section.document'))
     assert not (AttrPath(SubSection, 'section') == AttrPath(
         SubSection, 'section.document'))
示例#11
0
 def test_getitem(self, Section, SubSection):
     path = AttrPath(SubSection, 'section.document')
     assert path[0] is SubSection.section
     assert path[1] is Section.document
示例#12
0
 def test_iter(self, Section, SubSection):
     path = AttrPath(SubSection, 'section.document')
     assert list(path) == [SubSection.section, Section.document]
示例#13
0
 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'
示例#14
0
 def test_direction(self, SubSection):
     assert (AttrPath(SubSection,
                      'section').direction == symbol('MANYTOONE'))
示例#15
0
 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')
示例#16
0
 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'))
示例#17
0
 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'