1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
from functools import partial, partialmethod
from sentry_sdk.utils import transaction_from_function
class MyClass:
def myfunc(self):
pass
def myfunc():
pass
@partial
def my_partial():
pass
my_lambda = lambda: None
my_partial_lambda = partial(lambda: None)
def test_transaction_from_function():
x = transaction_from_function
assert x(MyClass) == "tests.utils.test_transaction.MyClass"
assert x(MyClass.myfunc) == "tests.utils.test_transaction.MyClass.myfunc"
assert x(myfunc) == "tests.utils.test_transaction.myfunc"
assert x(None) is None
assert x(42) is None
assert x(lambda: None).endswith("<lambda>")
assert x(my_lambda) == "tests.utils.test_transaction.<lambda>"
assert (
x(my_partial) == "partial(<function tests.utils.test_transaction.my_partial>)"
)
assert (
x(my_partial_lambda)
== "partial(<function tests.utils.test_transaction.<lambda>>)"
)
def test_transaction_from_function_partialmethod():
x = transaction_from_function
class MyPartialClass:
@partialmethod
def my_partial_method(self):
pass
assert (
x(MyPartialClass.my_partial_method)
== "partialmethod(<function tests.utils.test_transaction.test_transaction_from_function_partialmethod.<locals>.MyPartialClass.my_partial_method>)"
)
|