def test_isaspect(self, RootAspect): @RootAspect.subaspect class SubAspect: """ Description """ assert isaspect(RootAspect) assert isaspect(SubAspect) assert isaspect(SubAspect('Python')) assert isaspect(Root('py')) assert not isaspect('String')
def test__contains__(self): list_of_aspect = AspectList( [Metadata.CommitMessage.Shortlog, Metadata.CommitMessage.Body]) assert Metadata.CommitMessage.Shortlog in list_of_aspect assert Metadata.CommitMessage.Shortlog.ColonExistence in list_of_aspect assert Metadata.CommitMessage.Body in list_of_aspect assert Metadata not in list_of_aspect assert Metadata.CommitMessage.Emptiness not in list_of_aspect with pytest.raises(aspectTypeError) as exc: 'Metadata.CommitMessage.Shortlog' in list_of_aspect assert not isaspect('Metadata.CommitMessage.Shortlog') exc.match("'Metadata.CommitMessage.Shortlog' is not an " 'aspectclass or an instance of an aspectclass') with pytest.raises(aspectTypeError) as exc: str in list_of_aspect assert not isaspect(str) exc.match("<class 'str'> is not an " 'aspectclass or an instance of an aspectclass')
def test_issubaspect(self, RootAspect): @RootAspect.subaspect class SubAspect: """ Description """ assert issubaspect(SubAspect, RootAspect) assert not issubaspect(Root, RootAspect) assert issubaspect(RootAspect, RootAspect) with pytest.raises(aspectTypeError) as exc: issubaspect('String', SubAspect) assert not isaspect('String') assert (str(exc.value) == "'String' is not an aspectclass or " 'an instance of an aspectclass') with pytest.raises(aspectTypeError) as exc: issubaspect(RootAspect, str) assert not isaspect(str) assert (str(exc.value) == "<class 'str'> is not an aspectclass or " 'an instance of an aspectclass') assert issubaspect(SubAspect('Python'), RootAspect)
def get(self, aspect): """ Return first item that match or contain an aspect. See :meth:`coalib.bearlib.aspects.aspectbase.get` for further example. :param aspect: An aspectclass OR name of an aspect. :return: An aspectclass OR aspectclass instance, depend on AspectList content. Return None if no match found. """ if not isaspect(aspect): aspect = coalib.bearlib.aspects[aspect] try: return next(filter(None, (item.get(aspect) for item in self))) except StopIteration: return None
def __init__(self, seq=()): """ Initialize a new AspectList. >>> from .Metadata import CommitMessage >>> AspectList([CommitMessage.Shortlog, CommitMessage.Body]) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] >>> AspectList(['Shortlog', 'CommitMessage.Body']) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] >>> AspectList([CommitMessage.Shortlog, 'CommitMessage.Body']) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] :param seq: A sequence containing either aspectclass, aspectclass instance, or string of partial/full qualified aspect name. """ super().__init__( (item if isaspect(item) else coalib.bearlib.aspects[item] for item in seq))
def __init__(self, seq=(), exclude=None): """ Initialize a new AspectList. >>> from .Metadata import CommitMessage >>> AspectList([CommitMessage.Shortlog, CommitMessage.Body]) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] >>> AspectList(['Shortlog', 'CommitMessage.Body']) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] >>> AspectList([CommitMessage.Shortlog, 'CommitMessage.Body']) [<aspectclass '...Shortlog'>, <aspectclass '...Body'>] :param seq: A sequence containing either aspectclass, aspectclass instance, or string of partial/full qualified aspect name. :param exclude: A sequence of either aspectclass or string of aspect name that marked as excluded from the list. """ super().__init__( (item if isaspect(item) else coalib.bearlib.aspects[item] for item in seq)) self.exclude = AspectList(exclude) if exclude is not None else []