1- import decimal
2- from decimal import Inexact , FloatOperation
31from unittest import mock
42
53import pytest
@@ -20,7 +18,8 @@ def test_deterministic_sampled(sentry_init, capture_events, sample_rate, sample_
2018 events = capture_events ()
2119
2220 with mock .patch (
23- "sentry_sdk.tracing_utils.Random.uniform" , return_value = sample_rand
21+ "sentry_sdk.tracing_utils.Random.randrange" ,
22+ return_value = int (sample_rand * 1000000 ),
2423 ):
2524 with sentry_sdk .start_transaction () as transaction :
2625 assert (
@@ -55,35 +54,3 @@ def test_transaction_uses_incoming_sample_rand(
5554 # Transaction event captured if sample_rand < sample_rate, indicating that
5655 # sample_rand is used to make the sampling decision.
5756 assert len (events ) == int (sample_rand < sample_rate )
58-
59-
60- def test_decimal_context (sentry_init , capture_events ):
61- """
62- Ensure that having a user altered decimal context with a precision below 6
63- does not cause an InvalidOperation exception.
64- """
65- sentry_init (traces_sample_rate = 1.0 )
66- events = capture_events ()
67-
68- old_prec = decimal .getcontext ().prec
69- old_inexact = decimal .getcontext ().traps [Inexact ]
70- old_float_operation = decimal .getcontext ().traps [FloatOperation ]
71-
72- decimal .getcontext ().prec = 2
73- decimal .getcontext ().traps [Inexact ] = True
74- decimal .getcontext ().traps [FloatOperation ] = True
75-
76- try :
77- with mock .patch (
78- "sentry_sdk.tracing_utils.Random.uniform" , return_value = 0.123456789
79- ):
80- with sentry_sdk .start_transaction () as transaction :
81- assert (
82- transaction .get_baggage ().sentry_items ["sample_rand" ] == "0.123456"
83- )
84- finally :
85- decimal .getcontext ().prec = old_prec
86- decimal .getcontext ().traps [Inexact ] = old_inexact
87- decimal .getcontext ().traps [FloatOperation ] = old_float_operation
88-
89- assert len (events ) == 1
0 commit comments