Beispiel #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
                        )
                    )
Beispiel #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
Beispiel #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
Beispiel #4
0
 def test_repr(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert repr(path) == ("AttrPath(SubSection, 'section.document')")
Beispiel #5
0
 def test_iter(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert list(path) == [self.SubSection.section, self.Section.document]
Beispiel #6
0
 def test_init(self):
     path = AttrPath(self.SubSection, 'section.document')
     assert path.class_ == self.SubSection
     assert path.path == Path('section.document')
Beispiel #7
0
 def test_len(self):
     len(AttrPath(self.SubSection, 'section.document')) == 2
Beispiel #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
Beispiel #9
0
 def test_direction(self, class_, path, direction):
     assert (AttrPath(getattr(self, class_), path).direction == direction)
Beispiel #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'))
Beispiel #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
Beispiel #12
0
 def test_iter(self, Section, SubSection):
     path = AttrPath(SubSection, 'section.document')
     assert list(path) == [SubSection.section, Section.document]
Beispiel #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'
Beispiel #14
0
 def test_direction(self, SubSection):
     assert (AttrPath(SubSection,
                      'section').direction == symbol('MANYTOONE'))
Beispiel #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')
Beispiel #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'))
Beispiel #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'