-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Move expected tracer.events from test code to golden files #133
Move expected tracer.events from test code to golden files #133
Conversation
Thanks for taking care of this. Actually what I meant in #125 is that, we still keep the assertions for You removed the |
Could we generate the |
Generating trace.events JSON from the existing json data files is fine, but eventually we need to be able to dump these JSON from the trace.events in memory. Imagine we add a field to the events, and we definitely don't want to manually update the golden files. We already support the golden file override feature for mock response, and it would be the same for trace.events. |
I'm working on #126 to support Python 3.10. 3.10 changes bytecode quite a bit, so hard-code Btw, do you think |
|
@@ -64,6 +64,8 @@ class Event: | |||
|
|||
@staticmethod | |||
def value_serializer(inst: type, field: attr.Attribute, value: Any): | |||
if field is None: |
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.
why do we need this?
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.
It's not particularly needed for this PR but if you use it in attr.asdict
without the filter removing sources, it throws an error. This is due to it recursing into the sources list and becoming simple types with no fields. I added this as a sanity check to avoid that error if we happen to use attr.asdict
for other purposes. If you don't think it's necessary, I'll remove it.
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.
We can leave it here and add a comment
test/conftest.py
Outdated
@@ -73,4 +126,16 @@ def mocked_responses(request): | |||
if get_os_type() == "windows" and frame_name in {"test_numpy", "test_pandas"}: | |||
return | |||
|
|||
assert frame_data == golden_frame_data, json.dumps(frame_data, indent=4) | |||
if golden_frame_data.get("response", None) is None: |
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.
If default is not given, it defaults to None
so None
is not needed here
@pytest.fixture | ||
def mocked_responses(request): | ||
def check_response(request): |
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 feel like this function is doing multiple things and we should break into smaller ones, something like
golden_response = get_golden_response()
if golden_response:
assert ...
else:
update_golden_response()
This makese the intent more clear. A good side effect: skip assertion if golden_response does not exist (now assertion still happens if the file exists).
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.
Same with check_tracer_events
test/conftest.py
Outdated
snapshot = { | ||
"location": symbol.snapshot.location, | ||
"events_pointer": symbol.snapshot.events_pointer, | ||
} |
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.
you can do
# If snapshot is None, keep it.
snapshot = snapshot and {
"location": symbol.snapshot.location,
"events_pointer": symbol.snapshot.events_pointer,
}
|
||
yield | ||
|
||
tracer_events = [] |
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.
this can be extracted to a separate function.
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.
left some comments
will do
…On Wed, Oct 6, 2021 at 9:21 AM Victor Sun ***@***.***> wrote:
@victorjzsun <https://github.com/victorjzsun> requested your review on:
#133 <#133> Move assertions to
golden files.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#133 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATY3TK27LLHPETDYYUQQATUFRZSHANCNFSM5C2LTEHQ>
.
|
test/conftest.py
Outdated
def get_golden_data(golden_filepath, key): | ||
directory = os.path.dirname(golden_filepath) |
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.
type hints
test/conftest.py
Outdated
def update_golden_data(golden_filepath, key, value): | ||
golden_frame_data = {} |
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.
ditto
test/conftest.py
Outdated
def get_serialized_events(): | ||
tracer_events = [] |
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.
Please add a doc string with a simple example.
Overall it looks good now. Just a few nits. |
Only collaborators have merge access so I can't even merge it regardless. |
Perhaps I should add you as a collaborator then🙂 let me think about it |
Anything else you want to add? If not, Im going to merge it. |
Nope, go ahead 🙂 |
Merged. Thanks again for the great contribution! |
Addresses #125. Replaces certain assertions to instead be checked using golden files.