-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce a distinct searchable non-broken storage for markers #3317
Changes from all commits
360d608
2707221
f1a1695
e8feee0
180ae09
99015bf
2d06ae0
5e56e9b
ced1316
775fb96
159ea9b
a92a51b
02315c0
2cb7e72
ee51fa5
8805036
dbb1b5a
802da78
e4a52c1
7454a38
a2974dd
1fcadeb
48bcc34
a8ad89c
3582e1f
e534cc8
4df8f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ | |
import inspect | ||
|
||
import attr | ||
from ..deprecated import MARK_PARAMETERSET_UNPACKING | ||
|
||
from ..deprecated import MARK_PARAMETERSET_UNPACKING, MARK_INFO_ATTRIBUTE | ||
from ..compat import NOTSET, getfslineno | ||
from six.moves import map | ||
from six.moves import map, reduce | ||
|
||
|
||
EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark" | ||
|
@@ -113,11 +114,21 @@ def _for_parametrize(cls, argnames, argvalues, func, config): | |
|
||
@attr.s(frozen=True) | ||
class Mark(object): | ||
name = attr.ib() | ||
args = attr.ib() | ||
kwargs = attr.ib() | ||
#: name of the mark | ||
name = attr.ib(type=str) | ||
#: positional arguments of the mark decorator | ||
args = attr.ib(type="List[object]") | ||
#: keyword arguments of the mark decorator | ||
kwargs = attr.ib(type="Dict[str, object]") | ||
|
||
def combined_with(self, other): | ||
""" | ||
:param other: the mark to combine with | ||
:type other: Mark | ||
:rtype: Mark | ||
|
||
combines by appending aargs and merging the mappings | ||
""" | ||
assert self.name == other.name | ||
return Mark( | ||
self.name, self.args + other.args, | ||
|
@@ -233,7 +244,7 @@ def store_legacy_markinfo(func, mark): | |
raise TypeError("got {mark!r} instead of a Mark".format(mark=mark)) | ||
holder = getattr(func, mark.name, None) | ||
if holder is None: | ||
holder = MarkInfo(mark) | ||
holder = MarkInfo.for_mark(mark) | ||
setattr(func, mark.name, holder) | ||
else: | ||
holder.add_mark(mark) | ||
|
@@ -260,23 +271,29 @@ def _marked(func, mark): | |
invoked more than once. | ||
""" | ||
try: | ||
func_mark = getattr(func, mark.name) | ||
func_mark = getattr(func, getattr(mark, 'combined', mark).name) | ||
except AttributeError: | ||
return False | ||
return mark.args == func_mark.args and mark.kwargs == func_mark.kwargs | ||
return any(mark == info.combined for info in func_mark) | ||
|
||
|
||
@attr.s | ||
class MarkInfo(object): | ||
""" Marking object created by :class:`MarkDecorator` instances. """ | ||
|
||
def __init__(self, mark): | ||
assert isinstance(mark, Mark), repr(mark) | ||
self.combined = mark | ||
self._marks = [mark] | ||
_marks = attr.ib() | ||
combined = attr.ib( | ||
repr=False, | ||
default=attr.Factory(lambda self: reduce(Mark.combined_with, self._marks), | ||
takes_self=True)) | ||
|
||
name = alias('combined.name') | ||
args = alias('combined.args') | ||
kwargs = alias('combined.kwargs') | ||
name = alias('combined.name', warning=MARK_INFO_ATTRIBUTE) | ||
args = alias('combined.args', warning=MARK_INFO_ATTRIBUTE) | ||
kwargs = alias('combined.kwargs', warning=MARK_INFO_ATTRIBUTE) | ||
|
||
@classmethod | ||
def for_mark(cls, mark): | ||
return cls([mark]) | ||
|
||
def __repr__(self): | ||
return "<MarkInfo {0!r}>".format(self.combined) | ||
|
@@ -288,7 +305,7 @@ def add_mark(self, mark): | |
|
||
def __iter__(self): | ||
""" yield MarkInfo objects each relating to a marking-call. """ | ||
return map(MarkInfo, self._marks) | ||
return map(MarkInfo.for_mark, self._marks) | ||
|
||
|
||
class MarkGenerator(object): | ||
|
@@ -365,3 +382,33 @@ def __len__(self): | |
|
||
def __repr__(self): | ||
return "<NodeKeywords for node %s>" % (self.node, ) | ||
|
||
|
||
@attr.s(cmp=False, hash=False) | ||
class NodeMarkers(object): | ||
""" | ||
internal strucutre for storing marks belongong to a node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be added to the docs in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think so, it should be noted that it currently cant be accessed via public attributes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that's the case, then it doesn't need adding to the docs does it? |
||
|
||
..warning:: | ||
|
||
unstable api | ||
|
||
""" | ||
own_markers = attr.ib(default=attr.Factory(list)) | ||
|
||
def update(self, add_markers): | ||
"""update the own markers | ||
""" | ||
self.own_markers.extend(add_markers) | ||
|
||
def find(self, name): | ||
""" | ||
find markers in own nodes or parent nodes | ||
needs a better place | ||
""" | ||
for mark in self.own_markers: | ||
if mark.name == name: | ||
yield mark | ||
|
||
def __iter__(self): | ||
return iter(self.own_markers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use
find_markers
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and no, im at it now and its a very brittle part of fixtures i dont fully understand,
its currently implemented using the old mechanism, and i'm afraid to touch it as its so messy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tracked it back to c462393
as far as i can tell it has been incorrect the whole time and i cant fix that incorrectness, but i should use find_markers
im on it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about 3 different attempts to fox this with a normal loop failed, its not clear how to correctly fix at first glance, as such i will leave that code as is for now and revisit later