-
Notifications
You must be signed in to change notification settings - Fork 2
Advanced attribute manager #23
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8fe3b7e
Advanced attribute manager
konraddysput 56a4a10
Add unicode
06d3f68
if statment for python3/2
8c42fe9
Format primitive types
konraddysput 0132da7
Remove debug logs
konraddysput 6ca384a
Simplify the get method
konraddysput 722e645
Primitve types description
konraddysput 00523be
Use report data builder via function
konraddysput File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import sys | ||
|
||
|
||
class ReportDataBuilder: | ||
|
||
primitive_types = ( | ||
(int, float, bool, type(None), str) | ||
if sys.version_info.major >= 3 | ||
else (int, float, bool, type(None), str, unicode) | ||
) | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@staticmethod | ||
def get(provider_attributes): | ||
attributes = {} | ||
annotations = {} | ||
|
||
# Iterate through input_dict and split based on value types | ||
for key, value in provider_attributes.items(): | ||
if isinstance(value, ReportDataBuilder.primitive_types): | ||
attributes[key] = value | ||
else: | ||
annotations[key] = value | ||
|
||
# Return both dictionaries | ||
return attributes, annotations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from backtracepython.attributes.attribute_provider import AttributeProvider | ||
from backtracepython.version import version_string | ||
|
||
|
||
class UserAttributeProvider(AttributeProvider): | ||
def __init__(self, attributes): | ||
self.attributes = attributes | ||
|
||
def get(self): | ||
return self.attributes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from backtracepython.client import get_attributes, set_attribute, set_attributes | ||
from backtracepython.report import BacktraceReport | ||
|
||
|
||
def test_setting_client_attribute(): | ||
key = "foo" | ||
value = "bar" | ||
set_attribute(key, value) | ||
|
||
client_attributes = get_attributes() | ||
assert client_attributes[key] == value | ||
|
||
|
||
def test_overriding_client_attribute(): | ||
current_attributes = get_attributes() | ||
key = list(current_attributes.keys())[0] | ||
previous_value = list(current_attributes.values())[0] | ||
|
||
new_value = "bar" | ||
set_attribute(key, new_value) | ||
|
||
client_attributes = get_attributes() | ||
assert client_attributes[key] == new_value | ||
assert new_value != previous_value | ||
|
||
|
||
def test_primitive_values_in_attributes(): | ||
primitive_attributes = { | ||
"string": "test", | ||
"int": 123, | ||
"float": 123123.123, | ||
"boolean": False, | ||
"None": None, | ||
} | ||
|
||
set_attributes(primitive_attributes) | ||
new_report = BacktraceReport() | ||
report_attributes = new_report.get_attributes() | ||
|
||
for primitive_value_key in primitive_attributes: | ||
assert primitive_value_key in report_attributes | ||
assert ( | ||
report_attributes[primitive_value_key] | ||
== primitive_attributes[primitive_value_key] | ||
) | ||
|
||
|
||
def test_complex_objects_in_annotations(): | ||
objects_to_test = ( | ||
{"foo": 1, "bar": 2}, | ||
("foo", "bar", "baz"), | ||
lambda: None, | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BacktraceReport(), | ||
) | ||
|
||
for index, value in enumerate(objects_to_test): | ||
set_attribute(index, value) | ||
|
||
new_report = BacktraceReport() | ||
report_annotations = new_report.get_annotations() | ||
|
||
assert len(report_annotations) == len(objects_to_test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.